consumer-app/App.vue

53 lines
1.3 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<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>