wip: save file

This commit is contained in:
zzs 2025-03-22 14:23:12 +08:00
parent 7641ee6dbb
commit a8e549de60

View File

@ -67,6 +67,9 @@ onMounted(async () => {
case 'ReplaceWithJSON': case 'ReplaceWithJSON':
proxyReplaceWithJSON(data) proxyReplaceWithJSON(data)
break break
case 'SaveFile':
handleSaveFile()
break
} }
// WOPI Client // WOPI Client
switch (MessageId) { switch (MessageId) {
@ -74,13 +77,16 @@ onMounted(async () => {
case 'Doc_ModifiedStatus': case 'Doc_ModifiedStatus':
handleUpdateModifiedStatus(data) handleUpdateModifiedStatus(data)
break break
// //
case 'UI_Save': case 'UI_Save':
handleUserSaveOp() handleUserSaveOp()
break break
case 'CallPythonScript-Result': case 'CallPythonScript-Result':
handlePythonScriptCallBack(data) handlePythonScriptCallBack(data)
break break
case 'Action_Save_Resp':
handleUserSaveOp()
break
} }
}) })
}) })
@ -166,12 +172,12 @@ async function downloadAndSendCurrentEditFile() {
const arrayBuffer: ArrayBuffer = response.data const arrayBuffer: ArrayBuffer = response.data
sendMessageToCaller({ sendMessageToCaller({
ActionId: 'SAVE_FILE', ActionId: 'SaveFile',
Payload: { Payload: {
name: currentEditFile.value.name, name: currentEditFile.value.name,
buffer: arrayBuffer, buffer: arrayBuffer,
}, },
}) }, true)
} }
catch (error) { catch (error) {
console.error('文件下载失败:', error) console.error('文件下载失败:', error)
@ -255,9 +261,15 @@ function sendMessageToWopiClient(data: any) {
* 发送消息给第三方调用者 * 发送消息给第三方调用者
* 用于转发部分WopiClient回调 * 用于转发部分WopiClient回调
*/ */
function sendMessageToCaller(data: any) { function sendMessageToCaller(data: any, ignore: boolean = false) {
try { try {
const targetWindow = window.parent const targetWindow = window.parent
if (ignore) {
targetWindow.postMessage(data, '*')
return
}
if (typeof data === 'string') if (typeof data === 'string')
targetWindow.postMessage(data, '*') targetWindow.postMessage(data, '*')
@ -300,6 +312,18 @@ function handlePythonScriptCallBack(data: any) {
} }
} }
function handleSaveFile() {
sendMessageToWopiClient({
MessageId: 'Action_Save',
Values: {
DontTerminateEdit: true,
DontSaveIfUnmodified: false,
Notify: true,
ExtendedData: '',
},
})
}
function logEvent(e: MessageEvent) { function logEvent(e: MessageEvent) {
console.log('=============receive message start=======') console.log('=============receive message start=======')
console.log(e.data) console.log(e.data)