| 12345678910111213141516171819202122232425 |
- /**
- * 底部「消息」Tab 角标:统一走 GET /messages/unread-count
- */
- import { getUnreadCount, getToken } from '../utils/api'
- import { chatStore } from '../store/chat'
- export async function fetchUnreadCountAndUpdateTabBar() {
- const token = getToken()
- if (!token) {
- chatStore.setTabBarUnreadFromServer(0)
- return
- }
- try {
- const raw = await getUnreadCount(token)
- const n =
- typeof raw === 'number'
- ? raw
- : raw != null && typeof raw === 'object'
- ? Number(raw.count ?? raw.unread_count ?? raw.total ?? 0)
- : Number(raw) || 0
- chatStore.setTabBarUnreadFromServer(n)
- } catch (e) {
- // 网络失败时保留当前角标
- }
- }
|