Просмотр исходного кода

refactor: TabTransition 动态化 - 数据就绪后才自动消失

User 4 месяцев назад
Родитель
Сommit
9c56ed7a5e

+ 2 - 8
cfc-frontend/components/tab-transition.vue

@@ -1,6 +1,6 @@
 <template>
   <view class="tab-transition-overlay" :style="'background:' + bgGradient">
-    <view class="transition-content" :class="{ 'fade-out': fadeOut }">
+    <view class="transition-content">
       <!-- Large dimension character -->
       <text class="dim-char" :style="'color:' + dimConfig.color">{{ dimConfig.char }}</text>
       <!-- Icon -->
@@ -33,7 +33,6 @@ export default {
   },
   data() {
     return {
-      fadeOut: false
     }
   },
   computed: {
@@ -49,12 +48,7 @@ export default {
       return 'linear-gradient(160deg, #FFF7ED 0%, rgba(' + r + ',' + g + ',' + b + ',0.4) 100%)'
     }
   },
-  mounted() {
-    var self = this
-    setTimeout(function() {
-      self.fadeOut = true
-    }, 800)
-  }
+  // mounted 已清空:显隐完全由父组件 v-if 控制
 }
 </script>
 

+ 19 - 0
cfc-frontend/pages/action/index.vue

@@ -483,6 +483,25 @@ export default {
     },
     goRelationshipQuestionnaire: function() {
       uni.navigateTo({ url: '/pages/action-detail/relationship-questionnaire' })
+    },
+    _watchPageReady() {
+      var self = this
+      var unwatch = this.$watch(function() {
+        if (self.isLoggedIn) {
+          return !!(self.dualDimension || self.sandboxData || (self.dimensionTasks && self.dimensionTasks.length > 0))
+        }
+        return !!(self.dimensionActivities && self.dimensionActivities.length > 0) ||
+               !!(self.dimensionProducts && self.dimensionProducts.length > 0)
+      }, function(val) {
+        if (val) {
+          if (unwatch) unwatch()
+          self.showTabTransition = false
+        }
+      })
+      setTimeout(function() {
+        if (unwatch) unwatch()
+        self.showTabTransition = false
+      }, 5000)
     }
   }
 }

+ 20 - 5
cfc-frontend/pages/body/index.vue

@@ -321,12 +321,7 @@ export default {
     }
   },
   onShow() {
-    // Tabbar 切换过渡动画(最少停留 1 秒)
     this.showTabTransition = true
-    var self = this
-    setTimeout(function() {
-      self.showTabTransition = false
-    }, 1800)
 
     var token = uni.getStorageSync('token')
     this.isLoggedIn = !!token
@@ -345,6 +340,7 @@ export default {
     this.loadDimensionProducts()
     // 游客也能浏览文章
     this.loadFeaturedArticles()
+    this._watchPageReady()
   },
   methods: {
     loadSectionConfig: function() {
@@ -660,6 +656,25 @@ export default {
       } catch (e) {
         return dateStr
       }
+    },
+    _watchPageReady() {
+      var self = this
+      var unwatch = this.$watch(function() {
+        if (self.isLoggedIn) {
+          return !!(self.dualDimension || self.sandboxData || (self.dimensionTasks && self.dimensionTasks.length > 0))
+        }
+        return !!(self.dimensionActivities && self.dimensionActivities.length > 0) ||
+               !!(self.dimensionProducts && self.dimensionProducts.length > 0)
+      }, function(val) {
+        if (val) {
+          if (unwatch) unwatch()
+          self.showTabTransition = false
+        }
+      })
+      setTimeout(function() {
+        if (unwatch) unwatch()
+        self.showTabTransition = false
+      }, 5000)
     }
   }
 }

+ 1 - 0
cfc-frontend/pages/index/child-index.vue

@@ -608,6 +608,7 @@ export default {
         uni.showToast({ title: '加载失败', icon: 'none' })
       } finally {
         this.loading = false
+        this.$emit('ready')
       }
     },
     unlockBadge(id) {

+ 1 - 0
cfc-frontend/pages/index/parent-index.vue

@@ -648,6 +648,7 @@ export default {
         console.error('加载数据失败', e)
       } finally {
         this.loading = false
+        this.$emit('ready')
       }
     },
     async approveTask(taskId) {

+ 20 - 5
cfc-frontend/pages/mind/index.vue

@@ -442,12 +442,7 @@ export default {
     }
   },
   onShow() {
-    // Tabbar 切换过渡动画(最少停留 1 秒)
     this.showTabTransition = true
-    var self = this
-    setTimeout(function() {
-      self.showTabTransition = false
-    }, 1800)
 
     var token = uni.getStorageSync('token')
     this.isLoggedIn = !!token
@@ -474,6 +469,7 @@ export default {
     // 游客也能浏览活动和商品
     this.loadDimensionActivities()
     this.loadDimensionProducts()
+    this._watchPageReady()
   },
   methods: {
     // ===== 区块可见性 =====
@@ -868,6 +864,25 @@ export default {
           self.traditionalData = null
         }
       })
+    },
+    _watchPageReady() {
+      var self = this
+      var unwatch = this.$watch(function() {
+        if (self.isLoggedIn) {
+          return !!(self.emiData || self.energyOverview || (self.dimensionActivities && self.dimensionActivities.length > 0))
+        }
+        return !!(self.dimensionActivities && self.dimensionActivities.length > 0) ||
+               !!(self.dailyTip)
+      }, function(val) {
+        if (val) {
+          if (unwatch) unwatch()
+          self.showTabTransition = false
+        }
+      })
+      setTimeout(function() {
+        if (unwatch) unwatch()
+        self.showTabTransition = false
+      }, 5000)
     }
   }
 }

+ 14 - 6
cfc-frontend/pages/profile/profile.vue

@@ -100,19 +100,18 @@ export default {
     }
   },
   onShow() {
-    // Tabbar 切换过渡动画(最少停留 1 秒)
     this.showTabTransition = true
-    var self = this
-    setTimeout(function() {
-      self.showTabTransition = false
-    }, 1800)
 
-    if (!uni.getStorageSync('token')) return
+    if (!uni.getStorageSync('token')) {
+      this._watchPageReady()
+      return
+    }
     this.loadMascot()
     const currentRole = uni.getStorageSync('currentRole') || uni.getStorageSync('role') || 'parent'
     if (currentRole === 'teacher') {
       uni.redirectTo({ url: '/pages/teacher/teacher-profile' })
     }
+    this._watchPageReady()
   },
   methods: {
     goLogin() {
@@ -147,6 +146,15 @@ export default {
         this.selectedMascot = userInfo.mascot;
         this.currentMascotName = userInfo.mascot === 'xibao' ? '浠宝' : '福宝';
       }
+    },
+    _watchPageReady() {
+      var self = this
+      this.$nextTick(function() {
+        self.showTabTransition = false
+      })
+      setTimeout(function() {
+        self.showTabTransition = false
+      }, 2000)
     }
   }
 }

+ 20 - 5
cfc-frontend/pages/wisdom/index.vue

@@ -257,12 +257,7 @@ export default {
     }
   },
   onShow() {
-    // Tabbar 切换过渡动画(最少停留 1 秒)
     this.showTabTransition = true
-    var self = this
-    setTimeout(function() {
-      self.showTabTransition = false
-    }, 1800)
 
     var token = uni.getStorageSync('token')
     this.isLoggedIn = !!token
@@ -281,6 +276,7 @@ export default {
     this.loadDimensionProducts()
     // 游客也能浏览文章
     this.loadFeaturedArticles()
+    this._watchPageReady()
   },
   methods: {
     loadSectionConfig: function() {
@@ -530,6 +526,25 @@ export default {
     },
     goRelationshipQuestionnaire: function() {
       uni.navigateTo({ url: '/pages/wisdom-detail/relationship-questionnaire' })
+    },
+    _watchPageReady() {
+      var self = this
+      var unwatch = this.$watch(function() {
+        if (self.isLoggedIn) {
+          return !!(self.cognitiveReport || self.energyOverview)
+        }
+        return !!(self.dimensionActivities && self.dimensionActivities.length > 0) ||
+               !!(self.dimensionProducts && self.dimensionProducts.length > 0)
+      }, function(val) {
+        if (val) {
+          if (unwatch) unwatch()
+          self.showTabTransition = false
+        }
+      })
+      setTimeout(function() {
+        if (unwatch) unwatch()
+        self.showTabTransition = false
+      }, 5000)
     }
   }
 }

+ 1 - 1
cfc-frontend/utils/api.js

@@ -1046,7 +1046,7 @@ export const productCreate = (params) => {
   return request('/api/product/create', 'POST', params)
 }
 
-// 鏈嶅姟鍟嗘洿鏂板晢鍝?
+// 服务商更新商品
 export const productUpdate = (params) => {
   return request('/api/product/update', 'POST', params)
 }