duy 2 сар өмнө
parent
commit
04a3e59c4b

+ 61 - 25
src/views/tentative/detect/test.vue

@@ -226,7 +226,7 @@
                     <div v-else class="pdf-file-list-box">
                         <hc-empty />
                     </div>
-                    <iframe v-if="attachmentPdfUrl" :src="attachmentPdfUrl" frameborder="1" height="100%" width="80%" />
+                    <!-- <iframe v-if="attachmentPdfUrl" :src="attachmentPdfUrl" frameborder="1" height="100%" width="80%" /> -->
                     <div class="hc-no-table-form">
                         <div class="table-form-no">
                             <HcDragUpload
@@ -915,20 +915,22 @@ const getAttachmentModalClick = async (id, type) => {
 
 }
 const refeshAttachmentModalClick = async (id, type) => {
-    const { error, code, data } = await dataApi.ancillaryDocumentsList({ id: id, type: type })
-    //处理数据
-    viewAttachmentLoading.value = false
-    if (!error && code === 200) {
-        viewAttachmentData.value = getArrValue(data)
-        if (viewAttachmentData.value.length < 1) {
-            //  window.$message?.warning('该条记录不存在附件')
+     try {
+        const { error, code, data } = await dataApi.ancillaryDocumentsList({ 
+            id: id, 
+            type: type, 
+        })
+        
+        if (!error && code === 200) {
+            viewAttachmentData.value = getArrValue(data)
+            if (viewAttachmentData.value.length > 0) {
+                await viewCurFile(viewAttachmentData.value[0])
+            }
         } else {
-            viewCurFile(viewAttachmentData.value[0])
+            viewAttachmentData.value = []
         }
-
-    } else {
-        viewAttachmentData.value = []
-
+    } catch (error) {
+        console.error('刷新附件列表失败:', error)
     }
 }
 const attachmentPdfUrl = ref('')
@@ -972,17 +974,28 @@ const splitFileName = (str) => {
 }
 //查看当前文件pdf
 const viewCurFile = (item) => {
-    console.log(item, 'item')
-    if (item) {
+     if (!item) return
+    
+    try {
+        viewAttachmentLoading.value = true
         curFileData.value = item
-        let arr = []
-        arr.push({ name: item.fileName, url: item.url })
-        fileListData.value = getArrValue(arr)
-        viewAttachmentData.value.forEach((ele) => {
+        
+        // 设置文件列表
+        fileListData.value = [{ name: item.fileName, url: item.url }]
+        
+        // 更新选中状态
+        viewAttachmentData.value.forEach(ele => {
             ele.isCheck = false
         })
         item.isCheck = true
 
+        // 设置预览地址
+        attachmentPdfUrl.value = item.url
+        
+        viewAttachmentLoading.value = false
+    } catch (error) {
+        viewAttachmentLoading.value = false
+        window.$message.error('文件加载失败')
     }
 
 }
@@ -994,16 +1007,39 @@ const uploadprogress = (res) => {
 
 //上传完成
 const uploadFinished = async (res) => {
-    const { error, code, data } = await dataApi.updateAncillaryDocument(
-        {
+    // const { error, code, data } = await dataApi.updateAncillaryDocument(
+    //     {
+    //         selfId: viewAttachmentId.value,
+    //         url: res.link,
+    //         type: tabTypeKey.value,
+
+    //     })
+    // console.log(data, 'data')
+    // if (!error && code === 200) {
+    //     refeshAttachmentModalClick(viewAttachmentId.value, tabTypeKey.value)
+    // }
+        try {
+        // 1. 显示上传中状态
+        viewAttachmentLoading.value = true
+        
+        // 2. 调用更新附件接口
+        const { error, code, data } = await dataApi.updateAncillaryDocument({
             selfId: viewAttachmentId.value,
             url: res.link,
             type: tabTypeKey.value,
-
         })
-    console.log(data, 'data')
-    if (!error && code === 200) {
-        refeshAttachmentModalClick(viewAttachmentId.value, tabTypeKey.value)
+
+        if (!error && code === 200) {
+            // 3. 延迟刷新文件列表,给服务器一些处理时间
+            setTimeout(async () => {
+                await refeshAttachmentModalClick(viewAttachmentId.value, tabTypeKey.value)
+                viewAttachmentLoading.value = false
+                window.$message.success('上传成功')
+            }, 1000)
+        }
+    } catch (error) {
+        viewAttachmentLoading.value = false
+        window.$message.error('上传失败')
     }
 }
 //上传文件delFileData