Browse Source

feat(mind): 对接后端接口为家庭天盘提供动态数据

- 修改 pages/mind/index.vue 调用 /api/mind/fortune 接口
- 添加 getFamilyFortune API 函数到 utils/api.js
- 优先使用后端返回的数据,兼容模式使用前端算法
- 调整 FamilyTianpanCard 组件的数据绑定逻辑
User 2 tháng trước cách đây
mục cha
commit
1258299af2
2 tập tin đã thay đổi với 76 bổ sung25 xóa
  1. 73 25
      cfc-frontend/pages/mind/index.vue
  2. 3 0
      cfc-frontend/utils/api.js

+ 73 - 25
cfc-frontend/pages/mind/index.vue

@@ -324,7 +324,7 @@ import FamilyRelationGraph from '../../components/FamilyRelationGraph.vue'
 import PsychCrisisBanner from '../../components/PsychCrisisBanner.vue'
 import AIFloatingAvatar from '../../components/AIFloatingAvatar.vue'
 import FamilyTianpanCard from '../../components/FamilyTianpanCard.vue'
-import { getVisibleSections, getFeaturedArticles, getEmiReport, getFamilyEnergySandbox, getTodayTasksByCategory, getActivityList, getProductsByDomain, getChildren, getVisibleFamilyMembers, getEnergyOverview, getContactList, getHealthAlerts, getMilestones, getDanReportByChild } from '../../utils/api.js'
+import { getVisibleSections, getFeaturedArticles, getEmiReport, getFamilyEnergySandbox, getTodayTasksByCategory, getActivityList, getProductsByDomain, getChildren, getVisibleFamilyMembers, getEnergyOverview, getContactList, getHealthAlerts, getMilestones, getDanReportByChild, getFamilyFortune } from '../../utils/api.js'
 import config from '../../config.js'
 
 export default {
@@ -399,12 +399,15 @@ export default {
       milestones: [],
       danReports: [],
 
-      // 家庭天盘 - 今日心情(占位数据)
-      todayMood: {
+    // 家庭天盘 - 今日心情(占位数据)
+    todayMood: {
         emoji: '\u{1F60A}',
         text: '平静',
         score: 65
-      }
+    },
+    
+    // 家庭天盘 - 每日运势数据
+    dailyFortuneData: null
     }
   },
   computed: {
@@ -551,26 +554,36 @@ export default {
       return '0'
     },
     dailyFortune: function() {
-      if (!this.dominantElement) return null
-      var today = new Date()
-      var dateStr = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate()
-      var seedStr = dateStr + (this.fortuneSeed || '')
-      var hash = 0
-      for (var i = 0; i < seedStr.length; i++) {
-        hash = ((hash << 5) - hash) + seedStr.charCodeAt(i)
-        hash = hash & hash
-      }
-      var level = Math.abs(hash) % 5
-      var levels = ['大吉', '吉', '平', '凶', '大凶']
-      var descMap = {
-        wood: ['大吉:木气旺盛,宜规划', '吉:行动力强', '平:静心养性', '凶:谨言慎行', '大凶:忌冲动'],
-        fire: ['大吉:热情高涨', '吉:精力充沛', '平:适当休息', '凶:注意情绪', '大凶:静心冥想'],
-        earth: ['大吉:稳重踏实', '吉:贵人运佳', '平:按部就班', '凶:注意肠胃', '大凶:不宜投资'],
-        metal: ['大吉:决策力强', '吉:思维清晰', '平:保持专注', '凶:注意言辞', '大凶:不宜强求'],
-        water: ['大吉:灵感丰富', '吉:人际和谐', '平:安静内省', '凶:情绪波动', '大凶:宜藏不宜放']
-      }
-      var descList = descMap[this.dominantElement] || descMap.wood
-      return { level: level, text: levels[level], description: descList[level] }
+        // 优先使用后端接口数据
+        if (this.dailyFortuneData) {
+            var levels = ['大吉', '吉', '平', '凶', '大凶']
+            return {
+                level: this.dailyFortuneData.level,
+                text: levels[this.dailyFortuneData.level],
+                description: this.dailyFortuneData.description
+            }
+        }
+        // 兼容模式:没有接口数据时使用原算法
+        if (!this.dominantElement) return null
+        var today = new Date()
+        var dateStr = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate()
+        var seedStr = dateStr + (this.fortuneSeed || '')
+        var hash = 0
+        for (var i = 0; i < seedStr.length; i++) {
+            hash = ((hash << 5) - hash) + seedStr.charCodeAt(i)
+            hash = hash & hash
+        }
+        var level = Math.abs(hash) % 5
+        var levels = ['大吉', '吉', '平', '凶', '大凶']
+        var descMap = {
+            wood: ['大吉:木气旺盛,宜规划', '吉:行动力强', '平:静心养性', '凶:谨言慎行', '大凶:忌冲动'],
+            fire: ['大吉:热情高涨', '吉:精力充沛', '平:适当休息', '凶:注意情绪', '大凶:静心冥想'],
+            earth: ['大吉:稳重踏实', '吉:贵人运佳', '平:按部就班', '凶:注意肠胃', '大凶:不宜投资'],
+            metal: ['大吉:决策力强', '吉:思维清晰', '平:保持专注', '凶:注意言辞', '大凶:不宜强求'],
+            water: ['大吉:灵感丰富', '吉:人际和谐', '平:安静内省', '凶:情绪波动', '大凶:宜藏不宜放']
+        }
+        var descList = descMap[this.dominantElement] || descMap.wood
+        return { level: level, text: levels[level], description: descList[level] }
     }
   },
   onShow() {
@@ -602,6 +615,7 @@ export default {
     // 游客也能浏览活动和商品
     this.loadDimensionActivities()
     this.loadDimensionProducts()
+    this.loadFamilyFortune()
     this._watchPageReady()
   },
   methods: {
@@ -623,7 +637,41 @@ export default {
         }
       }).catch(function() {
         self.visibleSections = ['func_entries', 'daily_tip', 'recommended_reading', 'mind_tasks', 'related_activities', 'purchased_courses']
-      })
+        })
+    },
+
+    // 加载家庭天盘数据
+    loadFamilyFortune: function() {
+        var self = this
+        if (!self.isLoggedIn) return
+        
+        getFamilyFortune().then(function(res) {
+            if (res.code === 200 && res.data) {
+                // 更新 todayMood 占位数据为真实接口数据
+                self.todayMood = {
+                    emoji: res.data.moodEmoji || '\u{1F60A}',
+                    text: res.data.moodText || '平静',
+                    score: res.data.moodScore || 65
+                }
+                // 更新 dailyFortune computed 函数依赖的数据
+                self.dailyFortuneData = {
+                    level: res.data.fortuneLevel,
+                    text: res.data.fortuneLevelText,
+                    description: res.data.fortuneDescription
+                }
+                // 更新主导五行
+                self.traditionalData = self.traditionalData || {}
+                self.traditionalData.wuxingElements = {}
+                if (res.data.dominantElement) {
+                    self.traditionalData.wuxingElements[res.data.dominantElement] = 100
+                }
+                // 更新周报提示
+                self.compatibilityData = self.compatibilityData || {}
+                self.compatibilityData.weeklyInsight = res.data.weeklyTip || self.compatibilityData.weeklyInsight
+            }
+        }).catch(function(err) {
+            console.error('Failed to load family fortune:', err)
+        })
     },
     sectionVisible: function(key) {
       return this.visibleSections.length === 0 || this.visibleSections.indexOf(key) !== -1

+ 3 - 0
cfc-frontend/utils/api.js

@@ -1553,6 +1553,9 @@ export const saveNutritionProfile = (data) => request('/api/nutrition/profile/sa
 
 // ===== 钀ュ吇妗f涓庣己涔忓垎鏋?=====
 export const getChildNutritionProfile = (childId) => request('/api/health/nutrition/profile', 'POST', { childId })
+
+// ===== 家庭天盘 =====
+export const getFamilyFortune = () => request('/api/mind/fortune', 'POST', {})
 export const getDeficiencyAnalysis = (childId) => request('/api/health/nutrition/deficiency', 'POST', { childId })
 export const getDeficiencySummary = (childId) => request('/api/health/nutrition/deficiency-summary', 'POST', { childId })
 export const getNutritionTrend = (childId) => request('/api/health/nutrition/trend', 'POST', { childId })