duy 1 týždeň pred
rodič
commit
617e5c0c7b
1 zmenil súbory, kde vykonal 17 pridanie a 16 odobranie
  1. 17 16
      src/views/archives/manage/FileInsertModal.vue

+ 17 - 16
src/views/archives/manage/FileInsertModal.vue

@@ -192,13 +192,17 @@ const handleRowClick = ({ row }) => {
     window?.$message?.error('请选择插入位置')
     return
   }
+  
   // 记录当前点击行的ID
   currentRowId.value = row.id
   tableRef.value?.toggleRowSelection(row)
   
   // 如果有要插入的行数据,则执行插入操作
   if (insertRows.value && insertRows.value.length > 0) {
-    // 获取当前行ID对应的索引
+    // 1. 先移除表格中所有之前插入的数据(标记为inType=1的行)
+    tableData.value = tableData.value.filter(item => item.inType !== 1)
+    
+    // 2. 获取当前行ID对应的索引
     const index = getRowIndexById(row.id)
     
     if (index === -1) {
@@ -206,28 +210,23 @@ const handleRowClick = ({ row }) => {
       return
     }
     
-    // 深拷贝要插入的数据,避免引用问题
+    // 3. 深拷贝要插入的数据,避免引用问题
     const rowsToInsert = JSON.parse(JSON.stringify(insertRows.value))
     
-    // 生成新的ID(实际项目中可能由后端生成)
+    // 4. 生成新的ID(实际项目中可能由后端生成)
     const newRows = rowsToInsert.map(item => ({
       ...item,
-    
+      inType: 1, // 标记为插入的数据
     }))
     
-    // 根据选择的位置插入数据
+    // 5. 根据选择的位置插入数据
     if (insertModal.type === '1') {
       // 插入到当前行之前
       tableData.value.splice(index, 0, ...newRows)
-      //window?.$message?.success(`已在第${index + 1}行的文件前插入 ${newRows.length} 个文件`)
     } else {
       // 插入到当前行之后
       tableData.value.splice(index + 1, 0, ...newRows)
-      //window?.$message?.success(`已在ID为${index + 1}的文件后插入 ${newRows.length} 个文件`)
     }
-    
-    // 清空插入数据,避免重复插入
-    // insertRows.value = []
   }
 }
 
@@ -264,9 +263,11 @@ const nodeIds = ref('')
 const archiveId = ref('')
 const rowsToSave = ref([])
 const openInsertDialog = (rows, fromId, aId) => {
+  tableData.value = []
+     tableRef.value?.clearSelection()
   insertDialog.value = true
   insertRows.value = rows || [] // 接收要插入的行数据
-   rowsToSave.value = JSON.parse(JSON.stringify(insertRows.value))
+  rowsToSave.value = JSON.parse(JSON.stringify(insertRows.value))
   insertRows.value.forEach(row => {
     row.inType = 1 // 标记为插入的数据
   })
@@ -274,7 +275,6 @@ const openInsertDialog = (rows, fromId, aId) => {
   archiveId.value = aId
 
   getFileNumberOptions() // 加载文件编号选项
-
 }
 
 //设置某一行的样式
@@ -341,10 +341,10 @@ const insertDialogSave = async () => {
     return
   }
   
-  if (selectedFiles.value.length === 0) {
-    window?.$message?.warning('请选择文件')
-    return
-  }
+  // if (selectedFiles.value.length === 0) {
+  //   window?.$message?.warning('请选择文件')
+  //   return
+  // }
 
   
   // 准备提交的数据,保留inType信息
@@ -416,3 +416,4 @@ onMounted(() => {
 <style scoped>
 
 </style>
+