App({ onLaunch() { this.checkLoginStatus() // 初始化本地存储 if (!wx.getStorageSync('records')) { wx.setStorageSync('records', []); } const defaultCategories = [ { id: 1, name: '餐饮', type: 'out', icon: 'cutlery' }, { id: 2, name: '交通', type: 'out', icon: 'car' }, { id: 3, name: '购物', type: 'out', icon: 'shopping-cart' }, { id: 4, name: '娱乐', type: 'out', icon: 'film' }, { id: 5, name: '工资', type: 'in', icon: 'money' }, { id: 6, name: '奖金', type: 'in', icon: 'gift' } ]; wx.setStorageSync('categories', defaultCategories); }, // 检查登录状态 checkLoginStatus() { // 从本地存储获取token const token = wx.getStorageSync('token') // const tokenExpire = wx.getStorageSync('tokenExpire') // 过期时间(可选) // // 检查token是否存在且未过期 // const isLogin = token && (!tokenExpire || Date.now() < tokenExpire) if (token) { // 已登录,跳转首页 wx.switchTab({ url: '/pages/index/index' // 首页路径 }) } else { // 未登录或token过期,跳转登录页 wx.redirectTo({ url: '/pages/login/login' // 登录页路径 }) } }, globalData: { userInfo: null } })