// app.ts App({ globalData: {}, onLaunch() { // 小程序每次打开都会调用一次 // 展示本地存储能力 const logs = wx.getStorageSync('logs') || []; logs.unshift(Date.now()); wx.setStorageSync('logs', logs); wx.getSetting({ success(res: any) { console.log(res.authSetting); if (!res.authSetting['scope.userLocation']) { wx.showToast({ title: '请在小程序设置界面中设置位置消息权限。', icon: 'none' }); } } }); // 登录 wx.login({ success: res => { console.log(res.code); // 发送 res.code 到后台换取 openId, sessionKey, unionId wx.setStorageSync('code', res.code); } }); // 判断是否登录 const token = wx.getStorageSync('token'); if (!token) { wx.reLaunch({ url: '/pages/login/login' }); } else { // 获取token,用户信息 判断账号角色然后跳转到对应的首页 let userInfo = wx.getStorageSync('userInfo'); if (userInfo.type == '1') { wx.reLaunch({ url: '/pages/driverIndex/index' }); } else if (userInfo.type == '2') { wx.reLaunch({ url: '/pages/manufacturerIndex/manufacturerIndex' }); } else if (userInfo.type == '3') { wx.reLaunch({ url: '/pages/projectIndex/projectIndex' }); } else if (userInfo.type == '4') { wx.reLaunch({ url: '/pages/maintenanceIndex/maintenanceIndex' }); } else { wx.reLaunch({ url: '/pages/login/login' }); } } } });