Jelajahi Sumber

床垫报价-修复业务补充替换报价tab问题

MY 2 minggu lalu
induk
melakukan
a7dcd7ee3f
1 mengubah file dengan 54 tambahan dan 42 penghapusan
  1. 54 42
      JLHWEB/src/stores/modules/keepAlive.ts

+ 54 - 42
JLHWEB/src/stores/modules/keepAlive.ts

@@ -286,26 +286,52 @@ export const useKeepAliveStore = defineStore({
       let isReplace = false;
       const tabsMenuList = [...tabStore.tabsMenuList];
 
-      // 判断是否为同一单据的单据编码
+      // 判断是否为同一单据的单据编码和单据类型
       const getBillCode = route => {
         return route?.query?.code || "";
       };
+      const getBillType = route => {
+        const pathMatch = route?.fullPath?.match(/\/([a-zA-Z]+)\/(detail|edit|copy|index)/);
+        return pathMatch ? pathMatch[1] : "";
+      };
+
       const toBillCode = getBillCode(to);
       const fromBillCode = getBillCode(from);
+      const toBillType = getBillType(to);
+      const fromBillType = getBillType(from);
+
+      // 判断是否为相同类型的单据(同时比较单据编码和单据类型)
+      const isSameBill = (code1, type1, code2, type2) => {
+        return code1 && code2 && code1 === code2 && type1 && type2 && type1 === type2;
+      };
+
+      console.log("computedKeepAliveNamePro 路由分析:", {
+        to: to.fullPath,
+        from: from?.fullPath,
+        toBillCode,
+        toBillType,
+        fromBillCode,
+        fromBillType,
+        isSameBillType: isSameBill(toBillCode, toBillType, fromBillCode, fromBillType)
+      });
 
       // 情况1: 列表页跳转到详情页 (/list -> /detail)
       const isListToDetail =
         (!from || from.fullPath.includes("/index")) && (to.fullPath.includes("/detail?") || to.fullPath.includes("/detail/"));
 
       if (isListToDetail && toBillCode) {
-        // 查找是否有相同单据的编辑页
+        // 查找是否有相同单据类型和单据编码的编辑页
         const editTabIndex = tabsMenuList.findIndex(item => {
           const itemBillCode = getBillCode(item);
-          return itemBillCode === toBillCode && (item.path.includes("/edit?") || item.path.includes("/edit/"));
+          const itemBillType = getBillType(item);
+          return (
+            isSameBill(itemBillCode, itemBillType, toBillCode, toBillType) &&
+            (item.path.includes("/edit?") || item.path.includes("/edit/"))
+          );
         });
 
         if (editTabIndex > -1) {
-          // 保存被替换的编辑页信息,用于解锁
+          // 保存被替换的编辑页信息
           const oldEditTab = tabsMenuList[editTabIndex];
 
           // 替换编辑页为详情页
@@ -313,16 +339,8 @@ export const useKeepAliveStore = defineStore({
           tabsMenuList[editTabIndex] = tabsParams;
           tabStore.setTabs(tabsMenuList);
 
-          // 如果被替换的编辑页需要锁定,解锁单据
-          if (oldEditTab.needLock && oldEditTab.billid) {
-            UnLockBill({
-              keyword: oldEditTab.keyword,
-              billid: oldEditTab.billid,
-              billcode: oldEditTab.billcode
-            }).catch(err => {
-              console.warn("替换编辑页时解锁失败:", err);
-            });
-          }
+          // 移除编辑页的 keepAlive 缓存(removeKeepAliveName 已包含解锁逻辑)
+          this.removeKeepAliveName(oldEditTab);
 
           isReplace = true;
           to.meta.isKeepAlive && this.addKeepAliveName(to);
@@ -335,23 +353,24 @@ export const useKeepAliveStore = defineStore({
         from &&
         (from.fullPath.includes("/detail?") || from.fullPath.includes("/detail/")) &&
         (to.fullPath.includes("/edit?") || to.fullPath.includes("/edit/")) &&
-        toBillCode &&
-        fromBillCode &&
-        toBillCode === fromBillCode;
+        isSameBill(toBillCode, toBillType, fromBillCode, fromBillType);
 
       if (isDetailToEdit) {
-        // 查找是否有相同单据的详情页
+        // 查找是否有相同单据类型和单据编码的详情页
         const detailTabIndex = tabsMenuList.findIndex(item => {
           const itemBillCode = getBillCode(item);
+          const itemBillType = getBillType(item);
           const isDetailTab = item.path.includes("/detail?") || item.path.includes("/detail/");
           console.log("检查tab:", {
             itemPath: item.path,
             itemBillCode,
+            itemBillType,
             toBillCode,
+            toBillType,
             isDetailTab,
-            match: itemBillCode === toBillCode && isDetailTab
+            match: isSameBill(itemBillCode, itemBillType, toBillCode, toBillType) && isDetailTab
           });
-          return itemBillCode === toBillCode && isDetailTab;
+          return isSameBill(itemBillCode, itemBillType, toBillCode, toBillType) && isDetailTab;
         });
 
         console.log("找到的详情页索引:", detailTabIndex);
@@ -371,24 +390,25 @@ export const useKeepAliveStore = defineStore({
         from &&
         (from.fullPath.includes("/edit?") || from.fullPath.includes("/edit/")) &&
         (to.fullPath.includes("/detail?") || to.fullPath.includes("/detail/")) &&
-        toBillCode &&
-        fromBillCode &&
-        toBillCode === fromBillCode;
+        isSameBill(toBillCode, toBillType, fromBillCode, fromBillType);
 
       if (isEditToDetailPro) {
-        console.log("编辑页->详情页: 解锁单据", fromBillCode);
-        // 查找是否有相同单据的编辑页
+        console.log("编辑页->详情页: 解锁单据", fromBillType, fromBillCode);
+        // 查找是否有相同单据类型和单据编码的编辑页
         const editTabIndex = tabsMenuList.findIndex(item => {
           const itemBillCode = getBillCode(item);
+          const itemBillType = getBillType(item);
           const isEditTab = item.path.includes("/edit?") || item.path.includes("/edit/");
           console.log("检查tab:", {
             itemPath: item.path,
             itemBillCode,
+            itemBillType,
             fromBillCode,
+            fromBillType,
             isEditTab,
-            match: itemBillCode === fromBillCode && isEditTab
+            match: isSameBill(itemBillCode, itemBillType, fromBillCode, fromBillType) && isEditTab
           });
-          return itemBillCode === fromBillCode && isEditTab;
+          return isSameBill(itemBillCode, itemBillType, fromBillCode, fromBillType) && isEditTab;
         });
 
         console.log("找到的编辑页索引:", editTabIndex);
@@ -398,20 +418,9 @@ export const useKeepAliveStore = defineStore({
           tabsMenuList[editTabIndex] = tabsParams;
           tabStore.setTabs(tabsMenuList);
 
-          // 关键修复:移除编辑页的 keepAlive 缓存,确保下次进入编辑页会触发加锁
+          // 移除编辑页的 keepAlive 缓存(removeKeepAliveName 已包含解锁逻辑)
           this.removeKeepAliveName(from);
 
-          if (from.meta?.needLock && from.query?.id) {
-            // 解锁单据
-            UnLockBill({
-              keyword: String(from.meta.billtype),
-              billid: Number(from.query.id),
-              billcode: String(from.query.code)
-            }).catch(err => {
-              console.warn("edit->detail 解锁失败:", err);
-            });
-          }
-
           isReplace = true;
           to.meta.isKeepAlive && this.addKeepAliveName(to);
           to.meta.isKeepAlive && this.updateKeepAliveName(to);
@@ -422,18 +431,21 @@ export const useKeepAliveStore = defineStore({
       const isListToEdit =
         (!from || from.fullPath.includes("/index")) && (to.fullPath.includes("/edit?") || to.fullPath.includes("/edit/"));
       if (isListToEdit && toBillCode) {
-        // 查找是否有相同单据的详情页
+        // 查找是否有相同单据类型和单据编码的详情页
         const detailTabIndex = tabsMenuList.findIndex(item => {
           const itemBillCode = getBillCode(item);
+          const itemBillType = getBillType(item);
           const isDetailTab = item.path.includes("/detail?") || item.path.includes("/detail/");
           console.log("检查tab:", {
             itemPath: item.path,
             itemBillCode,
+            itemBillType,
             toBillCode,
+            toBillType,
             isDetailTab,
-            match: itemBillCode === toBillCode && isDetailTab
+            match: isSameBill(itemBillCode, itemBillType, toBillCode, toBillType) && isDetailTab
           });
-          return itemBillCode === toBillCode && isDetailTab;
+          return isSameBill(itemBillCode, itemBillType, toBillCode, toBillType) && isDetailTab;
         });
 
         console.log("找到的详情页索引:", detailTabIndex);