From 92af7405c64f22fbd7010e127373d9bbaed0ed7d Mon Sep 17 00:00:00 2001 From: zzs Date: Mon, 24 Mar 2025 11:50:30 +0800 Subject: [PATCH] wip: insert bookmark and locate bookmark --- src/views/infra/bookmark/index.vue | 62 ++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/views/infra/bookmark/index.vue b/src/views/infra/bookmark/index.vue index 457211d..df7df34 100644 --- a/src/views/infra/bookmark/index.vue +++ b/src/views/infra/bookmark/index.vue @@ -95,6 +95,12 @@ onMounted(async () => { case 'SaveFile': handleSaveFile() break + case 'AddBookmark': + handleAddBookmark(data) + break + case 'LocateBookmark': + handleLocateBookmark(data) + break } // WOPI Client发送消息 switch (MessageId) { @@ -359,6 +365,62 @@ function handleSaveFile() { }) } +/** + * 第三方调用者在选中文字或光标位置处插入书签 + * @param data + */ +function handleAddBookmark(data: any) { + try { + const bookmarkName = data.content.Payload.bookmarkName + if (!bookmarkName) + return + sendMessageToWopiClient({ + MessageId: 'CallPythonScript', + SendTime: Date.now(), + ScriptFile: 'BookmarkOP.py', + Function: 'InsertBookmark', + Values: { + params: { + type: 'string', + value: bookmarkName, + }, + }, + }) + } + catch (e) { + console.error(e) + createMessage.error('执行失败,请查看控制台日志!') + } +} + +/** + * 定位书签 + * @param data + */ +function handleLocateBookmark(data: any) { + try { + const bookmarkName = data.content.Payload.bookmarkName + if (!bookmarkName) + return + sendMessageToWopiClient({ + MessageId: 'CallPythonScript', + SendTime: Date.now(), + ScriptFile: 'BookmarkOP.py', + Function: 'LocateBookmark', + Values: { + params: { + type: 'string', + value: bookmarkName, + }, + }, + }) + } + catch (e) { + console.error(e) + createMessage.error('执行失败,请查看控制台日志!') + } +} + function logEvent(e: MessageEvent) { console.log('=============receive message start=======') console.log(typeof e.data)