From 1db33454a09bdc4edfffdeea4f289ec4242a7cbb Mon Sep 17 00:00:00 2001 From: baiqi Date: Tue, 11 Jun 2024 11:12:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=84=91=E5=9B=BE):=20=E8=84=91=E5=9B=BE?= =?UTF-8?q?=E6=9C=AA=E4=BF=9D=E5=AD=98=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ms-minders/featureCaseMinder/index.vue | 2 +- .../business/ms-minders/locale/en-US.ts | 1 + .../business/ms-minders/locale/zh-CN.ts | 1 + .../pure/ms-minder-editor/main/mainEditor.vue | 20 +++++++-- frontend/src/hooks/useLeaveUnSaveTip.ts | 2 +- .../modules/components/minder-editor/index.ts | 9 ++++ .../modules/components/minder-editor/types.ts | 1 + .../components/caseTable.vue | 45 ++++++++++++++----- 8 files changed, 63 insertions(+), 18 deletions(-) diff --git a/frontend/src/components/business/ms-minders/featureCaseMinder/index.vue b/frontend/src/components/business/ms-minders/featureCaseMinder/index.vue index 4d55571ace..8d694337c9 100644 --- a/frontend/src/components/business/ms-minders/featureCaseMinder/index.vue +++ b/frontend/src/components/business/ms-minders/featureCaseMinder/index.vue @@ -198,7 +198,7 @@ } } - watchEffect(() => { + onMounted(() => { initCaseTree(); }); diff --git a/frontend/src/components/business/ms-minders/locale/en-US.ts b/frontend/src/components/business/ms-minders/locale/en-US.ts index 44636b8f47..5b69e28e65 100644 --- a/frontend/src/components/business/ms-minders/locale/en-US.ts +++ b/frontend/src/components/business/ms-minders/locale/en-US.ts @@ -9,4 +9,5 @@ export default { 'ms.minders.caseNameNotNull': 'Test Case Name cannot be empty', 'ms.minders.commentTotal': '{num} Comments in Total', 'ms.minders.text': 'Text', + 'ms.minders.leaveUnsavedTip': 'The mind map has unsaved changes, are you sure you want to exit?', }; diff --git a/frontend/src/components/business/ms-minders/locale/zh-CN.ts b/frontend/src/components/business/ms-minders/locale/zh-CN.ts index 9bfb9bdb4c..3fb4b9ecf7 100644 --- a/frontend/src/components/business/ms-minders/locale/zh-CN.ts +++ b/frontend/src/components/business/ms-minders/locale/zh-CN.ts @@ -9,4 +9,5 @@ export default { 'ms.minders.caseNameNotNull': '用例名称不能为空', 'ms.minders.commentTotal': '共 {num} 评论', 'ms.minders.text': '文本', + 'ms.minders.leaveUnsavedTip': '脑图有未保存的更改,确认离开吗?', }; diff --git a/frontend/src/components/pure/ms-minder-editor/main/mainEditor.vue b/frontend/src/components/pure/ms-minder-editor/main/mainEditor.vue index aa3c1f9796..5f8d67c353 100644 --- a/frontend/src/components/pure/ms-minder-editor/main/mainEditor.vue +++ b/frontend/src/components/pure/ms-minder-editor/main/mainEditor.vue @@ -27,6 +27,7 @@ import minderHeader from './header.vue'; import Navigator from './navigator.vue'; + import useLeaveUnSaveTip from '@/hooks/useLeaveUnSaveTip'; import useMinderStore from '@/store/modules/components/minder-editor'; import { findNodePathByKey, replaceNodeInTree } from '@/utils'; @@ -63,6 +64,11 @@ }>(); const minderStore = useMinderStore(); + const { setIsSave } = useLeaveUnSaveTip({ + leaveContent: 'ms.minders.leaveUnsavedTip', + leaveTitle: 'common.unSaveLeaveTitle', + tipType: 'warning', + }); const mec: Ref = ref(null); const importJson = defineModel('importJson', { required: true, @@ -72,7 +78,6 @@ template: 'default', treePath: [], }); - const minderUnsaved = ref(false); function handlePriorityButton() { const { priorityPrefix } = props; @@ -148,7 +153,7 @@ 'zoomOut', ]); if (selectNodes && !notChangeCommands.has(env.commandName.toLocaleLowerCase())) { - minderUnsaved.value = true; + minderStore.setMinderUnsaved(true); minderStore.dispatchEvent(MinderEventName.MINDER_CHANGED); selectNodes.forEach((node: MinderJsonNode) => { markChangeNode(node); @@ -179,7 +184,7 @@ * @param node 切换的节点 */ function switchNode(node: MinderJsonNode | MinderJsonNodeData) { - if (minderUnsaved.value) { + if (minderStore.minderUnsaved) { // 切换前,如果脑图未保存,先把更改的节点信息同步一次 replaceNodeInTree( [importJson.value.root], @@ -232,10 +237,17 @@ data = window.minder.exportJson(); } emit('save', data, () => { - minderUnsaved.value = false; + minderStore.setMinderUnsaved(false); menuVisible.value = false; }); } + + watch( + () => minderStore.getMinderUnsaved, + (val) => { + setIsSave(!val); + } + );