From 353446ec9194962845f5824c1ddcf0aebdaf2662 Mon Sep 17 00:00:00 2001
From: 周宾 <2802492122@qq.com>
Date: 星期二, 16 十二月 2025 14:33:16 +0800
Subject: [PATCH] 海川开心-修复图片上传问题

---
 src/pages/inspectionUpload/index.vue |   78 ++++++++++++++++++++++++++++++++------
 1 files changed, 65 insertions(+), 13 deletions(-)

diff --git a/src/pages/inspectionUpload/index.vue b/src/pages/inspectionUpload/index.vue
index a31902d..caf3783 100644
--- a/src/pages/inspectionUpload/index.vue
+++ b/src/pages/inspectionUpload/index.vue
@@ -174,7 +174,7 @@
                 <view class="upload-buttons">
                   <u-button 
                     type="primary" 
-                    @click="chooseImage"
+                    @click="chooseMedia('image')"
                     :loading="uploading"
                     :disabled="getCurrentFiles().length >= uploadConfig.limit"
                     :customStyle="{ marginRight: '10px', flex: 1 }"
@@ -184,12 +184,12 @@
                   </u-button>
                   <u-button 
                     type="success" 
-                    @click="chooseVideo"
+                    @click="chooseMedia('video')"
                     :loading="uploading"
                     :disabled="getCurrentFiles().length >= uploadConfig.limit"
                     :customStyle="{ flex: 1 }"
                   >
-                    <u-icon name="video" size="18" color="#fff" style="margin-right: 5px;"></u-icon>
+                    <uni-icons type="videocam" name="videocam" size="18" color="#fff" style="margin-right: 5px;"></uni-icons>
                     {{ uploading ? '涓婁紶涓�...' : '鎷嶈棰�' }}
                   </u-button>
                 </view>
@@ -212,13 +212,13 @@
                   >
                     <view class="file-preview-container">
                       <image 
-                        v-if="file.type === 'image'"
-                        :src="file.url || file.tempFilePath || file.path" 
+                        v-if="file?.path?.fileType === 'image'"
+                        :src="file?.url || file?.tempFilePath?.tempFilePath || file?.path?.tempFilePath" 
                         class="file-preview"
                         mode="aspectFill"
                       />
                       <view v-else class="video-preview">
-                        <u-icon name="video" size="24" color="#409eff"></u-icon>
+                        <uni-icons type="videocam" name="videocam" size="18" color="#fff" style="margin-right: 5px;"></uni-icons>
                         <text class="video-text">瑙嗛</text>
                       </view>
                       
@@ -439,9 +439,9 @@
   if (process.env.VUE_APP_BASE_API) {
     baseUrl = process.env.VUE_APP_BASE_API;
   } else if (process.env.NODE_ENV === 'development') {
-    baseUrl = 'http://192.168.1.147:9036';
+    baseUrl = 'http://114.132.189.42:9068';
   } else {
-    baseUrl = 'http://192.168.1.147:9036';
+    baseUrl = 'http://114.132.189.42:9068';
   }
   
   return baseUrl + uploadConfig.action;
@@ -702,8 +702,10 @@
 
 // 鑾峰彇褰撳墠鍒嗙被鐨勬枃浠跺垪琛�
 const getCurrentFiles = () => {
+	console.log('currentUploadType',currentUploadType.value)
   switch (currentUploadType.value) {
     case 'before':
+	console.log('beforeModelValue',beforeModelValue.value)
       return beforeModelValue.value
     case 'after':
       return afterModelValue.value
@@ -1007,6 +1009,54 @@
   })
 }
 
+// 浣跨敤鐩告満
+const chooseMedia = (type) => {
+	let mediaPamaes={
+		count: 1,
+		mediaType:[type||'image'],
+		sizeType: ['compressed', 'original'],
+		sourceType: ['camera'],
+	}
+	uni.chooseMedia({
+	  ...mediaPamaes,
+	  success: (res) => {
+	    try {
+	      if (!res.tempFiles || res.tempFiles.length === 0) {
+	        throw new Error('鏈幏鍙栧埌鍥剧墖鏂囦欢');
+	      }
+	      
+	      const tempFilePath = res.tempFiles[0];
+	      const tempFile = res.tempFiles && res.tempFiles[0] ? res.tempFiles[0] : {};
+	      
+	      const file = {
+	        tempFilePath: tempFilePath,
+	        path: tempFilePath, // 淇濇寔鍏煎鎬�
+	        type: 'image',
+	        name: `photo_${Date.now()}.jpg`,
+	        size: tempFile.size || 0,
+	        createTime: new Date().getTime(),
+	        uid: Date.now() + Math.random()
+	      };
+	      
+	      handleBeforeUpload(file);
+	    } catch (error) {
+	      console.error('澶勭悊鎷嶇収缁撴灉澶辫触:', error);
+	      uni.showToast({
+	        title: '澶勭悊鍥剧墖澶辫触',
+	        icon: 'error'
+	      });
+	    }
+	  },
+	  fail: (err) => {
+	    console.error('鎷嶇収澶辫触:', err);
+	    uni.showToast({
+	      title: '鎷嶇収澶辫触: ' + (err.errMsg || '鏈煡閿欒'),
+	      icon: 'error'
+	    });
+	  }
+	})
+}
+
 // 鎷嶇収
 const chooseImage = () => {
   if (uploadFiles.value.length >= uploadConfig.limit) {
@@ -1017,17 +1067,18 @@
     return;
   }
   
-  uni.chooseImage({
+  uni.chooseMedia({
     count: 1,
+	mediaType:['image', 'video'],
     sizeType: ['compressed', 'original'],
     sourceType: ['camera'],
     success: (res) => {
       try {
-        if (!res.tempFilePaths || res.tempFilePaths.length === 0) {
+        if (!res.tempFiles || res.tempFiles.length === 0) {
           throw new Error('鏈幏鍙栧埌鍥剧墖鏂囦欢');
         }
         
-        const tempFilePath = res.tempFilePaths[0];
+        const tempFilePath = res.tempFiles[0];
         const tempFile = res.tempFiles && res.tempFiles[0] ? res.tempFiles[0] : {};
         
         const file = {
@@ -1229,7 +1280,7 @@
   number.value++; // 澧炲姞涓婁紶璁℃暟
   
   // 纭繚鏂囦欢璺緞姝g‘
-  const filePath = file.tempFilePath || file.path;
+  const filePath = file.tempFilePath?.tempFilePath || file.path?.tempFilePath||'';
   if (!filePath) {
     handleUploadError('鏂囦欢璺緞涓嶅瓨鍦�');
     return;
@@ -1254,7 +1305,7 @@
       'Authorization': `Bearer ${token}`
     }
   };
-  
+  console.log('uploadParams',uploadParams)
   const uploadTask = uni.uploadFile({
     ...uploadParams,
     success: (res) => {
@@ -1334,6 +1385,7 @@
 
 // 涓婁紶鎴愬姛鍥炶皟
 const handleUploadSuccess = (res, file) => {
+	console.log(res,file)
   if (res.code === 200 && res.data && Array.isArray(res.data) && res.data.length > 0) {
     const uploadedFile = res.data[0];
     

--
Gitblit v1.9.3