53 lines
1.3 KiB
Vue
53 lines
1.3 KiB
Vue
<script>
|
||
export default {
|
||
globalData: {
|
||
// 用于从首页跳转到服务页面时传递需要高亮的分类
|
||
serviceCategory: null
|
||
},
|
||
onLaunch: function() {
|
||
console.log('App Launch')
|
||
// 检查登录状态
|
||
this.checkLoginStatus()
|
||
},
|
||
onShow: function() {
|
||
console.log('App Show')
|
||
},
|
||
onHide: function() {
|
||
console.log('App Hide')
|
||
},
|
||
methods: {
|
||
// 检查登录状态
|
||
checkLoginStatus() {
|
||
const token = uni.getStorageSync('token')
|
||
|
||
// 如果有token,且当前在登录页,则跳转到首页
|
||
if (token) {
|
||
// 延迟一下,确保页面已经初始化
|
||
setTimeout(() => {
|
||
const pages = getCurrentPages()
|
||
const currentPage = pages[pages.length - 1]
|
||
const currentRoute = currentPage ? currentPage.route : ''
|
||
|
||
// 如果当前在登录页,跳转到首页
|
||
if (currentRoute === 'pages/login/login') {
|
||
uni.switchTab({
|
||
url: '/pages/index/index',
|
||
fail: () => {
|
||
// 如果switchTab失败(可能不在tabBar页面),使用reLaunch
|
||
uni.reLaunch({
|
||
url: '/pages/index/index'
|
||
})
|
||
}
|
||
})
|
||
}
|
||
}, 100)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style>
|
||
/*每个页面公共css */
|
||
</style>
|