From 559b2e34c983f615b6d6747f52c801022c561803 Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期一, 27 十月 2025 23:05:08 +0800
Subject: [PATCH] feat: 优化任务显示列表
---
app/App.vue | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/app/App.vue b/app/App.vue
index 797f513..3610e7c 100644
--- a/app/App.vue
+++ b/app/App.vue
@@ -2,10 +2,17 @@
import config from './config'
import store from '@/store'
import { getToken } from '@/utils/auth'
+ import { getUnreadCount } from '@/api/message'
export default {
onLaunch: function() {
this.initApp()
+ },
+ onShow: function() {
+ // 搴旂敤鏄剧ず鏃跺埛鏂版湭璇绘秷鎭暟閲�
+ if (getToken()) {
+ this.updateUnreadMessageBadge()
+ }
},
methods: {
// 鍒濆鍖栧簲鐢�
@@ -16,6 +23,13 @@
//#ifdef H5
this.checkLogin()
//#endif
+
+ // 濡傛灉宸茬櫥褰曪紝鍚姩鏈娑堟伅杞
+ if (getToken()) {
+ this.updateUnreadMessageBadge()
+ // 姣�30绉掕疆璇竴娆�
+ this.startMessagePolling()
+ }
},
initConfig() {
this.globalData.config = config
@@ -24,6 +38,50 @@
if (!getToken()) {
this.$tab.reLaunch('/pages/login')
}
+ },
+
+ // 鏇存柊鏈娑堟伅寰芥爣
+ updateUnreadMessageBadge() {
+ getUnreadCount().then(response => {
+ const count = response.data || 0
+ console.log('鏈娑堟伅鏁伴噺:', count)
+
+ if (count > 0) {
+ // 璁剧疆寰芥爣
+ uni.setTabBarBadge({
+ index: 3, // 娑堟伅椤甸潰鍦╰abBar涓殑绱㈠紩浣嶇疆锛�0寮�濮嬶級
+ text: count > 99 ? '99+' : count.toString()
+ })
+ } else {
+ // 绉婚櫎寰芥爣
+ uni.removeTabBarBadge({
+ index: 3
+ })
+ }
+ }).catch(error => {
+ console.error('鑾峰彇鏈娑堟伅鏁伴噺澶辫触:', error)
+ })
+ },
+
+ // 鍚姩娑堟伅杞
+ startMessagePolling() {
+ // 姣�30绉掕疆璇竴娆�
+ this.messagePollingTimer = setInterval(() => {
+ if (getToken()) {
+ this.updateUnreadMessageBadge()
+ } else {
+ // 濡傛灉鐢ㄦ埛宸茬櫥鍑猴紝鍋滄杞
+ this.stopMessagePolling()
+ }
+ }, 30000) // 30绉�
+ },
+
+ // 鍋滄娑堟伅杞
+ stopMessagePolling() {
+ if (this.messagePollingTimer) {
+ clearInterval(this.messagePollingTimer)
+ this.messagePollingTimer = null
+ }
}
}
}
--
Gitblit v1.9.1