Files
qingcheng-xiaochengxu/utils/logcheck.js

48 lines
888 B
JavaScript
Raw Normal View History

2025-08-15 00:36:04 +08:00
const { baseUrl } = require('./request');
2025-05-15 21:01:14 +08:00
function checkLogin() {
2025-08-15 00:36:04 +08:00
const token = wx.getStorageSync('token');
2025-05-15 21:01:14 +08:00
try {
2025-08-15 00:36:04 +08:00
if (!token) {
wx.redirectTo({
url: '/pages/welcome/homePage/homePage',
2025-05-15 21:01:14 +08:00
});
}
} catch (e) {
2025-08-15 00:36:04 +08:00
wx.redirectTo({
url: '/pages/welcome/homePage/homePage',
2025-05-15 21:01:14 +08:00
});
}
2025-06-17 18:43:08 +08:00
2025-08-15 00:36:04 +08:00
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',
2025-06-17 18:43:08 +08:00
});
2025-08-15 00:36:04 +08:00
}
})
2025-06-17 18:43:08 +08:00
}
2025-08-15 00:36:04 +08:00
2025-05-15 21:01:14 +08:00
module.exports = {
2025-08-15 00:36:04 +08:00
checkLogin
2025-05-15 21:01:14 +08:00
};