Explorar o código

fix: 根据登录状态显示/隐藏TabBar(未登录跳转发现页)

Ultraworked with Sisyphus
User hai 5 meses
pai
achega
8ddfd8678a
Modificáronse 1 ficheiros con 17 adicións e 0 borrados
  1. 17 0
      cfc-frontend/App.vue

+ 17 - 0
cfc-frontend/App.vue

@@ -6,13 +6,30 @@ export default {
     const token = uni.getStorageSync('token')
     if (token) {
       this.$store.commit('setToken', token)
+      // 已登录:确保原生 TabBar 显示
+      uni.showTabBar()
     } 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时尝试自动登录
       this.tryAutoLogin()
     }
   },
   onShow: function() {
     console.log('App Show')
+    // 每次显示时检查登录状态,同步 TabBar
+    const token = uni.getStorageSync('token')
+    if (token) {
+      uni.showTabBar()
+    } else {
+      uni.hideTabBar()
+    }
   },
   onHide: function() {
     console.log('App Hide')