import { request } from '../utils/request' Component({ data: { selected: 0, unread: 0, list: [ { pagePath: '/pages/wardrobe/wardrobe', text: '衣橱', icon: 'icon-hanger' }, { pagePath: '/pages/outfit/outfit', text: '穿搭', icon: 'icon-shirt' }, { pagePath: '/pages/horoscope/horoscope', text: '运势', icon: 'icon-sparkles' }, { pagePath: '/pages/closet-share/closet-share', text: '分享', icon: 'icon-share' }, { pagePath: '/pages/profile/profile', text: '我的', icon: 'icon-user' }, ], }, lifetimes: { attached() { this.refreshUnread() }, }, methods: { refreshUnread() { const unread = (wx.getStorageSync('zt_closet_unread') as number) || 0 this.setData({ unread }) this.fetchUnread() }, fetchUnread() { request<{ unread_count: number }>({ url: '/notification/unread', showError: false }) .then((res) => { const unread = res.unread_count || 0 wx.setStorageSync('zt_closet_unread', unread) this.setData({ unread }) }) .catch(() => {}) }, switchTab(e: WechatMiniprogram.TouchEvent) { const { path, index } = e.currentTarget.dataset as { path: string; index: number } wx.switchTab({ url: path }) this.setData({ selected: index }) }, }, })