|
@@ -6,13 +6,30 @@ export default {
|
|
|
const token = uni.getStorageSync('token')
|
|
const token = uni.getStorageSync('token')
|
|
|
if (token) {
|
|
if (token) {
|
|
|
this.$store.commit('setToken', token)
|
|
this.$store.commit('setToken', token)
|
|
|
|
|
+ // 已登录:确保原生 TabBar 显示
|
|
|
|
|
+ uni.showTabBar()
|
|
|
} else {
|
|
} else {
|
|
|
|
|
+ // 未登录:隐藏原生 TabBar
|
|
|
|
|
+ uni.hideTabBar()
|
|
|
|
|
+ // 如果当前不在发现页或商城页,则跳转
|
|
|
|
|
+ const pages = getCurrentPages()
|
|
|
|
|
+ const currentRoute = pages.length > 0 ? pages[pages.length - 1].route : ''
|
|
|
|
|
+ if (currentRoute !== 'pages/discover/index' && currentRoute !== 'pages/shop/index') {
|
|
|
|
|
+ uni.reLaunch({ url: '/pages/discover/index' })
|
|
|
|
|
+ }
|
|
|
// 无token时尝试自动登录
|
|
// 无token时尝试自动登录
|
|
|
this.tryAutoLogin()
|
|
this.tryAutoLogin()
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
onShow: function() {
|
|
onShow: function() {
|
|
|
console.log('App Show')
|
|
console.log('App Show')
|
|
|
|
|
+ // 每次显示时检查登录状态,同步 TabBar
|
|
|
|
|
+ const token = uni.getStorageSync('token')
|
|
|
|
|
+ if (token) {
|
|
|
|
|
+ uni.showTabBar()
|
|
|
|
|
+ } else {
|
|
|
|
|
+ uni.hideTabBar()
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
onHide: function() {
|
|
onHide: function() {
|
|
|
console.log('App Hide')
|
|
console.log('App Hide')
|