48 lines
888 B
JavaScript
48 lines
888 B
JavaScript
const { baseUrl } = require('./request');
|
|
function checkLogin() {
|
|
const token = wx.getStorageSync('token');
|
|
try {
|
|
if (!token) {
|
|
wx.redirectTo({
|
|
url: '/pages/welcome/homePage/homePage',
|
|
});
|
|
}
|
|
} catch (e) {
|
|
wx.redirectTo({
|
|
url: '/pages/welcome/homePage/homePage',
|
|
});
|
|
}
|
|
|
|
wx.request({
|
|
url: baseUrl + '/userInfo/verify/token',
|
|
method: 'POST',
|
|
header: {
|
|
'Authorization': token
|
|
},
|
|
success: res => {
|
|
console.log('登录校验=======>', res.data)
|
|
if (res.data.code === 1) {
|
|
wx.switchTab({
|
|
url: '/pages/course/homepage/homepage'
|
|
})
|
|
} else {
|
|
wx.redirectTo({
|
|
url: '/pages/welcome/homePage/homePage',
|
|
});
|
|
}
|
|
},
|
|
fail: () => {
|
|
wx.redirectTo({
|
|
url: '/pages/welcome/homePage/homePage',
|
|
});
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
checkLogin
|
|
};
|