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