duy пре 2 месеци
родитељ
комит
8e067a574c
1 измењених фајлова са 45 додато и 50 уклоњено
  1. 45 50
      src/views/data-fill/components/HcUpload.vue

+ 45 - 50
src/views/data-fill/components/HcUpload.vue

@@ -206,10 +206,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 +248,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
         }
-
     }
 }
 
@@ -343,15 +330,18 @@ const submitUpload = async () => {
     formData.append('files', file.raw || file) // 确保 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)
+
 
   // 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('contractId', uploadData.value.contractId)
+    formData.append('projectId', uploadData.value.projectId)
     const { error, code, msg } = await wbsApi.addBussFile(formData) // 修改这里
         uploadDisabled.value = false
      subLoading.value = false
@@ -364,6 +354,11 @@ 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