45 lines
1.1 KiB
Vue
45 lines
1.1 KiB
Vue
<script>
|
|
export default {
|
|
onLaunch: function() {
|
|
// 检查本地登录凭证是否存在
|
|
const token = uni.getStorageSync('token')
|
|
if (!token) {
|
|
// 未登录,跳转登录页
|
|
uni.reLaunch({ url: '/pages/login/login' })
|
|
return
|
|
}
|
|
|
|
// 简单检查 JWT 是否过期
|
|
try {
|
|
const parts = token.split('.')
|
|
if (parts.length === 3) {
|
|
const payload = JSON.parse(atob(parts[1]))
|
|
if (payload.exp && payload.exp * 1000 < Date.now()) {
|
|
// token 已过期,清除并跳转登录页
|
|
uni.removeStorageSync('token')
|
|
uni.removeStorageSync('userInfo')
|
|
uni.reLaunch({ url: '/pages/login/login' })
|
|
}
|
|
}
|
|
} catch (e) {
|
|
// 解析失败,清除无效 token
|
|
uni.removeStorageSync('token')
|
|
uni.removeStorageSync('userInfo')
|
|
uni.reLaunch({ url: '/pages/login/login' })
|
|
}
|
|
},
|
|
onShow: function() {},
|
|
onHide: function() {}
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
/* 全局公共样式 */
|
|
page {
|
|
background-color: #F5F5F5;
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
font-size: 28rpx;
|
|
color: #333333;
|
|
}
|
|
</style>
|