campus-errand/miniapp/App.vue
2026-03-01 05:01:47 +08:00

45 lines
1.2 KiB
Vue
Raw 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.

<script>
export default {
onLaunch: function() {
// 检查本地登录凭证是否存在Requirements 1.8
const token = uni.getStorageSync('token')
if (!token) {
// 未登录跳转登录页Requirements 1.1
uni.reLaunch({ url: '/pages/login/login' })
return
}
// 简单检查 JWT 是否过期Requirements 1.9
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>