From d3fd4b0ab851bab89c30c199e27245f7f45f1c0e Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期六, 08 十一月 2025 08:01:12 +0800
Subject: [PATCH] feat:实现了微信上传图片

---
 app/pages/index.vue |   82 +++++++++++++++++++++++++++++-----------
 1 files changed, 59 insertions(+), 23 deletions(-)

diff --git a/app/pages/index.vue b/app/pages/index.vue
index 16b1513..72efa8a 100644
--- a/app/pages/index.vue
+++ b/app/pages/index.vue
@@ -55,7 +55,7 @@
             <!-- 浠诲姟澶撮儴锛氭爣棰樺拰鐘舵�佹爣绛� -->
             <view class="task-header">
               <view class="task-title">{{ getTaskTypeText(task.type) }} - {{ task.vehicle }}</view>
-              <view class="task-status" :class="getStatusClass(task.taskStatus)">
+              <view class="task-status" :class="task.taskStatus === 'PENDING' ? 'status-pending' : task.taskStatus === 'DEPARTING' ? 'status-departing' : task.taskStatus === 'ARRIVED' ? 'status-arrived' : task.taskStatus === 'RETURNING' ? 'status-returning' : task.taskStatus === 'COMPLETED' ? 'status-completed' : task.taskStatus === 'CANCELLED' ? 'status-cancelled' : task.taskStatus === 'IN_PROGRESS' ? 'status-in-progress' : 'status-default'">
                 {{ getStatusText(task.status) }}
               </view>
             </view>
@@ -162,6 +162,8 @@
   import { getMyTasks, changeTaskStatus } from '@/api/task'
   import { getUserProfile } from '@/api/system/user'
   import { getUserBoundVehicle } from '@/api/vehicle'
+  import { getUnreadCount } from '@/api/message'
+  import { formatDateTime } from '@/utils/common'
   
   export default {
     data() {
@@ -172,6 +174,7 @@
         
         // 娑堟伅鏁版嵁
         messages: [],
+        unreadMessageCount: 0,
         
         // 姝e湪杩愯鐨勪换鍔″垪琛�
         taskList: [],
@@ -190,23 +193,35 @@
           // 鍖呭惈寰呭鐞嗐�佸嚭鍙戜腑銆佸凡鍒拌揪銆佽繑绋嬩腑绛夋墍鏈夋湭瀹屾垚鐨勭姸鎬�
           return ['PENDING', 'DEPARTING', 'ARRIVED', 'RETURNING', 'IN_PROGRESS'].includes(task.taskStatus)
         });
-      },
-      
-      // 鏈娑堟伅鏁伴噺
-      unreadMessageCount() {
-        return this.messages.filter(message => !message.read).length;
       }
     },
     onLoad() {
+      // 妫�鏌ョ敤鎴锋槸鍚﹀凡鐧诲綍
+      const userId = this.currentUser.userId
+      if (!userId) {
+        console.log('鐢ㄦ埛鏈櫥褰曪紝璺宠繃鍔犺浇鏁版嵁')
+        return
+      }
+      
       // 鍔犺浇鐢ㄦ埛缁戝畾杞﹁締淇℃伅
       this.loadUserVehicle()
       // 鍔犺浇姝e湪杩愯鐨勪换鍔�
       this.loadRunningTasks()
+      // 鍔犺浇鏈娑堟伅鏁伴噺
+      this.loadUnreadMessageCount()
     },
     onShow() {
-      // 姣忔鏄剧ず椤甸潰鏃跺埛鏂颁换鍔″垪琛ㄥ拰缁戝畾杞﹁締
+      // 妫�鏌ョ敤鎴锋槸鍚﹀凡鐧诲綍
+      const userId = this.currentUser.userId
+      if (!userId) {
+        console.log('鐢ㄦ埛鏈櫥褰曪紝璺宠繃鍔犺浇鏁版嵁')
+        return
+      }
+      
+      // 姣忔鏄剧ず椤甸潰鏃跺埛鏂颁换鍔″垪琛ㄣ�佺粦瀹氳溅杈嗗拰娑堟伅鏁伴噺
       this.loadUserVehicle()
       this.loadRunningTasks()
+      this.loadUnreadMessageCount()
     },
     onPullDownRefresh() {
       // 涓嬫媺鍒锋柊
@@ -241,6 +256,40 @@
           this.boundVehicle = ''
           this.boundVehicleId = null
         })
+      },
+      
+      // 鍔犺浇鏈娑堟伅鏁伴噺
+      loadUnreadMessageCount() {
+        // 妫�鏌ョ敤鎴锋槸鍚﹀凡鐧诲綍
+        const userId = this.currentUser.userId
+        if (!userId) {
+          console.log('鐢ㄦ埛鏈櫥褰曪紝璺宠繃鑾峰彇鏈娑堟伅鏁伴噺')
+          return
+        }
+        
+        getUnreadCount().then(response => {
+          if (response.code === 200) {
+            this.unreadMessageCount = response.data || 0
+            // 鏇存柊TabBar寰芥爣
+            this.updateTabBarBadge(this.unreadMessageCount)
+          }
+        }).catch(error => {
+          console.error('鑾峰彇鏈娑堟伅鏁伴噺澶辫触:', error)
+        })
+      },
+      
+      // 鏇存柊TabBar寰芥爣
+      updateTabBarBadge(count) {
+        if (count > 0) {
+          uni.setTabBarBadge({
+            index: 3, // 娑堟伅椤甸潰鍦╰abBar涓殑绱㈠紩
+            text: count > 99 ? '99+' : count.toString()
+          })
+        } else {
+          uni.removeTabBarBadge({
+            index: 3
+          })
+        }
       },
       
       // 鍔犺浇鐢ㄦ埛淇℃伅锛堜繚鐣欎互鍏煎涔嬪墠鐨勪唬鐮侊級
@@ -304,7 +353,7 @@
                 vehicleList: task.assignedVehicles || [],
                 startLocation: this.formatAddress(task.departureAddress || task.startLocation || '鏈缃�'),
                 endLocation: this.formatAddress(task.destinationAddress || task.endLocation || '鏈缃�'),
-                startTime: task.plannedStartTime ? this.formatDateTime(task.plannedStartTime) : '鏈缃�',
+                startTime: task.plannedStartTime ? formatDateTime(task.plannedStartTime, 'YYYY-MM-DD HH:mm') : '鏈缃�',
                 assignee: task.assigneeName || '鏈垎閰�',
                 taskNo: task.taskCode || '鏈煡缂栧彿',
                 status: this.convertStatus(task.taskStatus) // 杞崲鐘舵�佹牸寮忎互鍏煎鏃I
@@ -313,19 +362,6 @@
         }).catch(error => {
           this.loading = false
           console.error('鍔犺浇浠诲姟鍒楄〃澶辫触:', error)
-        })
-      },
-      
-      // 鏍煎紡鍖栨棩鏈熸椂闂�
-      formatDateTime(dateTime) {
-        if (!dateTime) return ''
-        const date = new Date(dateTime)
-        return date.toLocaleString('zh-CN', {
-          year: 'numeric',
-          month: '2-digit',
-          day: '2-digit',
-          hour: '2-digit',
-          minute: '2-digit'
         })
       },
       
@@ -517,13 +553,13 @@
           'MAINTENANCE': '缁翠慨淇濆吇',
           'FUEL': '鍔犳补',
           'OTHER': '鍏朵粬',
-          'EMERGENCY_TRANSFER': '鎬ユ晳杞繍',
+          'EMERGENCY_TRANSFER': '杞繍浠诲姟',
           'WELFARE': '绂忕杞�',
           // 鏃ф牸寮忥紙UI绫诲瀷锛�
           'maintenance': '缁翠慨淇濆吇',
           'refuel': '鍔犳补',
           'inspection': '宸℃',
-          'emergency': '鎬ユ晳杞繍',
+          'emergency': '杞繍浠诲姟',
           'welfare': '绂忕杞�'
         }
         return typeMap[type] || '鏈煡绫诲瀷'

--
Gitblit v1.9.1