2025-06-19 17:33:18 +08:00

63 lines
1.7 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// app.ts
App<IAppOption>({
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'
});
}
}
}
});