Przeglądaj źródła

feat: 本地修改同步提交 - 小程序前端组件更新

openhands 3 miesięcy temu
rodzic
commit
42e530b173

+ 5 - 6
cfc-frontend/components/DimensionTasks.vue

@@ -24,6 +24,7 @@
 </template>
 </template>
 
 
 <script>
 <script>
+import api from '@/utils/api.js'
 export default {
 export default {
   props: {
   props: {
     dimensionCode: { type: String, required: true },
     dimensionCode: { type: String, required: true },
@@ -47,12 +48,10 @@ export default {
     loadTasks: function() {
     loadTasks: function() {
       var self = this
       var self = this
       if (!self.childId) return
       if (!self.childId) return
-      import('@/utils/api.js').then(function(api) {
-        api.getTodayTasksByCategory(self.childId, self.dimensionCode).then(function(res) {
-          self.tasksData = res.data || []
-        }).catch(function() {
-          // silently fail
-        })
+      api.getTodayTasksByCategory(self.childId, self.dimensionCode).then(function(res) {
+        self.tasksData = res.data || []
+      }).catch(function() {
+        // silently fail
       })
       })
     }
     }
   }
   }

+ 15 - 7
cfc-frontend/components/FamilyRelationGraph.vue

@@ -259,6 +259,14 @@ export default {
       this.startSimulation()
       this.startSimulation()
     },
     },
 
 
+    // hex → rgba(小程序不支持 8 位 hex 颜色 #RRGGBBAA)
+    hexToRgba: function(hex, alpha) {
+      var r = parseInt(hex.slice(1, 3), 16)
+      var g = parseInt(hex.slice(3, 5), 16)
+      var b = parseInt(hex.slice(5, 7), 16)
+      return 'rgba(' + r + ',' + g + ',' + b + ',' + alpha + ')'
+    },
+
     startSimulation: function() {
     startSimulation: function() {
       if (this.isSimulating) return
       if (this.isSimulating) return
       this.isSimulating = true
       this.isSimulating = true
@@ -399,10 +407,10 @@ export default {
       // 6. 渲染
       // 6. 渲染
       this.render()
       this.render()
 
 
-      // 7. 下一帧
-      this.animFrameId = requestAnimationFrame(function() {
+      // 7. 下一帧(小程序无 requestAnimationFrame,用 setTimeout 降级)
+      this.animFrameId = setTimeout(function() {
         self.simulationTick()
         self.simulationTick()
-      })
+      }, 16)
     },
     },
 
 
     // ===== 渲染 =====
     // ===== 渲染 =====
@@ -474,7 +482,7 @@ export default {
           ctx.lineWidth = 3
           ctx.lineWidth = 3
           ctx.stroke()
           ctx.stroke()
         } else {
         } else {
-          ctx.fillStyle = this.themeColor + '22'
+          ctx.fillStyle = this.hexToRgba(this.themeColor, 0.13)
           ctx.fill()
           ctx.fill()
         }
         }
 
 
@@ -529,18 +537,18 @@ export default {
           ctx.setLineWidth(3)
           ctx.setLineWidth(3)
           ctx.stroke()
           ctx.stroke()
         } else {
         } else {
-          ctx.setFillStyle(this.themeColor + '22')
+          ctx.setFillStyle(this.hexToRgba(this.themeColor, 0.13))
           ctx.fill()
           ctx.fill()
         }
         }
 
 
         ctx.setFillStyle(node.isSelf ? this.themeColor : '#4A5568')
         ctx.setFillStyle(node.isSelf ? this.themeColor : '#4A5568')
-        ctx.setFont('bold ' + (r * 0.9) + 'px sans-serif')
+        ctx.font = 'bold ' + (r * 0.9) + 'px sans-serif'
         ctx.setTextAlign('center')
         ctx.setTextAlign('center')
         ctx.setTextBaseline('middle')
         ctx.setTextBaseline('middle')
         ctx.fillText(node.displayName, node.x, node.y)
         ctx.fillText(node.displayName, node.x, node.y)
 
 
         ctx.setFillStyle(node.isSelf ? this.themeColor : '#94A3B8')
         ctx.setFillStyle(node.isSelf ? this.themeColor : '#94A3B8')
-        ctx.setFont((r * 0.4) + 'px sans-serif')
+        ctx.font = (r * 0.4) + 'px sans-serif'
         ctx.fillText(node.nickname.substring(0, 3), node.x, node.y + r + 10)
         ctx.fillText(node.nickname.substring(0, 3), node.x, node.y + r + 10)
       }
       }
 
 

+ 23 - 26
cfc-frontend/components/HealthCheckinCard.vue

@@ -23,6 +23,7 @@
 </template>
 </template>
 
 
 <script>
 <script>
+import api from '@/utils/api.js'
 export default {
 export default {
   props: {
   props: {
     childId: { type: Number, default: null }
     childId: { type: Number, default: null }
@@ -92,19 +93,17 @@ export default {
     loadCheckins: function() {
     loadCheckins: function() {
       var self = this
       var self = this
       if (!this.childId) return
       if (!this.childId) return
-      import('@/utils/api.js').then(function(api) {
-        var now = new Date()
-        var yearMonth = now.getFullYear() + '-' + ('' + (now.getMonth() + 1)).padStart(2, '0')
-        api.healthCheckinList({
-          childId: self.childId,
-          yearMonth: yearMonth
-        }).then(function(res) {
-          if (res.data) {
-            self.checkins = res.data
-          }
-        }).catch(function() {
-          self.checkins = []
-        })
+      var now = new Date()
+      var yearMonth = now.getFullYear() + '-' + ('' + (now.getMonth() + 1)).padStart(2, '0')
+      api.healthCheckinList({
+        childId: self.childId,
+        yearMonth: yearMonth
+      }).then(function(res) {
+        if (res.data) {
+          self.checkins = res.data
+        }
+      }).catch(function() {
+        self.checkins = []
       })
       })
     },
     },
     doCheckin: function() {
     doCheckin: function() {
@@ -115,19 +114,17 @@ export default {
       }
       }
       if (this.loading) return
       if (this.loading) return
       this.loading = true
       this.loading = true
-      import('@/utils/api.js').then(function(api) {
-        api.healthCheckinCreate({
-          childId: self.childId,
-          checkinDate: self.getDateString(new Date()),
-          behaviors: [],
-          mood: 'happy'
-        }).then(function(res) {
-          self.loading = false
-          uni.showToast({ title: '打卡成功!+' + (res.data && res.data.earnedEnergy || 5) + '身能量', icon: 'none' })
-          self.checkins.unshift(res.data)
-        }).catch(function() {
-          self.loading = false
-        })
+      api.healthCheckinCreate({
+        childId: self.childId,
+        checkinDate: self.getDateString(new Date()),
+        behaviors: [],
+        mood: 'happy'
+      }).then(function(res) {
+        self.loading = false
+        uni.showToast({ title: '打卡成功!+' + (res.data && res.data.earnedEnergy || 5) + '身能量', icon: 'none' })
+        self.checkins.unshift(res.data)
+      }).catch(function() {
+        self.loading = false
       })
       })
     }
     }
   }
   }

+ 4 - 2
cfc-frontend/pages/teacher/teacher-profile.vue

@@ -90,10 +90,12 @@ export default {
     }
     }
   },
   },
   onLoad() {
   onLoad() {
-    this.nickname = uni.getStorageSync('userInfo')?.nickname || ''
+    var _userInfo = uni.getStorageSync('userInfo')
+    this.nickname = (_userInfo && _userInfo.nickname) || ''
   },
   },
   onShow() {
   onShow() {
-    this.nickname = uni.getStorageSync('userInfo')?.nickname || ''
+    var _userInfo = uni.getStorageSync('userInfo')
+    this.nickname = (_userInfo && _userInfo.nickname) || ''
   },
   },
   methods: {
   methods: {
     async switchToParent() {
     async switchToParent() {