From 8d99d268c497fa54d4e60e0966514932b3805264 Mon Sep 17 00:00:00 2001 From: hanshiyang Date: Wed, 19 Nov 2025 18:50:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=B9=B6=E8=B0=83=E7=94=A8=E7=88=B6=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E5=9B=9E=E8=B0=83=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实现点击保存按钮时获取编辑器内容并通过OCDViewer.onSave回调传递给父窗口。当父窗口未提供回调接口时显示警告信息。 --- src/main.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main.ts b/src/main.ts index a71f533..6314d1e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -169,6 +169,29 @@ window.onload = function () { } } + // 保存(调用父窗口回调) + const saveCallbackDom = document.querySelector('.menu-item__save')! + saveCallbackDom.onclick = function () { + try { + const editorValue = instance.command.getValue() + const content = JSON.stringify(editorValue.data, null, 2) + + const parentWin: any = window.parent || window + const viewer = (parentWin && parentWin.OCDViewer) || (window as any).OCDViewer + + if (viewer && typeof viewer.onSave === 'function') { + viewer.onSave(content) + console.log('已调用父窗口 OCDViewer.onSave') + } else { + console.warn('父窗口未提供 OCDViewer.onSave') + alert('未检测到父窗口的保存接口') + } + } catch (error) { + console.error('保存回调调用失败:', error) + alert('保存回调调用失败') + } + } + const undoDom = document.querySelector('.menu-item__undo')! undoDom.title = `撤销(${isApple ? '⌘' : 'Ctrl'}+Z)` undoDom.onclick = function () {