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

fix: 雷达图销毁后停止初始化重试 + 成长页定期调研改名成长回看并防御空项点击

liaoxg 2 месяцев назад
Родитель
Сommit
8f72a235eb
2 измененных файлов с 20 добавлено и 7 удалено
  1. 15 3
      cfc-frontend/components/RadarChart.vue
  2. 5 4
      cfc-frontend/pages/growth-main/index.vue

+ 15 - 3
cfc-frontend/components/RadarChart.vue

@@ -114,7 +114,11 @@ export default {
       _animScores: [],
       _animId: null,
       /** 当前实例唯一的 canvas id(同页多实例时避免 select('#radarCanvas') 命中错误节点) */
-      canvasId: 'radarCanvas_' + (this._uid || 0)
+      canvasId: 'radarCanvas_' + (this._uid || 0),
+      /** 组件已销毁标志:mounted 的延迟初始化与重试链需据此停止,避免销毁后继续查询节点刷错误日志 */
+      _destroyed: false,
+      /** mounted 延迟初始化定时器引用(beforeDestroy 时清理) */
+      _initTimer: null
     }
   },
   computed: {
@@ -165,18 +169,25 @@ export default {
     var retryCount = 0
     var maxRetry = 5
     function tryInit() {
+      if (self._destroyed) return
       self.initCanvas(function(success) {
+        if (self._destroyed) return
         if (!success && retryCount < maxRetry) {
           retryCount++
-          setTimeout(tryInit, 60)
+          self._initTimer = setTimeout(tryInit, 60)
         } else if (!success) {
           console.log('[RadarChart] 初始化失败,重试 ' + maxRetry + ' 次后放弃', self.canvasId)
         }
       })
     }
-    setTimeout(tryInit, 100)
+    self._initTimer = setTimeout(tryInit, 100)
   },
   beforeDestroy: function() {
+    this._destroyed = true
+    if (this._initTimer) {
+      clearTimeout(this._initTimer)
+      this._initTimer = null
+    }
     if (this._animId) {
       this._cancelAnim(this._animId)
       this._animId = null
@@ -204,6 +215,7 @@ export default {
         .exec(function(res) {
           // 兜底:回调内任何异常都必须走 cb(false),否则 mounted 的重试机制永远不触发 → 永久空白且无日志
           try {
+            if (self._destroyed) return
             if (!res || !res[0]) {
               console.log('[RadarChart] 查询失败: 未找到 canvas 节点', self.canvasId)
               if (cb) cb(false)

+ 5 - 4
cfc-frontend/pages/growth-main/index.vue

@@ -43,7 +43,7 @@
         </view>
         <view class="feat-card" @click="handleGuestFeatureTap">
           <text class="feat-icon">📋</text>
-          <text class="feat-title">定期调研</text>
+          <text class="feat-title">成长回看</text>
           <text class="feat-desc">每周家庭健康问卷</text>
         </view>
         <view class="feat-card" @click="handleGuestFeatureTap">
@@ -205,7 +205,7 @@
       </view>
       <view class="section">
         <view class="survey-card">
-          <text class="section-title-row">📋 定期调研</text>
+          <text class="section-title-row">📋 成长回看</text>
           <view class="survey-pending" v-if="pendingSurvey">
             <text class="survey-alert">⚠ 本周还未完成调研</text>
             <text class="survey-title-text">{{ pendingSurvey.title }}</text>
@@ -263,6 +263,7 @@ export default {
     dismissReminder: function() { this.hasIncomplete = false },
     switchTab: function(key) { this.activeTab = key; this.loadTrackingData(key) },
     handleProgressClick: function(item) {
+      if (!item || !item.key) return
       var m = { checkin: '/pages/health/daily-checkin', diet: '/pages/health/diet-index', exercise: '/pages/health/exercise-index', sleep: '/pages/health/sleep-index', emotion: '/pages/mind/index' }
       var url = m[item.key]
       if (item.key === 'survey' && this.pendingSurvey && this.pendingSurvey.templateId) {
@@ -304,7 +305,7 @@ export default {
       items.push({ key: 'exercise', icon: '🏃', label: '运动记录', done: false, actionText: '记录' })
       items.push({ key: 'emotion', icon: '😊', label: '心情记录', done: false, actionText: '记录' })
       items.push({ key: 'survey', icon: '📋', label: '本周调研', done: self.allDone, actionText: self.allDone ? '' : '开始' })
-      self.progressItems = items
+      self.progressItems = items.filter(function(it) { return it && it.key })
       self.incompleteCount = 0
       for (var pi = 0; pi < items.length; pi++) if (items[pi] && !items[pi].done) self.incompleteCount++
       self.hasIncomplete = self.incompleteCount > 0
@@ -316,7 +317,7 @@ export default {
         if (statusRes.code === 200 && statusRes.data) {
           var list = statusRes.data
           self.pendingSurvey = null; self.allDone = true; var hasAny = false
-          for (var si = 0; si < list.length; si++) { var s = list[si]; if (!s) continue; hasAny = true; if (s.status === 'pending') { self.pendingSurvey = { templateId: s.templateId, title: s.title || '定期调研', dimension: s.dimension || '' }; self.allDone = false } }
+          for (var si = 0; si < list.length; si++) { var s = list[si]; if (!s) continue; hasAny = true; if (s.status === 'pending') { self.pendingSurvey = { templateId: s.templateId, title: s.title || '成长回看', dimension: s.dimension || '' }; self.allDone = false } }
           if (!hasAny) { self.pendingSurvey = null; self.allDone = false }
         }
       } catch(e) {}