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 () {