From 51b9df7d9e907506ce565fd47a7aa4661a4139ea Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期四, 13 十一月 2025 23:03:12 +0800
Subject: [PATCH] feat:优化增加自动匹配识别

---
 app/components/AttachmentUpload.vue |  108 ++++++++---------------------------------------------
 1 files changed, 17 insertions(+), 91 deletions(-)

diff --git a/app/components/AttachmentUpload.vue b/app/components/AttachmentUpload.vue
index 58714cd..2f319d3 100644
--- a/app/components/AttachmentUpload.vue
+++ b/app/components/AttachmentUpload.vue
@@ -3,7 +3,7 @@
     <view class="detail-section">
       <view class="section-title">
         {{ title }}
-        <button class="upload-btn" @click="showUploadDialog">涓婁紶闄勪欢</button>
+        <button class="upload-btn" @click="showUploadDialog" v-if="!readonly">涓婁紶闄勪欢</button>
       </view>
       <view v-if="attachmentList && attachmentList.length > 0">
         <view class="attachment-item" v-for="(item, index) in attachmentList" :key="item.attachmentId">
@@ -20,7 +20,7 @@
           </view>
           <view class="attachment-actions">
             <button class="action-btn view-btn" @click="viewAttachment(item)">鏌ョ湅</button>
-            <button class="action-btn delete-btn" @click="deleteAttachment(item.attachmentId, index)">鍒犻櫎</button>
+            <button class="action-btn delete-btn" @click="deleteAttachment(item.attachmentId, index)" v-if="!readonly">鍒犻櫎</button>
           </view>
         </view>
       </view>
@@ -67,8 +67,10 @@
 </template>
 
 <script>
-  import { getAttachmentList, uploadAttachmentFromWechat, deleteAttachment, getWechatAccessToken } from '@/api/task'
+  import { getAttachmentList, deleteAttachment } from '@/api/task'
   import { formatDateTime } from '@/utils/common'
+  import { getToken } from '@/utils/auth'
+  import config from '@/config'
   
   export default {
     name: 'AttachmentUpload',
@@ -87,6 +89,11 @@
       autoLoad: {
         type: Boolean,
         default: true
+      },
+      // 鏄惁鍙妯″紡锛堢姝笂浼犲拰鍒犻櫎锛�
+      readonly: {
+        type: Boolean,
+        default: false
       }
     },
     data() {
@@ -101,16 +108,10 @@
           { label: '绯诲畨鍏ㄥ甫', value: '6' }
         ],
         selectedCategoryIndex: 0,
-        tempImagePath: null,
-        isWechatMiniProgram: false
+        tempImagePath: null
       }
     },
     mounted() {
-      // 妫�娴嬫槸鍚︽槸寰俊灏忕▼搴忕幆澧�
-      // #ifdef MP-WEIXIN
-      this.isWechatMiniProgram = true
-      // #endif
-      
       // 鑷姩鍔犺浇闄勪欢鍒楄〃
       if (this.autoLoad && this.taskId) {
         this.loadAttachmentList()
@@ -184,95 +185,20 @@
         const that = this
         const category = this.categoryList[this.selectedCategoryIndex].value
         
-        // 寰俊灏忕▼搴忕幆澧冿細鍏堣幏鍙朅ccessToken锛屽啀涓婁紶鍒板井淇℃湇鍔″櫒锛屾渶鍚庢彁浜ediaId鍒板悗绔�
-        // #ifdef MP-WEIXIN
-        if (this.isWechatMiniProgram) {
-          uni.showLoading({
-            title: '涓婁紶涓�...'
-          })
-          
-          // 绗竴姝ワ細浠庡悗绔幏鍙朅ccessToken
-          getWechatAccessToken().then(tokenResponse => {
-            // 鎺ュ彛杩斿洖鏍煎紡锛歿"msg":"token鍊�","code":200}
-            console.log('鑾峰彇AccessToken鎴愬姛:', tokenResponse)
-            const accessToken = tokenResponse.msg || tokenResponse.data || tokenResponse
-            if (!accessToken) {
-              uni.hideLoading()
-              that.$modal.showToast('鑾峰彇AccessToken澶辫触')
-              console.error('鑾峰彇AccessToken澶辫触锛屽搷搴旀暟鎹�:', tokenResponse)
-              return
-            }
-            
-            console.log('鑾峰彇鍒癆ccessToken:', accessToken)
-            
-            // 绗簩姝ワ細涓婁紶鍒板井淇℃湇鍔″櫒
-            const uploadUrl = `https://api.weixin.qq.com/cgi-bin/media/upload?access_token=${accessToken}&type=image`
-            
-            uni.uploadFile({
-              url: uploadUrl,
-              filePath: that.tempImagePath,
-              name: 'media',
-              success: function(res) {
-                console.log('寰俊涓婁紶鍝嶅簲:', res)
-                try {
-                  const data = JSON.parse(res.data)
-                  if (data.media_id) {
-                    // 绗笁姝ワ細鎻愪氦mediaId鍒板悗绔�
-                    uploadAttachmentFromWechat(that.taskId, data.media_id, category).then(response => {
-                      uni.hideLoading()
-                      that.$modal.showToast('涓婁紶鎴愬姛')
-                      that.closeUploadDialog()
-                      that.loadAttachmentList()
-                      that.$emit('uploaded', response)
-                    }).catch(error => {
-                      uni.hideLoading()
-                      console.error('鎻愪氦mediaId澶辫触:', error)
-                      that.$modal.showToast('涓婁紶澶辫触锛�' + (error.msg || '璇烽噸璇�'))
-                      that.$emit('error', error)
-                    })
-                  } else {
-                    uni.hideLoading()
-                    const errMsg = data.errmsg || '鏈煡閿欒'
-                    console.error('寰俊杩斿洖閿欒:', data)
-                    that.$modal.showToast('寰俊涓婁紶澶辫触锛�' + errMsg)
-                  }
-                } catch (e) {
-                  uni.hideLoading()
-                  console.error('瑙f瀽寰俊鍝嶅簲澶辫触:', e, res.data)
-                  that.$modal.showToast('涓婁紶澶辫触锛氬搷搴旇В鏋愰敊璇�')
-                }
-              },
-              fail: function(err) {
-                uni.hideLoading()
-                console.error('涓婁紶鍒板井淇″け璐�:', err)
-                that.$modal.showToast('涓婁紶澶辫触锛�' + (err.errMsg || '璇锋鏌ョ綉缁�'))
-                that.$emit('error', err)
-              }
-            })
-          }).catch(error => {
-            uni.hideLoading()
-            console.error('鑾峰彇AccessToken澶辫触:', error)
-            that.$modal.showToast('鑾峰彇AccessToken澶辫触')
-            that.$emit('error', error)
-          })
-          return
-        }
-        // #endif
-        
-        // 闈炲井淇″皬绋嬪簭鐜锛氱洿鎺ヤ笂浼犲埌鍚庣鏈嶅姟鍣�
+        // 缁熶竴鐩存帴涓婁紶鍒板悗绔湇鍔″櫒
         uni.showLoading({
           title: '涓婁紶涓�...'
         })
         
         uni.uploadFile({
-          url: that.$baseUrl + '/task/attachment/upload/' + that.taskId,
+          url: config.baseUrl + '/task/attachment/upload/' + that.taskId,
           filePath: that.tempImagePath,
           name: 'file',
           formData: {
             'category': category
           },
           header: {
-            'Authorization': 'Bearer ' + uni.getStorageSync('token')
+            'Authorization': 'Bearer ' + getToken()
           },
           success: function(uploadRes) {
             uni.hideLoading()
@@ -296,7 +222,7 @@
           fail: function(err) {
             uni.hideLoading()
             console.error('涓婁紶澶辫触:', err)
-            that.$modal.showToast('涓婁紶澶辫触')
+            that.$modal.showToast('涓婁紶澶辫触锛�' + (err.errMsg || '璇锋鏌ョ綉缁�'))
             that.$emit('error', err)
           }
         })
@@ -313,7 +239,7 @@
           let imageUrl = item.fileUrl
           // 濡傛灉娌℃湁fileUrl锛屽垯浣跨敤涓嬭浇鎺ュ彛
           if (!imageUrl) {
-            imageUrl = this.$baseUrl + '/task/attachment/download/' + item.attachmentId
+            imageUrl = config.baseUrl + '/task/attachment/download/' + item.attachmentId
           }
           
           // 寰俊灏忕▼搴忎腑棰勮鍥剧墖
@@ -400,7 +326,7 @@
         }
         // 浣跨敤涓嬭浇鎺ュ彛
         if (item.attachmentId) {
-          return this.$baseUrl + '/task/attachment/download/' + item.attachmentId
+          return config.baseUrl + '/task/attachment/download/' + item.attachmentId
         }
         // 榛樿鍗犱綅鍥�
         return '/static/images/default-image.png'

--
Gitblit v1.9.1