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

fix(frontend): 消除开发者工具告警 - getSystemInfoSync 弃用替换为 getWindowInfo, 修复 article-center articles prop 非数组类型错误

liaoxg 3 месяцев назад
Родитель
Сommit
16d67746bc

+ 2 - 0
cfc-frontend/AGENTS.md

@@ -98,6 +98,8 @@ pages.json 中定义 5 个 TabBar 页面(TabBar 文案,非五维维度名)
 - **NEVER** 在 CSS 类名、选择器中使用中文(如 `.val-偏高`、`.badge-低风险`),微信小程序 wxss 编译器不支持中文类名 → 使用英文(如 `.val-high`、`.badge-low`),数据中的中文状态通过 `_cssClass` 字段映射
 - **NEVER** 在 `:key` 中使用表达式(如 `:key="item.id || item.circleId"`),微信小程序模板编译器不支持带运算符的 `:key` 绑定 → 改用方法调用(如 `:key="getItemKey(item)"`,在 methods 中定义 `getItemKey(item) { return item.id || item.circleId }`)
 - **NEVER** 直接用 `new Date(string)` 解析日期字符串。部分 iOS(JavaScriptCore)的 `new Date()` 只支持 `yyyy/MM/dd`、`yyyy/MM/dd HH:mm:ss`、`yyyy-MM-dd`、`yyyy-MM-ddTHH:mm:ss`、`yyyy-MM-ddTHH:mm:ss+HH:mm` 格式,后端常见的 `"2026-08-22 14:00"`(空格分隔的 MySQL DATETIME 风格)和 Java 的 `"Sat Aug 22 14:00:00 CST 2026"` 会解析失败返回 Invalid Date → 一律使用 `utils/format.js` 的 `parseDate()`,它会自动归一化上述两种格式并返回 `Date|null`(如 `var d = parseDate(item.startTime); if (!d) return`)
+- **NEVER** 新增 `uni.getSystemInfoSync()` 调用。该 API 已在微信基础库 2.20.1+ 弃用,开发者工具会持续告警(`getSystemInfoSync is deprecated`)→ 改用 `uni.getWindowInfo()`(取 `windowWidth`/`pixelRatio`/`safeArea` 等窗口信息)或 `uni.getDeviceInfo()`(取 `system`/`brand`/`model` 等设备信息)。已有兼容代码(`components/mp-html/` 内的 `uni.canIUse('getWindowInfo')` 兜底)保持不变。参考替换:`uni.getSystemInfoSync().pixelRatio` → `uni.getWindowInfo().pixelRatio`
+- **NEVER** 给 `props` 传可能为非数组的值而不做兜底。组件接收 `Array` 类型 prop 时,父组件传值必须保证是数组(`|| []` 兜底 + `Array.isArray` 校验),否则触发 `Invalid prop: type check failed for prop "xxx". Expected Array, got Object` 告警。典型场景:接口返回结构不确定(`res.data.list` 可能为 `Object`)时,用 `var arr = (res.data && res.data.list) || (res.data instanceof Array ? res.data : [])` 三态兼容
 
 ## UNIQUE FEATURES
 

+ 1 - 1
cfc-frontend/components/FamilyRelationGraph.vue

@@ -230,7 +230,7 @@ export default {
     this._destroyed = false
     var self = this
     try {
-      this.dpr = uni.getSystemInfoSync().pixelRatio || 1
+      this.dpr = uni.getWindowInfo().pixelRatio || 1
     } catch (e) {
       this.dpr = 1
     }

+ 1 - 1
cfc-frontend/components/FamilyTianpanCard.vue

@@ -345,7 +345,7 @@ export default {
       .exec(function(res) {
         if (!res || !res[0] || !res[0].node) return
         var ctx = res[0].node.getContext('2d')
-        var dpr = uni.getSystemInfoSync().pixelRatio || 2
+        var dpr = uni.getWindowInfo().pixelRatio || 2
         var w = res[0].width
         var h = res[0].height
         

+ 1 - 1
cfc-frontend/components/RadarChart.vue

@@ -205,7 +205,7 @@ export default {
           var height = info.height
           if (!width || !height) { if (cb) cb(false); return }
 
-          var system = uni.getSystemInfoSync()
+          var system = uni.getWindowInfo()
           var pixelRatio = system.pixelRatio || 2
 
           canvas.width = width * pixelRatio

+ 2 - 2
cfc-frontend/components/wuxing-sandbox.vue

@@ -410,7 +410,7 @@ export default {
           var height = res[0].height
           if (!width || !height) return
 
-          var pixelRatio = uni.getSystemInfoSync().pixelRatio || 2
+          var pixelRatio = uni.getWindowInfo().pixelRatio || 2
 
           canvas.width = width * pixelRatio
           canvas.height = height * pixelRatio
@@ -482,7 +482,7 @@ export default {
           var height = res[0].height
           if (!width || !height) return
 
-          var pixelRatio = uni.getSystemInfoSync().pixelRatio || 2
+          var pixelRatio = uni.getWindowInfo().pixelRatio || 2
           canvas.width = width * pixelRatio
           canvas.height = height * pixelRatio
 

+ 3 - 1
cfc-frontend/pages/article-center/index.vue

@@ -227,7 +227,9 @@ export default {
       try {
         var res = await getFeaturedArticles({ size: 8 })
         if (res && res.code === 200 && res.data) {
-          self.recommendedArticles = res.data.list || res.data || []
+          // 兼容数组 / { list } / { records } 三种响应结构,保证永远赋值数组
+          var raw = Array.isArray(res.data) ? res.data : (res.data.list || res.data.records || [])
+          self.recommendedArticles = Array.isArray(raw) ? raw : []
         }
       } catch (e) {
         // silent fail

+ 1 - 1
cfc-frontend/pages/family/self-check-result.vue

@@ -196,7 +196,7 @@ export default {
         return
       }
       var ctx = res[0].node.getContext('2d')
-      var dpr = uni.getSystemInfoSync().pixelRatio
+      var dpr = uni.getWindowInfo().pixelRatio
       this.canvasContext = ctx
       this.canvasContext.scale(dpr, dpr)
       this.drawRadar()

+ 2 - 2
cfc-frontend/pages/mind-detail/emotion-checkin.vue

@@ -305,7 +305,7 @@ export default {
 
   onReady() {
     // 估算 grid 尺寸(基于屏幕宽度)
-    var sysInfo = uni.getSystemInfoSync()
+    var sysInfo = uni.getWindowInfo()
     // 页面左右margin=32rpx, section padding=28rpx
     // gridWidth ≈ screenWidth - (32+28)*2 = screenWidth - 120
     var screenWidth = sysInfo.windowWidth
@@ -348,7 +348,7 @@ export default {
       }
 
       // px → rpx 转换
-      var sysInfo = uni.getSystemInfoSync()
+      var sysInfo = uni.getWindowInfo()
       var scale = 750 / sysInfo.windowWidth
 
       // 直接使用事件中的偏移(px),然后转 rpx

+ 2 - 2
cfc-frontend/pages/mind-detail/family-dashboard.vue

@@ -383,7 +383,7 @@ export default {
           if (!res || !res[0] || !res[0].node) return
           
           const canvas = res[0].node
-          const dpr = uni.getSystemInfoSync().pixelRatio || 2
+          const dpr = uni.getWindowInfo().pixelRatio || 2
           const w = res[0].width
           const h = res[0].height
           
@@ -486,7 +486,7 @@ export default {
           if (!res || !res[0] || !res[0].node) return
           
           const canvas = res[0].node
-          const dpr = uni.getSystemInfoSync().pixelRatio || 2
+          const dpr = uni.getWindowInfo().pixelRatio || 2
           const w = res[0].width
           const h = res[0].height
           

+ 2 - 2
cfc-frontend/pages/mind/emotion-checkin.vue

@@ -282,7 +282,7 @@ export default {
 
   onReady() {
     // 估算 grid 尺寸(基于屏幕宽度)
-    var sysInfo = uni.getSystemInfoSync()
+    var sysInfo = uni.getWindowInfo()
     // 页面左右margin=32rpx, section padding=28rpx
     // gridWidth ≈ screenWidth - (32+28)*2 = screenWidth - 120
     var screenWidth = sysInfo.windowWidth
@@ -325,7 +325,7 @@ export default {
       }
 
       // px → rpx 转换
-      var sysInfo = uni.getSystemInfoSync()
+      var sysInfo = uni.getWindowInfo()
       var scale = 750 / sysInfo.windowWidth
 
       // 直接使用事件中的偏移(px),然后转 rpx

+ 1 - 1
cfc-frontend/pages/tianpan/annual-energy.vue

@@ -79,7 +79,7 @@ export default {
       var self = this
       if (!self.energy || !self.energy.dimensions) return
       var d = self.energy.dimensions
-      var w = uni.getSystemInfoSync().windowWidth
+      var w = uni.getWindowInfo().windowWidth
       var size = Math.min(w - 80, 260)
       var ctx = uni.createCanvasContext('energyRadar')
       var cx = size / 2, cy = size / 2, r = size / 2 - 30

+ 1 - 1
cfc-frontend/pages/tianpan/index.vue

@@ -213,7 +213,7 @@ export default {
         return
       }
       var ctx = res[0].node.getContext('2d')
-      var dpr = uni.getSystemInfoSync().pixelRatio
+      var dpr = uni.getWindowInfo().pixelRatio
       this.canvasContext = ctx
       this.canvasContext.scale(dpr, dpr)
       this.drawCanvas()

+ 2 - 2
cfc-frontend/pages/tianpan/relation-detail.vue

@@ -231,7 +231,7 @@ export default {
         return
       }
       var ctx = res[0].node.getContext('2d')
-      var dpr = uni.getSystemInfoSync().pixelRatio
+      var dpr = uni.getWindowInfo().pixelRatio
       this.scoreCanvasContext = ctx
       this.scoreCanvasContext.scale(dpr, dpr)
       
@@ -279,7 +279,7 @@ export default {
         return
       }
       var ctx = res[0].node.getContext('2d')
-      var dpr = uni.getSystemInfoSync().pixelRatio
+      var dpr = uni.getWindowInfo().pixelRatio
       this.trendCanvasContext = ctx
       this.trendCanvasContext.scale(dpr, dpr)