Prechádzať zdrojové kódy

Merge branch 'master' into test-dev

duy 2 mesiacov pred
rodič
commit
9c024101cb

+ 11 - 0
src/api/modules/data-fill/wbs.js

@@ -532,4 +532,15 @@ export default {
             data: form,
         })
     },
+    //上传文件后排序接口
+    async addFileSort(form) {
+        return HcApi(
+            {
+                url: '/api/blade-manager/exceltab/add-bussfile-node-sort',
+                   method: 'post',
+                data: form,
+            },
+            false,
+        )
+    },
 }

+ 101 - 51
src/views/data-fill/components/HcUpload.vue

@@ -1,4 +1,7 @@
 <template>
+    <div class="mb-1 p-2">
+        <span class="text-orange">按住鼠标拖动文件可进行附件列表排序</span>
+    </div>
     <el-upload
         ref="uploadRef"
         :accept="accept" :action="action" :before-remove="delUploadData" :before-upload="beforeUpload"
@@ -188,6 +191,7 @@ const q = 1 // 假设q是固定偏移量,可以根据需要调整
 // 新增的处理方法
 // 文件变化处理
 const handleFileChange = (file, fileList) => {
+console.log(file, 'file')
 
     
   fileListData.value = fileList.map((item, index) => ({
@@ -206,10 +210,9 @@ const onDragEnd = () => {
 }
 // 手动删除文件
 const handleRemove = (file) => {
-  const index = fileListData.value.findIndex(f => f.uid === file.uid)
-  if (index !== -1) {
-    fileListData.value.splice(index, 1)
-  }
+  console.log('手动删除文件', file)
+  
+      delUploadData(file)
 }
 //上传中
 const loadingText = ref('上传中...')
@@ -249,53 +252,41 @@ const uploadPreview = ({ url }) => {
     }*/
 }
 const uploadRef = ref(null)
-//删除文件
-const delUploadData = async (res) => {
-    const { id, status } = res
-    console.log(res, 'res')
+
+// 删除文件
+const delUploadData = async (file) => {
+    const { id, status } = file
+    console.log(file, 'file')
     
-    if (accept.value === 'application/pdf') {
-        if (!id || status === 'uploading') {
-            uploadRef.value.abort()
-            uploadDisabled.value = false
-            return true
-         } else {
-            loadingText.value = '删除中...'
-            uploadDisabled.value = true
-            const { error, code, msg } = await wbsApi.delTabById({
-                ids: id,
-            })
-            uploadDisabled.value = false
-            if (!error && code === 200) {
-                window?.$message?.success('删除成功')
-                return true
-            } else {
-                window?.$message?.error(msg || '操作失败')
-                return false
-            }
+    if (!id || status === 'uploading') {
+        // 如果id不存在或文件正在上传,直接删除文件
+        const index = fileListData.value.findIndex(f => f.uid === file.uid)
+        if (index !== -1) {
+            fileListData.value.splice(index, 1)
         }
-
+        uploadRef.value.abort()
+        uploadDisabled.value = false
+        return true
     } else {
-        if (!id || status === 'uploading') {
-            uploadRef.value.abort()
-            uploadDisabled.value = false
+        // 如果id存在且文件不在上传状态,调用接口删除文件
+        loadingText.value = '删除中...'
+        uploadDisabled.value = true
+        const { error, code, msg } = await (accept.value === 'application/pdf'
+            ? wbsApi.delTabById({ ids: id })
+            : wbsApi.removeBussFile({ ids: id }))
+        uploadDisabled.value = false
+        if (!error && code === 200) {
+            window?.$message?.success('删除成功')
+            // 从fileListData中移除已删除的文件
+            const index = fileListData.value.findIndex(f => f.uid === file.uid)
+            if (index !== -1) {
+                fileListData.value.splice(index, 1)
+            }
             return true
         } else {
-            loadingText.value = '删除中...'
-            uploadDisabled.value = true
-            const { error, code, msg } = await wbsApi.removeBussFile({
-                ids: id,
-            })
-            uploadDisabled.value = false
-            if (!error && code === 200) {
-                window?.$message?.success('删除成功')
-                return true
-            } else {
-                window?.$message?.error(msg || '操作失败')
-                return false
-            }
+            window?.$message?.error(msg || '操作失败')
+            return false
         }
-
     }
 }
 
@@ -340,23 +331,30 @@ const submitUpload = async () => {
   fileListData.value.forEach((file) => {
 
     
-    formData.append('files', file.raw || file) // 确保 file.raw 是 File 对象
+  if (file.raw !== undefined) {
+      formData.append('files', file.raw) // 确保 file.raw 是 File 对象
+    }
   })
 
-  // 2. 添加其他参数
-  formData.append('classify', uploadData.value.classify)
-  formData.append('nodeId', uploadData.value.nodeId)
-  formData.append('type', uploadData.value.type)
-  formData.append('contractId', uploadData.value.contractId)
+console.log( fileListData.value, ' fileListData.value')
+
 
   // 3. 发送请求
  subLoading.value = true
    if (isListFile.value) {
+          // 2. 添加其他参数
+  formData.append('classify', uploadData.value.classify)
+  formData.append('pkeyId', uploadData.value.pkeyId)
+    formData.append('nodeId', uploadData.value.nodeId)
+    formData.append('type', 2)
+  formData.append('contractId', uploadData.value.contractId)
+    formData.append('projectId', uploadData.value.projectId)
     const { error, code, msg } = await wbsApi.addBussFile(formData) // 修改这里
         uploadDisabled.value = false
      subLoading.value = false
     if (!error && code === 200) {
       window?.$message?.success('上传成功') 
+     await sortFile()
       emit('change', { type: 'success' })
 
     } else {
@@ -364,11 +362,17 @@ const submitUpload = async () => {
 
     }
   } else {
+      // 2. 添加其他参数
+  formData.append('classify', uploadData.value.classify)
+  formData.append('nodeId', uploadData.value.nodeId)
+  formData.append('type', uploadData.value.type)
+  formData.append('contractId', uploadData.value.contractId)
     const { error, code, msg } = await wbsApi.addBussFileNode(formData) // 修改这里
         uploadDisabled.value = false
         subLoading.value = false
     if (!error && code === 200) {
       window?.$message?.success('上传成功') 
+     await sortFile()
       emit('change', { type: 'success' })
 
     } else {
@@ -380,6 +384,52 @@ const submitUpload = async () => {
  
 
  
+}
+//上传文件后排序
+const sortFile = async ()=>{
+  if (fileListData.value.length <= 0) {
+    window.$message.warning('请先上传文件')
+    return
+  }
+  let list = []
+  fileListData.value.forEach((file) => {
+    list.push(
+      file.name,
+  
+    )
+  })
+  let obj1 = {
+    list:list,
+   
+    nodeId:uploadData.value.nodeId,
+    contractId:uploadData.value.contractId,
+    classify:uploadData.value.classify,
+    type:uploadData.value.type,
+   
+ 
+
+  }
+    let obj2 = {
+    list:list,
+    pkeyId:uploadData.value.pkeyId,
+    nodeId:uploadData.value.nodeId,
+    contractId:uploadData.value.contractId,
+    classify:uploadData.value.classify,
+    projectId:uploadData.value.projectId,
+     type:2,
+
+  }
+          const { error, code, msg } = await (isListFile.value
+            ? wbsApi.addFileSort(obj1)
+            : wbsApi.addFileSort(obj2))
+        uploadDisabled.value = false
+        if (!error && code === 200) {
+            window?.$message?.success('排序成功')
+           
+        } else {
+            window?.$message?.error(msg || '操作失败')
+            
+        }
 }
 </script>
 

+ 2 - 1
src/views/data-fill/wbs.vue

@@ -216,6 +216,7 @@
                         <el-button
                             hc-btn
                             color="#A16222"
+                            :disabled="isCanadd"
                             @click="attachmentModalShow"
                         >
                             查看附件
@@ -1299,7 +1300,7 @@
             </div>
             <template #footer>
                 <el-button @click="attachmentModal = false">关闭</el-button>
-                <el-button type="primary" :loading="saveFileOrderLoad" @click="saveFileOrder">确定排序</el-button>
+                <el-button type="primary" :loading="saveFileOrderLoad" :disabled="attachmentList.length === 0" @click="saveFileOrder">确定排序</el-button>
             </template>
         </hc-new-dialog>
         <!-- 上传文件 -->