Przeglądaj źródła

perfect_newfile

ananzhusen 2 lat temu
rodzic
commit
0d02389ab5
3 zmienionych plików z 16 dodań i 7 usunięć
  1. 14 5
      src/services/common.ts
  2. 1 1
      src/services/utils.ts
  3. 1 1
      src/views/components/View.vue

+ 14 - 5
src/services/common.ts

@@ -252,6 +252,7 @@ export const save = async (
   // setDot(false);
   dot.value = false;
   localforage.removeItem(localMeta2dDataName);
+  return true;
 };
 const pen = ref(false);
 const drawPen = () => {
@@ -310,8 +311,10 @@ export const showMap = () => {
 
 export const title = "系统可能不会保存您所做的更改,是否继续?";
 export const unLogin = "未登录,系统可能不会保存您的文件,是否继续?";
+export const unsave = "当前文件未保存,是否继续?(开通vip可享受自动保存服务)";
+
 //未登录,当前文件可能不会保存
-// 当前文件未保存,请先手动保存!(开通vip可享受自动保存服务)
+//
 export const newFile = async () => {
   if (!(user && user.id)) {
     if (await showNotification(unLogin)) {
@@ -319,8 +322,15 @@ export const newFile = async () => {
     }
   } else {
     if (dot.value) {
-      if (await showNotification(title)) {
-        newfile(false);
+      if (!user.vipExpired) {
+        if (await save(SaveType.Save)) {
+          //TODO 保存报错了需要save吗
+          newfile(false);
+        }
+      } else {
+        if (await showNotification(unsave)) {
+          newfile(false);
+        }
       }
     } else {
       newfile(false);
@@ -349,10 +359,9 @@ export const newfile = async (noRouter: boolean = false) => {
   meta2d.map?.isShow && showMap();
   // setDot(false);
   dot.value = false;
-  // await localforage.removeItem(localMeta2dDataName);
+  await localforage.removeItem(localMeta2dDataName);
   // 打开文件操作不跳转
   // const router = useRouter();
-  console.log("router", router);
   !noRouter &&
     router.replace({
       path: "/",

+ 1 - 1
src/services/utils.ts

@@ -54,7 +54,7 @@ export function showNotification(title: string): Promise<boolean> {
           notification.value = null;
           resolve(false);
         },
-        duration: 1000000,
+        // duration: 1000000,
         footer: h(
           Button,
           {

+ 1 - 1
src/views/components/View.vue

@@ -318,7 +318,7 @@ onMounted(() => {
 });
 
 const watcher = watch(
-  () => route.query.id,
+  () => route.query,
   async () => {
     open();
   }