From ad9726ecf2e02f4666cd1d554d6a4748a963c183 Mon Sep 17 00:00:00 2001
From: zhangwencui <1064582902@qq.com>
Date: 星期一, 18 五月 2026 13:54:39 +0800
Subject: [PATCH] 设备巡检上传接口报错问题,以及设备保养上传问题,上传组件更新

---
 src/pages/equipmentManagement/upkeep/fileList.vue |  133 ++++++++++++++++++++++++-------------------
 1 files changed, 74 insertions(+), 59 deletions(-)

diff --git a/src/pages/equipmentManagement/upkeep/fileList.vue b/src/pages/equipmentManagement/upkeep/fileList.vue
index b4d4b7f..1680fcb 100644
--- a/src/pages/equipmentManagement/upkeep/fileList.vue
+++ b/src/pages/equipmentManagement/upkeep/fileList.vue
@@ -8,7 +8,7 @@
       <view v-if="fileList.length > 0"
             class="file-list">
         <view v-for="(file, index) in fileList"
-              :key="file.id || index"
+              :key="file.storageAttachmentId || file.id || index"
               class="file-item">
           <!-- 鏂囦欢鍥炬爣 -->
           <!-- <view class="file-icon"
@@ -19,7 +19,7 @@
           </view> -->
           <!-- 鏂囦欢淇℃伅 -->
           <view class="file-info">
-            <text class="file-name">{{ file.name }}</text>
+            <text class="file-name">{{ file.originalFilename || file.name }}</text>
             <!-- <text class="file-meta">{{ formatFileSize(file.fileSize) }} 路 {{ file.uploadTime || file.createTime }}</text> -->
           </view>
           <!-- 鎿嶄綔鎸夐挳 -->
@@ -65,15 +65,16 @@
 
 <script setup>
   import { ref, onMounted } from "vue";
+  import { onLoad } from "@dcloudio/uni-app";
   import PageHeader from "@/components/PageHeader.vue";
   import config from "@/config";
   import { getToken } from "@/utils/auth";
   // import { saveAs } from "file-saver";
   import {
-    listMaintenanceTaskFiles,
-    addMaintenanceTaskFile,
-    delMaintenanceTaskFile,
-  } from "@/api/equipmentManagement/upkeep";
+    attachmentList,
+    createAttachment,
+    deleteAttachment,
+  } from "@/api/basicData/storageAttachment";
   import { blobValidate } from "@/utils/ruoyi";
 
   // 闄勪欢鍒楄〃
@@ -214,21 +215,27 @@
               // const fileType = fileName.split(".").pop();
               // 3. 鏋勯�犱繚瀛樻枃浠朵俊鎭殑鍙傛暟
               const saveData = {
-                name: fileName,
-                deviceMaintenanceId: upkeepId.value,
-                url: res.data.tempPath || "",
+                application: "file",
+                recordType: recordType.value,
+                recordId: upkeepId.value,
+                storageBlobDTOs: [
+                  {
+                    name: fileName,
+                    url:
+                      res.data.url ||
+                      res.data.previewURL ||
+                      res.data.tempPath ||
+                      "",
+                    ...res.data,
+                  },
+                ],
               };
               console.log(saveData, "淇濆瓨鏂囦欢淇℃伅鍙傛暟");
-              // 4. 璋冪敤 addRuleFile 鎺ュ彛淇濆瓨鏂囦欢淇℃伅
-              addMaintenanceTaskFile(saveData)
+              // 4. 璋冪敤 createAttachment 鎺ュ彛淇濆瓨鏂囦欢淇℃伅
+              createAttachment(saveData)
                 .then(addRes => {
                   if (addRes.code === 200) {
-                    // 5. 娣诲姞鍒版枃浠跺垪琛�
-                    const newFile = {
-                      ...addRes.data,
-                      uploadTime: new Date().toLocaleString(),
-                    };
-                    // fileList.value.push(newFile);
+                    // 5. 鍒锋柊鍒楄〃
                     getFileList();
                     showToast("涓婁紶鎴愬姛");
                   } else {
@@ -257,20 +264,32 @@
   };
   // 涓嬭浇鏂囦欢
   const downloadFile = file => {
-    var url =
-      config.baseUrl +
-      "/common/download?fileName=" +
-      encodeURIComponent(file.url) +
-      "&delete=true";
-    console.log(url, "url");
+    let url = file.downloadURL || file.previewURL || file.url;
 
+    if (!url) {
+      showToast("鏂囦欢鍦板潃鏃犳晥");
+      return;
+    }
+
+    // 濡傛灉涓嶆槸瀹屾暣鐨刄RL锛屽垯鎷兼帴
+    if (!url.startsWith("http")) {
+      url =
+        config.baseUrl +
+        "/common/download?fileName=" +
+        encodeURIComponent(url) +
+        "&delete=true";
+    }
+
+    console.log(url, "涓嬭浇鍦板潃");
+
+    uni.showLoading({ title: "姝e湪涓嬭浇...", mask: true });
     uni
       .downloadFile({
         url: url,
-        responseType: "blob",
         header: { Authorization: "Bearer " + getToken() },
       })
       .then(res => {
+        uni.hideLoading();
         let osType = uni.getStorageSync("deviceInfo").osName;
         let filePath = res.tempFilePath;
         if (osType === "ios") {
@@ -280,7 +299,6 @@
             success: res => {},
             fail: err => {
               console.log("uni.openDocument--fail");
-              reject(err);
             },
           });
         } else {
@@ -290,10 +308,8 @@
               uni.showToast({
                 icon: "none",
                 mask: true,
-                title:
-                  "鏂囦欢宸蹭繚瀛橈細Android/data/uni.UNI720216F/apps/__UNI__720216F/" +
-                  fileRes.savedFilePath, //淇濆瓨璺緞
-                duration: 3000,
+                title: "鏂囦欢宸蹭笅杞藉苟灏濊瘯鎵撳紑",
+                duration: 2000,
               });
               setTimeout(() => {
                 //鎵撳紑鏂囨。鏌ョ湅
@@ -305,24 +321,12 @@
             },
             fail: err => {
               console.log("uni.save--fail");
-              reject(err);
             },
           });
         }
-        // const isBlob = blobValidate(res.data);
-        // if (isBlob) {
-        //   const blob = new Blob([res.data], { type: "text/plain" });
-        //   const url = URL.createObjectURL(blob);
-        //   const downloadLink = document.getElementById("downloadLink");
-        //   downloadLink.href = url;
-        //   downloadLink.download = file.name;
-        //   downloadLink.click();
-        //   showToast("涓嬭浇鎴愬姛");
-        // } else {
-        //   showToast("涓嬭浇澶辫触");
-        // }
       })
       .catch(err => {
+        uni.hideLoading();
         console.error("涓嬭浇澶辫触:", err);
         showToast("涓嬭浇澶辫触");
       });
@@ -335,7 +339,7 @@
       content: `纭畾瑕佸垹闄ら檮浠� "${file.name}" 鍚楋紵`,
       success: res => {
         if (res.confirm) {
-          deleteFile(file.id, index);
+          deleteFile(file.storageAttachmentId || file.id, index);
         }
       },
     });
@@ -348,7 +352,7 @@
       mask: true,
     });
 
-    delMaintenanceTaskFile([fileId])
+    deleteAttachment([fileId])
       .then(res => {
         uni.hideLoading();
         if (res.code === 200) {
@@ -372,37 +376,48 @@
       icon: "none",
     });
   };
-  const rulesRegulationsManagementId = ref("");
   const upkeepId = ref("");
+  const recordType = ref("");
+
+  // 椤甸潰鍔犺浇鏃惰幏鍙栧弬鏁�
+  onLoad(options => {
+    if (options.recordId) {
+      upkeepId.value = options.recordId;
+    } else {
+      upkeepId.value = uni.getStorageSync("upkeepId");
+    }
+
+    if (options.recordType) {
+      recordType.value = options.recordType;
+    } else {
+      recordType.value = "device_maintenance"; // 榛樿鍏煎
+    }
+
+    getFileList();
+  });
+
   // 椤甸潰鍔犺浇鏃�
   onMounted(() => {
-    // 浠� API 鑾峰彇闄勪欢鍒楄〃
-
-    // 浠庢湰鍦板瓨鍌ㄨ幏鍙� rulesRegulationsManagementId
-    rulesRegulationsManagementId.value = uni.getStorageSync(
-      "rulesRegulationsManagement"
-    );
-    upkeepId.value = uni.getStorageSync("upkeepId");
-    getFileList();
+    // getFileList(); // onLoad 涓凡缁忚皟鐢ㄤ簡
   });
 
   // 鑾峰彇闄勪欢鍒楄〃
   const getFileList = () => {
+    if (!upkeepId.value) return;
+
     uni.showLoading({
       title: "鍔犺浇涓�...",
       mask: true,
     });
 
-    listMaintenanceTaskFiles({
-      current: 1,
-      size: 100,
-      deviceMaintenanceId: upkeepId.value,
-      rulesRegulationsManagementId: upkeepId.value,
+    attachmentList({
+      recordType: recordType.value,
+      recordId: upkeepId.value,
     })
       .then(res => {
         uni.hideLoading();
         if (res.code === 200) {
-          fileList.value = res.data.records || [];
+          fileList.value = res.data || [];
         } else {
           showToast("鑾峰彇闄勪欢鍒楄〃澶辫触");
         }

--
Gitblit v1.9.3