// app.ts App({ globalData: { userInfo: null, isLoggedIn: false }, onLaunch() { // 检查登录状态 const token = wx.getStorageSync('token'); const userInfo = wx.getStorageSync('userInfo'); if (token && userInfo) { this.globalData.isLoggedIn = true; this.globalData.userInfo = userInfo; } else { // 未登录则跳转到登录页 wx.redirectTo({ url: '/pages/login/index' }); } // 登录 wx.login({ success: res => { console.log('微信登录成功,code:', res.code); }, }); }, // 检查登录状态的方法 checkLogin() { if (!this.globalData.isLoggedIn) { wx.redirectTo({ url: '/pages/login/index' }); return false; } return true; } });