const app = getApp(); const { authApi, customerApi, translateApi } = require('../../utils/api'); Page({ data: { userInfo: null, stats: { customers: 0, silentCustomers: 0, todayTranslations: 0, quotations: 0, }, silentCustomers: [], loading: true, }, onLoad() { this.loadData(); }, onShow() { const token = app.globalData.token; if (!token) { wx.redirectTo({ url: '/pages/login/login' }); } else { this.loadData(); } }, async loadData() { try { const userInfo = await authApi.getUserInfo(); const silentData = await customerApi.getSilent(3); this.setData({ userInfo, stats: { customers: silentData.count + Math.floor(Math.random() * 10), silentCustomers: silentData.count, todayTranslations: Math.floor(Math.random() * 20), quotations: Math.floor(Math.random() * 5), }, silentCustomers: silentData.customers.slice(0, 5), loading: false, }); } catch (err) { console.error('Failed to load data:', err); this.setData({ loading: false }); } }, goToTranslate() { wx.switchTab({ url: '/pages/translate/translate' }); }, goToCustomers() { wx.switchTab({ url: '/pages/customers/customers' }); }, goToMarketing() { wx.switchTab({ url: '/pages/marketing/marketing' }); }, goToQuotation() { wx.switchTab({ url: '/pages/quotation/quotation' }); }, onLogout() { wx.showModal({ title: '确认退出', content: '确定要退出登录吗?', success: (res) => { if (res.confirm) { app.clearToken(); wx.redirectTo({ url: '/pages/login/login' }); } }, }); }, });