|
@@ -106,6 +106,8 @@ import asideData from "./aside/asideData.vue"
|
|
|
|
|
|
import node from "@/assets/img/node.png"
|
|
|
|
|
|
+import { debounce } from 'lodash-es'
|
|
|
+
|
|
|
// 获取路由实例
|
|
|
const router = useRouter()
|
|
|
|
|
@@ -159,6 +161,10 @@ const props = defineProps({
|
|
|
}
|
|
|
})
|
|
|
|
|
|
+const debouncedSave = debounce(() => {
|
|
|
+ saveproject()
|
|
|
+}, 500) // 500ms 防抖
|
|
|
+
|
|
|
|
|
|
// 处理节点拖动时的网格吸附
|
|
|
onNodeDrag(({ node }) => {
|
|
@@ -204,6 +210,8 @@ watch(
|
|
|
|
|
|
// 更新快照
|
|
|
prevNodes = [...newNodes]
|
|
|
+
|
|
|
+ debouncedSave();
|
|
|
},
|
|
|
{ deep: true }
|
|
|
)
|
|
@@ -249,6 +257,7 @@ watch(
|
|
|
|
|
|
// 更新快照
|
|
|
prevEdges = [...newEdges]
|
|
|
+ debouncedSave();
|
|
|
},
|
|
|
{ deep: true }
|
|
|
)
|
|
@@ -758,24 +767,24 @@ const closePanel = () => {
|
|
|
}
|
|
|
|
|
|
// 路由切换前保存
|
|
|
-router.beforeEach(async (to, from, next) => {
|
|
|
- if (to.path !== from.path) {
|
|
|
- try {
|
|
|
- await saveproject() // 直接调用 saveproject
|
|
|
- next()
|
|
|
- } catch (error) {
|
|
|
- console.error("路由切换保存失败:", error)
|
|
|
- next() // 即使保存失败也允许切换路由
|
|
|
- }
|
|
|
- } else {
|
|
|
- next()
|
|
|
- }
|
|
|
-})
|
|
|
-
|
|
|
-// 组件卸载前保存
|
|
|
-onBeforeUnmount(async () => {
|
|
|
- await saveproject() // 直接调用 saveproject
|
|
|
-})
|
|
|
+// router.beforeEach(async (to, from, next) => {
|
|
|
+// if (to.path !== from.path) {
|
|
|
+// try {
|
|
|
+// await saveproject() // 直接调用 saveproject
|
|
|
+// next()
|
|
|
+// } catch (error) {
|
|
|
+// console.error("路由切换保存失败:", error)
|
|
|
+// next() // 即使保存失败也允许切换路由
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// next()
|
|
|
+// }
|
|
|
+// })
|
|
|
+
|
|
|
+// // 组件卸载前保存
|
|
|
+// onBeforeUnmount(async () => {
|
|
|
+// await saveproject() // 直接调用 saveproject
|
|
|
+// })
|
|
|
|
|
|
defineExpose({
|
|
|
resetTransform,
|