瀏覽代碼

1、修复编辑页->详情页,不会删除编辑页缓存问题
2、修复切换tab进行多次上锁问题

MY 2 天之前
父節點
當前提交
6e16771cf6
共有 2 個文件被更改,包括 21 次插入66 次删除
  1. 9 9
      JLHWEB/src/routers/index.ts
  2. 12 57
      JLHWEB/src/stores/modules/keepAlive.ts

+ 9 - 9
JLHWEB/src/routers/index.ts

@@ -89,16 +89,16 @@ router.beforeEach(async (to, from, next) => {
 
   // 8.如果需要加锁的路由,进入时尝试加锁
   if (to.meta.needLock && Number(to.query.id)) {
-    // const keepAliveStore = useKeepAliveStore();
-    // const routeItem = keepAliveStore.getKeepAliveName(to.fullPath);
-    // if (!routeItem) {
-    try {
-      await LockBill({ keyword: String(to.meta.billtype), billid: Number(to.query.id), billcode: String(to.query.code) });
-    } catch (err) {
-      to.meta.aborted = true;
-      return next(false);
+    const keepAliveStore = useKeepAliveStore();
+    const routeItem = keepAliveStore.getKeepAliveName(to.fullPath);
+    if (!routeItem) {
+      try {
+        await LockBill({ keyword: String(to.meta.billtype), billid: Number(to.query.id), billcode: String(to.query.code) });
+      } catch (err) {
+        to.meta.aborted = true;
+        return next(false);
+      }
     }
-    // }
   }
 
   // 9.判断用户是否拥有权限,没有权限重定向到 403 页面

+ 12 - 57
JLHWEB/src/stores/modules/keepAlive.ts

@@ -48,9 +48,9 @@ export const useKeepAliveStore = defineStore({
     removeKeepAliveName(route: any) {
       this.keepAliveName = this.keepAliveName.filter(item => item !== route.name);
 
-      let index = this.keepAliveList.findIndex(item => item.fullPath === route.path);
+      let index = this.keepAliveList.findIndex(item => item.fullPath === route.fullPath);
       if (index > -1) {
-        if (this.closeAliveList.every(item => item.fullPath !== route.path)) {
+        if (this.closeAliveList.every(item => item.fullPath !== route.fullPath)) {
           this.closeAliveList.push(this.keepAliveList[index]);
         }
         this.keepAliveList.splice(index, 1);
@@ -75,7 +75,7 @@ export const useKeepAliveStore = defineStore({
       this.keepAliveName = keepAliveName;
     },
     async updateKeepAliveName(route: any) {
-      this.addKeepAliveName(route);
+      // this.addKeepAliveName(route);
       console.log("updateKeepAliveName route :>> ", route, this.keepAliveList);
       this.keepAliveList.forEach((item: any) => {
         console.log("updateKeepAliveName item :>> ", item.fullPath, route.fullPath, item.fullPath == route.fullPath);
@@ -103,6 +103,7 @@ export const useKeepAliveStore = defineStore({
         icon: to.meta.icon as string,
         title: to.meta.title as string,
         path: to.fullPath,
+        fullPath: to.fullPath,
         name: to.name as string,
         close: !to.meta.isAffix
       };
@@ -127,34 +128,7 @@ export const useKeepAliveStore = defineStore({
         });
       }
 
-      console.log("tabStore :>> ", tabStore, to);
-      console.log("tabsParams router:>> ", tabsParams);
       let isReplace = false;
-      // console.log(
-      //   'tabsParams.path.indexOf("/edit?") > -1 , :>> ',
-      //   tabsParams.path.indexOf("/edit?") > -1,
-      //   tabsParams.path.indexOf("/edit/") > -1
-      // );
-      // console.log(
-      //   'tabsParams.path.indexOf("/detail?") > -1 , :>> ',
-      //   tabsParams.path.indexOf("/detail?") > -1,
-      //   tabsParams.path.indexOf("/detail/") > -1
-      // );
-      console.log(
-        'to.fullPath.split("?")[0] != from.fullPath.split("?")[0] :>> ',
-        to.fullPath.split("?")[0],
-        from.fullPath.split("?")[0],
-        to.fullPath.split("?")[0] != from.fullPath.split("?")[0]
-      );
-      console.log(
-        'tabsParams.path.indexOf("/edit?") > -1 || tabsParams.path.indexOf("/edit/") > -1 :>> ',
-        Boolean(tabsParams.path.indexOf("/edit?") > -1 || tabsParams.path.indexOf("/edit/") > -1)
-      );
-      console.log(
-        'tabsParams.path.indexOf("/detail?") > -1 || tabsParams.path.indexOf("/detail/") > -1 :>> ',
-        Boolean(tabsParams.path.indexOf("/detail?") > -1 || tabsParams.path.indexOf("/detail/") > -1)
-      );
-      // if (from.meta?.activeMenu == to.meta?.activeMenu && to.fullPath.split("?")[0] != from.fullPath.split("?")[0]) {
       if (tabsParams.path.indexOf("/edit?") > -1 || tabsParams.path.indexOf("/edit/") > -1) {
         let key = "/edit?";
         let name = "";
@@ -171,18 +145,6 @@ export const useKeepAliveStore = defineStore({
             (hasPath1 && tabsMenuList[i].path == _path) ||
             (hasPath2 && tabsMenuList[i].path.split("?")[0] == _path2.split("?")[0])
           ) {
-            console.log(
-              "computedKeepAliveName edit ====>",
-              i,
-              tabsMenuList[i].path,
-              _path,
-              tabsMenuList[i].path == _path,
-              hasPath2,
-              tabsMenuList[i].path.split("?")[0],
-              _path2.split("?")[0],
-              tabsMenuList[i].path.split("?")[0] == _path2.split("?")[0],
-              tabsMenuList[i]
-            );
             name = tabsMenuList[i].name;
             tabsMenuList[i] = tabsParams;
             isReplace = true;
@@ -191,7 +153,10 @@ export const useKeepAliveStore = defineStore({
         }
         console.log("keilll name edit:>> ", name);
         tabStore.setTabs(tabsMenuList);
-        name && this.updateKeepAliveName(to);
+        isReplace && this.addKeepAliveName(to);
+        isReplace && this.removeKeepAliveName(from);
+        name && to.meta.isKeepAlive && this.updateKeepAliveName(to);
+        // name && this.updateKeepAliveName(to);
         // to.meta.isKeepAlive && this.updateKeepAliveName(route);
       } else if (tabsParams.path.indexOf("/detail?") > -1 || tabsParams.path.indexOf("/detail/") > -1) {
         let key = "/detail?";
@@ -211,17 +176,6 @@ export const useKeepAliveStore = defineStore({
                 (tabsMenuList[i].path == from.fullPath && from.fullPath.indexOf("/copy?") > -1))) ||
             (hasPath2 && tabsMenuList[i].path.split("?")[0] == _path2.split("?")[0])
           ) {
-            console.log(
-              "computedKeepAliveName detail ====>",
-              tabsMenuList[i].path,
-              _path,
-              tabsMenuList[i].path == _path,
-              hasPath2,
-              tabsMenuList[i].path.split("?")[0],
-              _path2.split("?")[0],
-              tabsMenuList[i].path.split("?")[0] == _path2.split("?")[0],
-              tabsMenuList[i]
-            );
             name = tabsMenuList[i].name;
             tabsMenuList[i] = tabsParams;
             isReplace = true;
@@ -230,14 +184,15 @@ export const useKeepAliveStore = defineStore({
         }
         tabStore.setTabs(tabsMenuList);
         console.log("keilll name detail:>> ", name);
-        name && this.updateKeepAliveName(to);
+        isReplace && this.addKeepAliveName(to);
+        isReplace && this.removeKeepAliveName(from);
+        name && to.meta.isKeepAlive && this.updateKeepAliveName(to);
+        // name && this.updateKeepAliveName(to);
         // to.meta.isKeepAlive && this.addKeepAliveName(to);
-        console.log("add this.keepAliveName :>> ", this.keepAliveName);
       }
       // }
       !isReplace && tabStore.addTabs(tabsParams);
       !isReplace && to.meta.isKeepAlive && this.addKeepAliveName(to);
-      console.log("!isReplace && to.meta.isKeepAlive => ", Boolean(!isReplace), Boolean(to.meta.isKeepAlive));
     }
   }
 });