From 4f2925f1974844b66225ac70ae35065b8262b315 Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期四, 04 十二月 2025 13:26:11 +0800
Subject: [PATCH] feat:增加微信token缓存

---
 app/pagesTask/components/StaffSelector.vue |  113 ++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 93 insertions(+), 20 deletions(-)

diff --git a/app/pagesTask/components/StaffSelector.vue b/app/pagesTask/components/StaffSelector.vue
index 55c5391..9f750ed 100644
--- a/app/pagesTask/components/StaffSelector.vue
+++ b/app/pagesTask/components/StaffSelector.vue
@@ -109,7 +109,7 @@
 <script>
 import { mapState } from 'vuex'
 import uniPopup from '@/uni_modules/uni-popup/components/uni-popup/uni-popup.vue'
-import { listBranchUsers } from "@/api/system/user"
+import { listUsersByBranchDepts } from "@/api/system/user"
 
 export default {
   name: 'StaffSelector',
@@ -141,6 +141,16 @@
     currentUserRemovable: {
       type: Boolean,
       default: false
+    },
+    // 鍒嗗叕鍙窱D鍒楄〃锛堝閮ㄤ紶鍏ワ紝鐢ㄤ簬鎸囧畾鍔犺浇鍝簺鍒嗗叕鍙哥殑鐢ㄦ埛锛�
+    branchDeptIds: {
+      type: Array,
+      default: null
+    },
+    // 鍗曚釜鍒嗗叕鍙窱D锛堜粎浼犱竴涓椂鏇翠究鎹凤級
+    branchDeptId: {
+      type: [Number, String],
+      default: null
     }
   },
   data() {
@@ -149,7 +159,9 @@
       allStaffList: [],
       filteredStaffList: [],
       staffSearchKeyword: '',
-      staffFilterType: 'driver' // 榛樿閫変腑鍙告満
+      staffFilterType: 'driver', // 榛樿閫変腑鍙告満
+      staffListCache: {}, // 缂撳瓨: { key: { data: [], timestamp: 0 } }
+      cacheExpireTime: 5 * 60 * 1000 // 缂撳瓨杩囨湡鏃堕棿锛�5鍒嗛挓
     }
   },
   computed: {
@@ -174,6 +186,23 @@
       },
       immediate: true,
       deep: true
+    },
+    // 鐩戝惉鍒嗗叕鍙窱D鏁扮粍鍙樺寲锛岄噸鏂板姞杞界敤鎴峰垪琛�
+    branchDeptIds: {
+      handler(newVal, oldVal) {
+        if (JSON.stringify(newVal) !== JSON.stringify(oldVal)) {
+          console.log('鍒嗗叕鍙窱D鍙樺寲锛岄噸鏂板姞杞界敤鎴�:', newVal)
+          this.loadStaffList()
+        }
+      },
+      deep: true
+    },
+    // 鐩戝惉鍗曚釜鍒嗗叕鍙窱D鍙樺寲
+    branchDeptId(newVal, oldVal) {
+      if (newVal !== oldVal) {
+        console.log('鍒嗗叕鍙窱D鍙樺寲锛岄噸鏂板姞杞界敤鎴�:', newVal)
+        this.loadStaffList()
+      }
     }
   },
   mounted() {
@@ -207,30 +236,74 @@
     
     // 鍔犺浇浜哄憳鍒楄〃
     loadStaffList() {
-      listBranchUsers().then(response => {
+      // 鑾峰彇鎵�鏈夐儴闂↖D
+      let deptIds = []
+      if (this.branchDeptIds && this.branchDeptIds.length > 0) {
+        deptIds = this.branchDeptIds
+      } else if (this.branchDeptId) {
+        deptIds = [this.branchDeptId]
+      }
+          
+      if (deptIds.length > 0) {
+        console.log('鏍规嵁鍒嗗叕鍙窱D鍔犺浇鐢ㄦ埛:', deptIds)
+        this.loadStaffByBranchDepts(deptIds)
+      } else {
+        console.log('鏈紶鍏ュ垎鍏徃ID,缁勪欢涓嶅姞杞戒汉鍛樺垪琛�')
+        this.$modal && this.$modal.showToast && this.$modal.showToast('璇蜂紶鍏ュ垎鍏徃ID')
+      }
+    },
+    
+    // 鏍规嵁鍒嗗叕鍙窱D鏁扮粍鍔犺浇鐢ㄦ埛锛堟敮鎸佺紦瀛橈級
+    loadStaffByBranchDepts(deptIds) {
+      // 鐢熸垚缂撳瓨key锛堟寜鎺掑簭鍚巌d鎷兼帴锛�
+      const cacheKey = [...deptIds].sort((a, b) => a - b).join(',')
+      const cached = this.staffListCache[cacheKey]
+      const now = Date.now()
+      
+      // 妫�鏌ョ紦瀛樻槸鍚︽湁鏁�
+      if (cached && (now - cached.timestamp) < this.cacheExpireTime) {
+        console.log('浣跨敤缂撳瓨鐨勪汉鍛樺垪琛�:', cacheKey)
+        this.processUserList(cached.data)
+        return
+      }
+      
+      // 缂撳瓨澶辨晥鎴栦笉瀛樺湪,璋冪敤鎺ュ彛
+      console.log('鍔犺浇浜哄憳鍒楄〃:', deptIds)
+      listUsersByBranchDepts(deptIds).then(response => {
         const userList = response.data || []
-        
-        this.allStaffList = userList.map(user => ({
-          userId: user.userId,
-          nickName: user.nickName,
-          phonenumber: user.phonenumber,
-          deptName: user.dept?.deptName || '',
-          postName: user.posts && user.posts.length > 0 ? user.posts[0].postName : '',
-          roleName: user.roles && user.roles.length > 0 ? user.roles[0].roleName : '',
-          posts: user.posts || [],
-          roles: user.roles || [],
-          dept: user.dept || null,
-          // 鏀寔澶氱绫诲瀷
-          types: this.getUserTypes(user),
-          type: this.getUserTypes(user)[0] || 'driver' // 涓昏绫诲瀷锛堢敤浜庡悜鍚庡吋瀹癸級
-        }))
-        
-        this.filterStaffList()
+        // 鏇存柊缂撳瓨
+        this.staffListCache[cacheKey] = {
+          data: userList,
+          timestamp: now
+        }
+        this.processUserList(userList)
       }).catch(error => {
         console.error('鍔犺浇浜哄憳鍒楄〃澶辫触:', error)
         this.$modal.showToast('鍔犺浇浜哄憳鍒楄〃澶辫触')
       })
     },
+
+    
+    
+    // 澶勭悊鐢ㄦ埛鍒楄〃鏁版嵁
+    processUserList(userList) {
+      this.allStaffList = userList.map(user => ({
+        userId: user.userId,
+        nickName: user.nickName,
+        phonenumber: user.phonenumber,
+        deptName: user.dept?.deptName || '',
+        postName: user.posts && user.posts.length > 0 ? user.posts[0].postName : '',
+        roleName: user.roles && user.roles.length > 0 ? user.roles[0].roleName : '',
+        posts: user.posts || [],
+        roles: user.roles || [],
+        dept: user.dept || null,
+        // 鏀寔澶氱绫诲瀷
+        types: this.getUserTypes(user),
+        type: this.getUserTypes(user)[0] || 'driver' // 涓昏绫诲瀷锛堢敤浜庡悜鍚庡吋瀹癸級
+      }))
+      
+      this.filterStaffList()
+    },
     
     // 鏍规嵁鐢ㄦ埛鐨勫矖浣嶆垨瑙掕壊鍒ゆ柇鎵�鏈夌被鍨嬶紙鏀寔澶氱韬唤锛�
     getUserTypes(user) {

--
Gitblit v1.9.1