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