bill 8 miesięcy temu
rodzic
commit
227e01ea7a

+ 1 - 1
src/api/path.ts

@@ -65,5 +65,5 @@ export const postUpdatePath = (path: Path) => {
 };
 
 export const postDeletePath = (id: Path["id"]) => {
-  return axios.post<undefined>(DELETE_PATH, { pathId: id });
+  return axios.post<undefined>(DELETE_PATH, { id: id });
 };

+ 3 - 0
src/store/path.ts

@@ -97,6 +97,9 @@ export const autoSavePaths = autoSetModeCallback(paths, {
     if (!paths.value.every(record => record.name)) {
       Message.warning('路径名称不可为空')
       throw '路径名称不可为空'
+    } else if (paths.value.some(path => path.points.length <= 1)) {
+      Message.warning('路径点不可少于两个')
+      throw '路径点不可少于两个'
     }
     await savePaths()
   }

+ 116 - 95
src/store/sys.ts

@@ -1,10 +1,10 @@
-import { ref, computed, watch, nextTick, watchEffect } from 'vue'
-import { asyncBusFactory } from '@/utils'
-import { Dialog } from 'bill/index'
-import { useViewStack } from '@/hook'
+import { ref, computed, watch, nextTick, watchEffect } from "vue";
+import { asyncBusFactory } from "@/utils";
+import { Dialog } from "bill/index";
+import { useViewStack } from "@/hook";
 
-import type { UnwrapRef } from 'vue'
-import { currentMeta } from '@/router'
+import type { UnwrapRef } from "vue";
+import { currentMeta } from "@/router";
 
 const Flags = {
   EDIT: 0b10,
@@ -12,130 +12,151 @@ const Flags = {
   NOW: 0b100,
   // 可写模式,用户已登陆
   LOGIN: 0b1000,
-} as const
-const mode = ref<number>(Flags.NOW)
+} as const;
+const mode = ref<number>(Flags.NOW);
 
-export const isEdit = computed(() => !!(mode.value & Flags.EDIT))
-export const isLogin = computed(() => !!(mode.value & Flags.LOGIN))
-export const isOld = computed(() => !(mode.value & Flags.NOW))
-export const isNow = computed(() => !!(mode.value & Flags.NOW))
-export const appEl = ref<HTMLDivElement | null>(null)
-export const prefix = ref('')
+export const isEdit = computed(() => !!(mode.value & Flags.EDIT));
+export const isLogin = computed(() => !!(mode.value & Flags.LOGIN));
+export const isOld = computed(() => !(mode.value & Flags.NOW));
+export const isNow = computed(() => !!(mode.value & Flags.NOW));
+export const appEl = ref<HTMLDivElement | null>(null);
+export const prefix = ref("");
 
-export const defTitle = ref('案件信息')
+export const defTitle = ref("案件信息");
 export const title = computed(() => {
-  console.error(currentMeta.value)
-  const last = currentMeta.value && 'sysTitle' in currentMeta.value
-    ? currentMeta.value.sysTitle
-    : defTitle.value
+  console.error(currentMeta.value);
+  const last =
+    currentMeta.value && "sysTitle" in currentMeta.value
+      ? currentMeta.value.sysTitle
+      : defTitle.value;
 
-  console.error(prefix.value)
+  console.error(prefix.value);
   if (prefix.value && last) {
-    return prefix.value + ' | ' + last
+    return prefix.value + " | " + last;
   } else {
-    return prefix.value + last
+    return prefix.value + last;
   }
-})
-watchEffect(() => (document.title = title.value))
+});
+watchEffect(() => (document.title = title.value));
 
-let currentTempIndex = 0
-export const isTemploraryID = (id: string) => id.includes('__currentTempIndex__')
-export const createTemploraryID = () => `__currentTempIndex__${currentTempIndex++}`
+let currentTempIndex = 0;
+export const isTemploraryID = (id: string) =>
+  id.includes("__currentTempIndex__");
+export const createTemploraryID = () =>
+  `__currentTempIndex__${currentTempIndex++}`;
 
-export const sysBus = asyncBusFactory<{ save: void; leave: void }>()
+export const sysBus = asyncBusFactory<{ save: void; leave: void }>();
 
 // 进入编辑界面
 export const enterEdit = (cb?: () => void) => {
-  mode.value |= Flags.EDIT
-  cb && sysBus.on('leave', cb)
-}
+  mode.value |= Flags.EDIT;
+  cb && sysBus.on("leave", cb);
+};
 
 export const enterOld = (cb?: () => void) => {
-  mode.value &= ~Flags.NOW
-  cb && sysBus.on('save', cb)
-}
+  mode.value &= ~Flags.NOW;
+  cb && sysBus.on("save", cb);
+};
 
 // 放弃保存内容
 export const giveupSave = () => {
-  sysBus.off('save')
-  mode.value |= Flags.NOW
-}
+  sysBus.off("save");
+  mode.value |= Flags.NOW;
+};
 
 // 放弃编辑内容
 export const giveupLeave = () => {
-  giveupSave()
-  sysBus.off('leave')
-  mode.value &= ~Flags.EDIT
-}
+  giveupSave();
+  sysBus.off("leave");
+  mode.value &= ~Flags.EDIT;
+};
 
 // 保存
 export const save = async () => {
-  await sysBus.emit('save')
-  giveupSave()
-  leave()
-}
+  await sysBus.emit("save");
+  giveupSave();
+  leave();
+};
 
 // 离开
 export const leave = async () => {
-  if (isOld.value && !(await Dialog.confirm('您有操作未保存,确定要退出吗?'))) {
+  if (
+    isOld.value &&
+    !(await Dialog.confirm("您有操作未保存,确定要退出吗?"))
+  ) {
     return;
   }
-  await sysBus.emit('leave')
-  giveupLeave()
-}
+  await sysBus.emit("leave");
+  giveupLeave();
+};
 
 export type AutoSetModeSetting<T> = {
-  save: () => any
-  leave?: () => any
-  isUpdate?: (newCurrent: UnwrapRef<T>, oldCurrent?: UnwrapRef<T>) => boolean
-  auto?: boolean
-  backup?: () => void
-  recovery?: () => void
-}
-
-let isUnset = false
+  save: () => any;
+  leave?: () => any;
+  isUpdate?: (newCurrent: UnwrapRef<T>, oldCurrent?: UnwrapRef<T>) => boolean;
+  auto?: boolean;
+  backup?: () => void;
+  recovery?: () => void;
+};
+
+let isUnset = false;
 export const unSetModelUpdate = (run: () => void) => {
-  isUnset = true
-  run()
-  nextTick(() => isUnset = false)
-}
-export const autoSetModeCallback = <T extends object>(current: T, setting: AutoSetModeSetting<T>, last = true) => {
-  let isLeaveIng = false
-  let isSave = false
-  const leaveCallback = (setting.recovery || setting.backup)
-    && (async () => {
-      isLeaveIng = true
-      setting.recovery && await setting.recovery()
-      setting.backup && await setting.backup()
-      setting.leave && await setting.leave()
-      isLeaveIng = false
-    })
-  
+  isUnset = true;
+  run();
+  nextTick(() => (isUnset = false));
+};
+export const autoSetModeCallback = <T extends object>(
+  current: T,
+  setting: AutoSetModeSetting<T>,
+  last = true
+) => {
+  let isLeaveIng = false;
+  let isSave = false;
+  const leaveCallback =
+    (setting.recovery || setting.backup) &&
+    (async () => {
+      console.log("???", isLeaveIng);
+      isLeaveIng = true;
+      setting.recovery && (await setting.recovery());
+      setting.backup && (await setting.backup());
+      setting.leave && (await setting.leave());
+      isLeaveIng = false;
+    });
+
   const saveCallback = async () => {
-    leaveCallback && sysBus.off('leave', leaveCallback, { last })
-    isSave = true
-    await setting.save()
-    setting.backup && setting.backup()
-    isSave = false
-  }
+    leaveCallback && sysBus.off("leave", leaveCallback, { last });
+    isSave = true;
+    try {
+      await setting.save();
+      setting.backup && setting.backup();
+      isSave = false;
+    } catch (e) {
+      isSave = false;
+      throw e;
+    }
+  };
 
   const handler = (newv: UnwrapRef<T>, oldv?: UnwrapRef<T>) => {
-    if (isSave || isUnset || isLeaveIng) return
+    if (isSave || isUnset || isLeaveIng) return;
     if (!setting.isUpdate || setting.isUpdate(newv, oldv)) {
-      isEdit.value || enterEdit()
-      isOld.value ||  enterOld()
-      saveCallback && sysBus.on('save', saveCallback, { last })
+      isEdit.value || enterEdit();
+      isOld.value || enterOld();
+      saveCallback && sysBus.on("save", saveCallback, { last });
     }
-    leaveCallback && sysBus.on('leave', leaveCallback, { last })
-  }
+    leaveCallback && sysBus.on("leave", leaveCallback, { last });
+  };
 
   return () => {
-    setting.backup && setting.backup()
-    return watch(current as any, handler, { deep: true })
-  }
-}
-
-export const useAutoSetMode = <T extends object>(current: T, setting: AutoSetModeSetting<T>, last = true) => {
-  const startWatch = autoSetModeCallback(current, setting, last)
-  useViewStack(startWatch)
-}
+    setting.backup && setting.backup();
+    return watch(current as any, handler, { deep: true });
+  };
+};
+
+export const useAutoSetMode = <T extends object>(
+  current: T,
+  setting: AutoSetModeSetting<T>,
+  last = true
+) => {
+  const startWatch = autoSetModeCallback(current, setting, last);
+  useViewStack(startWatch);
+};

+ 0 - 1
src/views/guide/path/edit-path.vue

@@ -225,7 +225,6 @@ const keepAdding = () => {
   const hide = Message.show({ msg: "请在模型上单击选择路径点位置", type: "warning" });
 
   unKeepAdding.value = () => {
-    console.error("????");
     node.value?.changeCanEdit(false);
     hide();
     unKeepAdding.value = void 0;

+ 13 - 2
src/views/guide/path/edit.vue

@@ -25,11 +25,20 @@ import PathSign from "./sign.vue";
 import EditPath from "./edit-path.vue";
 import { getPathNode, pathsGroup } from "@/sdk/association/path";
 import { useViewStack } from "@/hook";
-import { paths, enterEdit, sysBus, autoSavePaths, createPath, enterOld } from "@/store";
+import {
+  paths,
+  enterEdit,
+  sysBus,
+  autoSavePaths,
+  createPath,
+  enterOld,
+  save,
+} from "@/store";
 
 import type { Path } from "@/store";
 import { Dialog } from "bill/expose-common";
 import { showPathsStack, showPathStack } from "@/env";
+import { asyncTimeout } from "@/utils";
 
 const currentPath = ref<Path | null>();
 const leaveEdit = () => {
@@ -38,7 +47,9 @@ const leaveEdit = () => {
   showPathsStack.pop();
   showPathStack.pop();
 };
-const edit = (path?: Path) => {
+const edit = async (path?: Path) => {
+  await save();
+  await asyncTimeout(16);
   if (!path) {
     path = createPath();
     paths.value.unshift(path);

+ 3 - 0
src/views/measure/index.vue

@@ -60,6 +60,9 @@ import { useViewStack } from "@/hook";
 import type { Measure } from "@/store";
 import type { ActionsItem } from "@/components/actions/index.vue";
 import { asyncTimeout } from "@/utils";
+setTimeout(() => {
+  measures.value.length = 0;
+}, 1000);
 const keyword = ref("");
 const filterMeasures = computed(() =>
   measures.value.filter((measure) => measure.desc.includes(keyword.value))