Pārlūkot izejas kodu

Fixes selection state inconsistency on empty page

yz 2 nedēļas atpakaļ
vecāks
revīzija
2a73903deb
2 mainītis faili ar 30 papildinājumiem un 0 dzēšanām
  1. 10 0
      src/utils/selection-manager.js
  2. 20 0
      src/views/order/factory/index.vue

+ 10 - 0
src/utils/selection-manager.js

@@ -138,6 +138,16 @@ class SelectionManager {
     // 清除当前页选择标记
     this.currentPageSelections.clear();
 
+    // 【核心修复】当当前页选择为空时,清理所有选择状态
+    if (currentPageList.length === 0) {
+      console.log('SelectionManager: 当前页无选择,清空所有选择状态');
+      const wasCount = this.selections.size;
+      this.clearAllSelections();
+      console.log(`SelectionManager: 已清空 ${wasCount} 个选择记录`);
+      return;  // 直接返回,不再执行后续逻辑
+    }
+
+
     // 添加当前页选择
     currentPageList.forEach(order => {
       if (order && order.id) {

+ 20 - 0
src/views/order/factory/index.vue

@@ -326,6 +326,26 @@ export default {
       if (selectionManager && this.lifecycleManager) {
         selectionManager.mergeWithCurrentPage(list);
         this.updateSelectionUI();
+
+
+      // 【新增保护】当当前页选择为空时,确保avue-crud状态同步
+        if (list.length === 0) {
+          this.$nextTick(() => {
+            // 延迟检查,确保选择管理器已处理完成
+            const actualCount = selectionManager.getSelectionCount();
+
+            // 如果选择管理器仍有数据(异常情况),强制清空
+            if (actualCount > 0) {
+              console.warn('FactoryOrder: 检测到选择状态不一致,强制同步');
+              // 双重确保清空
+              if (this.$refs.crud) {
+                this.$refs.crud.clearSelection();
+              }
+              // 强制同步UI
+              this.updateSelectionUI();
+            }
+          });
+        }
       }
     },
     /** 页码变化:保持搜索条件不丢失并重新加载 */