Ver código fonte

🔧fix(item): refine file selection handling with individual and bulk operations

Shinohara Haruna 6 meses atrás
pai
commit
21eddc5258
1 arquivos alterados com 29 adições e 35 exclusões
  1. 29 35
      smsb-plus-ui/src/views/smsb/item/index.vue

+ 29 - 35
smsb-plus-ui/src/views/smsb/item/index.vue

@@ -114,7 +114,7 @@
           <!-- 界面名称输入框 -->
           <el-input v-model="itemName" placeholder="请输入轮播组名称" class="interface-input"></el-input>
 
-          <el-table ref="fileTable" :data="minioDataList" reserve-selection row-key="id" @selection-change="handleSelectionFile">
+          <el-table ref="fileTable" :data="minioDataList" reserve-selection row-key="id" @selection-change="handleSelectionFile" @select="handleSelect" @select-all="handleSelectAll">
             <el-table-column type="selection" width="55" header-align="center" />
             <el-table-column label="类型" header-align="center" prop="type" width="80">
               <template #default="scope">
@@ -410,45 +410,39 @@ const getFileList = async () => {
 };
 
 /** 多选框选中文件数据 */
+// selection-change 只做新增
 const handleSelectionFile = (selection: MinioDataVO[]) => {
-  // Get IDs of newly selected items
-  const newSelectionIds = new Set(selection.map(item => item.id));
-  
-  // Preserve existing selections that weren't in this batch
-  const preservedSelections = selectedFiles.value.filter(
-    f => !newSelectionIds.has(f.id)
-  );
-
-  // Get existing selections that were in this batch (to preserve their order)
-  const existingSelections = selectedFiles.value.filter(
-    f => newSelectionIds.has(f.id)
-  );
+  selection.forEach(item => {
+    if (!selectedFiles.value.some(f => String(f.id) === String(item.id))) {
+      selectedFiles.value.push({
+        id: item.id,
+        name: item.originalName,
+        type: item.type,
+        duration: item.type === 1 ? 10 : item.duration,
+        order: 0
+      });
+    }
+  });
+  // 重新排序
+  selectedFiles.value = selectedFiles.value.map((f, idx) => ({ ...f, order: idx + 1 }));
+};
 
-  // Get max order number from preserved selections
-  const maxOrder = preservedSelections.length > 0 
-    ? Math.max(...preservedSelections.map(f => f.order))
-    : 0;
-
-  // Create new selections with proper ordering
-  const newSelections = selection
-    .filter(item => !existingSelections.some(f => f.id === item.id))
-    .map((item, index) => ({
-      id: item.id,
-      name: item.originalName,
-      type: item.type,
-      duration: item.type === 1 ? 10 : item.duration,
-      order: maxOrder + index + 1
-    }));
+// 取消单个选中
+const handleSelect = (selection: MinioDataVO[], row: MinioDataVO) => {
+  if (!selection.some(item => String(item.id) === String(row.id))) {
+    selectedFiles.value = selectedFiles.value.filter(f => String(f.id) !== String(row.id));
+    selectedFiles.value = selectedFiles.value.map((f, idx) => ({ ...f, order: idx + 1 }));
+  }
+};
 
-  // Combine and sort all selections by order number
-  selectedFiles.value = [
-    ...preservedSelections,
-    ...existingSelections,
-    ...newSelections
-  ].sort((a, b) => a.order - b.order);
+// 取消全选
+const handleSelectAll = (selection: MinioDataVO[]) => {
+  const currentPageIds = new Set(minioDataList.value.map(item => String(item.id)));
+  const selectedIds = new Set(selection.map(item => String(item.id)));
+  selectedFiles.value = selectedFiles.value.filter(f => !currentPageIds.has(String(f.id)) || selectedIds.has(String(f.id)));
+  selectedFiles.value = selectedFiles.value.map((f, idx) => ({ ...f, order: idx + 1 }));
 };
 
-/** 取消按钮 */
 const cancel = () => {
   reset();
   dialog.visible = false;