Browse Source

JLHWEB: 1、修复页面缓存/刷新问题

JohnnyChan 1 ngày trước cách đây
mục cha
commit
1397c0a80e

+ 5 - 1
JLHWEB/src/layouts/components/Main/index.vue

@@ -98,7 +98,11 @@ const getRouteKey = (route: any) => {
   // const keepAliveStore1 = useKeepAliveStore();
   let routeItem = keepAliveStore.getKeepAliveName(route.fullPath);
   console.log("getKeepAliveName routeItem getRouteKey:>> ", routeItem, route.fullPath);
-  return routeItem.fullPath + "_" + routeItem.times;
+  if (routeItem) {
+    return routeItem.fullPath + "_" + routeItem.times;
+  } else {
+    return route.fullPath;
+  }
 };
 
 const tabsRef = ref();

+ 1 - 1
JLHWEB/src/routers/modules/erpApiRouter.ts

@@ -91,7 +91,7 @@ export const erpApiRouter: Menu.MenuOptions[] = [
               isHide: true,
               isFull: false,
               isAffix: false,
-              isKeepAlive: false,
+              isKeepAlive: true,
               funid: 71,
               activeMenu: "/erpapi/mattressInterface"
             }

+ 1 - 0
JLHWEB/src/stores/interface/index.ts

@@ -250,6 +250,7 @@ export interface CommonMenuItem {
 export interface KeepAliveState {
   keepAliveName: string[];
   keepAliveList: KeepAliveListState[];
+  closeAliveList: KeepAliveListState[];
 }
 
 export interface KeepAliveListState {

+ 31 - 10
JLHWEB/src/stores/modules/keepAlive.ts

@@ -7,7 +7,8 @@ export const useKeepAliveStore = defineStore({
   id: "geeker-keepAlive",
   state: (): KeepAliveState => ({
     keepAliveName: [],
-    keepAliveList: []
+    keepAliveList: [],
+    closeAliveList: []
   }),
   getters: {
     getKeepAliveList(): any[] {
@@ -26,11 +27,19 @@ export const useKeepAliveStore = defineStore({
       !this.keepAliveName.includes(route.name) && this.keepAliveName.push(route.name);
 
       let routeItem = this.keepAliveList.find((item: any) => item.fullPath == route.fullPath);
+      console.log("getKeepAliveName routeItem addKeepAliveName :>> ", JSON.stringify(this.keepAliveList));
+
+      console.log("getKeepAliveName routeItem removeKeepAliveName closeAliveList:>> ", JSON.stringify(this.closeAliveList));
       if (!routeItem) {
+        let closeItem = this.closeAliveList.find((item: any) => item.fullPath == route.fullPath);
         routeItem = {
           fullPath: route.fullPath,
           times: 0
         };
+        if (closeItem) {
+          routeItem.times = closeItem.times + 1;
+          this.closeAliveList = this.closeAliveList.filter((item: any) => item.fullPath != route.fullPath);
+        }
         this.keepAliveList.push(routeItem);
       }
     },
@@ -40,11 +49,13 @@ export const useKeepAliveStore = defineStore({
 
       let index = this.keepAliveList.findIndex(item => item.fullPath === route.path);
       if (index > -1) {
-        // this.keepAliveList.splice(index, 1);
-        this.keepAliveList[index].times = this.keepAliveList[index].times + 1;
+        if (this.closeAliveList.every(item => item.fullPath !== route.path)) {
+          this.closeAliveList.push(this.keepAliveList[index]);
+        }
+        this.keepAliveList.splice(index, 1);
+        // this.keepAliveList[index].times = this.keepAliveList[index].times + 1;
       }
-
-      console.log("getKeepAliveName routeItem removeKeepAliveName :>> ", JSON.stringify(this.keepAliveList));
+      console.log("getKeepAliveName routeItem removeKeepAliveName :>> ", index, JSON.stringify(this.keepAliveList));
       console.log("getKeepAliveName routeItem removeKeepAliveName :>> ", this.keepAliveList);
       console.log("getKeepAliveName routeItem keepAliveName :>> ", this.keepAliveName);
     },
@@ -65,11 +76,12 @@ export const useKeepAliveStore = defineStore({
     getKeepAliveName(name: string) {
       let routeItem = this.keepAliveList.find((item: any) => item.fullPath == name);
       if (!routeItem) {
-        routeItem = {
-          fullPath: name,
-          times: 0
-        };
-        this.keepAliveList.push(routeItem);
+        // routeItem = {
+        //   fullPath: name,
+        //   times: 0
+        // };
+        // this.keepAliveList.push(routeItem);
+        return undefined;
       }
       return routeItem;
     },
@@ -102,6 +114,14 @@ export const useKeepAliveStore = defineStore({
         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?";
@@ -185,6 +205,7 @@ export const useKeepAliveStore = defineStore({
       // }
       !isReplace && tabStore.addTabs(tabsParams);
       !isReplace && to.meta.isKeepAlive && this.addKeepAliveName(to);
+      console.log("!isReplace && to.meta.isKeepAlive => ", Boolean(!isReplace), Boolean(to.meta.isKeepAlive));
     }
   }
 });

+ 1 - 1
JLHWEB/src/views/erpapi/mattressInterface/detail.vue

@@ -125,7 +125,7 @@ interface detailProp {
   /**
    * @description 是否可编辑
    */
-  status: "edit" | "new" | string;
+  status?: "edit" | "new" | string;
   enum?: any;
 }