wip: save file
This commit is contained in:
parent
7641ee6dbb
commit
a8e549de60
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user