index.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  1. <template>
  2. <view class="body-container">
  3. <!-- Tabbar 切换过渡页 -->
  4. <tab-transition v-if="showTabTransition" dimCode="body" />
  5. <!-- 品牌头部 -->
  6. <PageBanner theme="body"
  7. tagline="科学管理全家健康"
  8. quote="身体健康是幸福的基础" />
  9. <!-- 游客专属区块 -->
  10. <template v-if="!isLoggedIn">
  11. <LoginGuideCard
  12. title="登录后查看全家健康数据"
  13. :items="[
  14. '查看全家身体能量数据和健康报告',
  15. '记录每日健康打卡,获取身体能量',
  16. '查看专属健康商品和活动价格'
  17. ]" />
  18. <HealthTips dimension="body" />
  19. </template>
  20. <!-- 登录后:五维能量条 -->
  21. <FamilyEnergyBar
  22. v-if="isLoggedIn"
  23. dimensionCode="body"
  24. :sandboxData="sandboxData"
  25. :dualDimension="dualDimension" />
  26. <!-- 关系图谱(登录后可见) -->
  27. <FamilyRelationGraph
  28. v-if="isLoggedIn && familyMembersVisible.length > 0"
  29. dimensionCode="body"
  30. :selfId="activeChildId"
  31. :members="familyMembersVisible"
  32. :energyMap="energyMapForGraph"
  33. :intimacyMap="intimacyMapForGraph"
  34. @memberTap="goMemberDetail" />
  35. <!-- 健康打卡卡片 -->
  36. <HealthCheckinCard
  37. v-if="isLoggedIn && activeChildId"
  38. :childId="activeChildId" />
  39. <!-- 雷达图 -->
  40. <view class="section" v-if="dimensionData">
  41. <view class="section-header" v-if="dimensionData.isAverage">
  42. <text class="section-title">七维健康图</text>
  43. <text class="avg-badge">同龄同性平均值 · 上传报告后显示个人数据</text>
  44. </view>
  45. <view class="section-header" v-else>
  46. <text class="section-title">七维健康图</text>
  47. </view>
  48. <RadarChart
  49. v-if="radarDimensions && radarDimensions.length >= 3"
  50. :dimensions="radarDimensions"
  51. :scores="radarScores"
  52. :avg-scores="radarAvgScores"
  53. fillColor="#FF8C42"
  54. gridColor="#FED7AA"
  55. labelColor="#9A3412"
  56. :width="580"
  57. :height="580"
  58. @dimensionClick="goDimensionDetail" />
  59. </view>
  60. <!-- 七维健康全景(嵌入卡片) -->
  61. <HealthDimensionsSection
  62. v-if="isLoggedIn && dimensionData"
  63. :healthData="dimensionData"
  64. :activeChildId="activeChildId || ($store.state && $store.state.currentChildId)" />
  65. <!-- 功能入口 -->
  66. <view class="func-section" v-if="sectionVisible('func_entries')">
  67. <view class="func-grid">
  68. <view class="func-item" v-for="item in funcList" :key="item.label" @click="onFuncClick(item)">
  69. <view class="func-icon-wrap">
  70. <text class="func-icon">{{ item.icon }}</text>
  71. </view>
  72. <text class="func-label">{{ item.label }}</text>
  73. </view>
  74. </view>
  75. </view>
  76. <!-- ===== 精准营养(含上传报告入口) ===== -->
  77. <view class="nutrition-section section" v-if="isLoggedIn">
  78. <view class="nutrition-report-card" @click="goToUploadReport">
  79. <view class="nutrition-report-left">
  80. <text class="nutrition-icon-large">🏥</text>
  81. </view>
  82. <view class="nutrition-report-right">
  83. <text class="nutrition-title">上传健康报告</text>
  84. <text class="nutrition-desc">上传体检报告或肠道检测报告,获取 AI 深度解读与精准营养推荐</text>
  85. <view class="nutrition-report-tags">
  86. <text class="tag">体检报告</text>
  87. <text class="tag">肠道检测</text>
  88. <text class="tag">AI分析</text>
  89. </view>
  90. </view>
  91. <text class="nutrition-arrow">›</text>
  92. </view>
  93. </view>
  94. <!-- ===== 精准营养(上传报告+产品+文章) ===== -->
  95. <view class="section nutrition-section" v-if="isLoggedIn">
  96. <view class="section-header">
  97. <text class="section-title">🥗 精准营养</text>
  98. </view>
  99. <!-- 上传报告入口 -->
  100. <view class="nutrition-report-card" @click="goToUploadReport">
  101. <view class="nutrition-report-left">
  102. <text class="nutrition-icon-large">📋</text>
  103. </view>
  104. <view class="nutrition-report-right">
  105. <text class="nutrition-title">上传健康报告</text>
  106. <text class="nutrition-desc">上传体检报告或肠道检测报告,AI智能解读分析,获取个性化营养方案</text>
  107. <view class="nutrition-report-tags">
  108. <text class="tag">体检报告</text>
  109. <text class="tag">肠道检测</text>
  110. <text class="tag">AI解读</text>
  111. </view>
  112. </view>
  113. <text class="nutrition-arrow">›</text>
  114. </view>
  115. </view>
  116. <!-- 维度任务 -->
  117. <DimensionTasks
  118. v-if="isLoggedIn"
  119. dimensionCode="body"
  120. :tasks="dimensionTasks"
  121. @taskClick="onTaskClick"
  122. @moreTasks="goTasks" />
  123. <!-- 维度活动 -->
  124. <DimensionActivities
  125. dimensionCode="body"
  126. :activities="dimensionActivities"
  127. :isLoggedIn="isLoggedIn"
  128. @activityClick="goActivityDetail"
  129. @moreActivities="goMoreActivities" />
  130. <!-- 商品推荐 -->
  131. <DimensionProductList
  132. v-if="isLoggedIn"
  133. dimensionCode="body"
  134. :familyId="activeChildId"
  135. title="为你推荐" />
  136. <!-- 推荐阅读 -->
  137. <DimensionArticles
  138. dimensionCode="body"
  139. :articles="bodyArticles"
  140. :isLoggedIn="isLoggedIn"
  141. @articleClick="goArticleDetail"
  142. @moreArticles="goMoreArticles" />
  143. <!-- 底部占位 -->
  144. <view class="bottom-spacer"></view>
  145. <AIFloatingAvatar />
  146. </view>
  147. </template>
  148. <script>
  149. import TabTransition from '../../components/tab-transition.vue'
  150. import PageBanner from '../../components/PageBanner.vue'
  151. import LoginGuideCard from '../../components/LoginGuideCard.vue'
  152. import FamilyEnergyBar from '../../components/FamilyEnergyBar.vue'
  153. import DimensionTasks from '../../components/DimensionTasks.vue'
  154. import DimensionActivities from '../../components/DimensionActivities.vue'
  155. import DimensionProducts from '../../components/DimensionProducts.vue'
  156. import DimensionProductList from '../../components/DimensionProductList.vue'
  157. import DimensionArticles from '../../components/DimensionArticles.vue'
  158. import FamilyRelationGraph from '../../components/FamilyRelationGraph.vue'
  159. import RadarChart from '../../components/RadarChart.vue'
  160. import HealthDimensionsSection from '../../components/HealthDimensionsSection.vue'
  161. import HealthCheckinCard from '../../components/HealthCheckinCard.vue'
  162. import AIFloatingAvatar from '../../components/AIFloatingAvatar.vue'
  163. import { getVisibleSections, getEnergyOverview, getChildren, getTodayTasksByCategory, getActivityList, getProductsByDomain, getFamilyEnergySandbox, getVisibleFamilyMembers, getDimensionOverview, getFeaturedArticles } from '../../utils/api.js'
  164. import config from '../../config.js'
  165. var BASE_URL = config.api('')
  166. const healthRequest = function(url, data) {
  167. var token = uni.getStorageSync('token')
  168. return new Promise(function(resolve, reject) {
  169. uni.request({
  170. url: BASE_URL + url,
  171. method: 'POST',
  172. data: data,
  173. header: {
  174. 'Content-Type': 'application/json',
  175. 'Authorization': token ? 'Bearer ' + token : ''
  176. },
  177. success: function(res) {
  178. if (res.data.code === 200) {
  179. resolve(res.data)
  180. } else {
  181. reject(res.data)
  182. }
  183. },
  184. fail: function(err) {
  185. reject(err)
  186. }
  187. })
  188. })
  189. }
  190. export default {
  191. components: { TabTransition, PageBanner, LoginGuideCard, FamilyEnergyBar, DimensionTasks, DimensionActivities, DimensionProducts, DimensionProductList, DimensionArticles, FamilyRelationGraph, RadarChart, HealthDimensionsSection, HealthCheckinCard, AIFloatingAvatar },
  192. data() {
  193. return {
  194. isLoggedIn: false,
  195. role: null,
  196. showTabTransition: true,
  197. activeChildId: null,
  198. activeChildName: '',
  199. currentUserId: null,
  200. userName: '',
  201. children: [],
  202. familyMembersVisible: [],
  203. sandboxData: null,
  204. dualDimension: null,
  205. visibleSections: [],
  206. latestReport: null,
  207. dimensionTasks: [],
  208. dimensionActivities: [],
  209. dimensionProducts: [],
  210. bodyArticles: [],
  211. dimensionData: null,
  212. /** Mock 平均值(7维):生长发育/睡眠质量/视力健康/免疫力/营养均衡/肠胃健康/运动活力 */
  213. radarAvgScores: [72, 68, 75, 70, 73, 69, 71],
  214. funcList: [
  215. { icon: '\u{1F3C3}', label: '运动', needLogin: true, page: '/pages/body/exercise-record' },
  216. { icon: '\u{1F957}', label: '饮食', needLogin: true, page: '/pages/body/meal-record' },
  217. { icon: '\u{1F634}', label: '作息', needLogin: true, page: '/pages/body/sleep-record' },
  218. { icon: '\u{1F9D8}', label: '冥想', needLogin: true, page: '/pages/health/meditation-index' },
  219. { icon: '\u{1F4CA}', label: '舌诊', needLogin: true, page: '/pages/health/report-upload?reportType=tongue' }
  220. ]
  221. }
  222. },
  223. computed: {
  224. reportTypeLabel: function() {
  225. if (!this.latestReport) return ''
  226. return this.latestReport.reportType === 'gut_flora' ? '肠道检测报告' : '体检报告'
  227. },
  228. energyMapForGraph: function() {
  229. var map = {}
  230. if (this.sandboxData && this.sandboxData.members) {
  231. for (var i = 0; i < this.sandboxData.members.length; i++) {
  232. var m = this.sandboxData.members[i]
  233. map[m.memberId || m.id] = {
  234. bodyScore: m.bodyScore || 0,
  235. mindScore: m.mindScore || 0,
  236. actionScore: m.actionScore || 0
  237. }
  238. }
  239. }
  240. return map
  241. },
  242. intimacyMapForGraph: function() {
  243. return {}
  244. },
  245. /** 七维雷达图:维度标签(遵守 AGENTS.md 禁止模板内方法调用,使用 computed 缓存) */
  246. radarDimensions: function() {
  247. var dims = this.dimensionData && this.dimensionData.dimensions
  248. if (!dims) return []
  249. var result = []
  250. for (var i = 0; i < dims.length; i++) {
  251. var d = dims[i]
  252. if (!d) continue
  253. result.push({ label: d.label || '', key: d.dimension || '' })
  254. }
  255. return result
  256. },
  257. /** 七维雷达图:分值(对 null/NaN 做归一化,避免 Canvas 计算 NaN 静默失败) */
  258. radarScores: function() {
  259. var dims = this.dimensionData && this.dimensionData.dimensions
  260. if (!dims) return []
  261. var result = []
  262. for (var i = 0; i < dims.length; i++) {
  263. var d = dims[i]
  264. if (!d) { result.push(0); continue }
  265. var s = d.score
  266. if (typeof s !== 'number' || isNaN(s) || s === null) s = 0
  267. result.push(s)
  268. }
  269. return result
  270. }
  271. },
  272. onShow() {
  273. this.showTabTransition = true
  274. var token = uni.getStorageSync('token')
  275. this.isLoggedIn = !!token
  276. if (this.isLoggedIn) {
  277. this.role = uni.getStorageSync('currentRole') || uni.getStorageSync('role') || null
  278. this.userName = uni.getStorageSync('nickname') || uni.getStorageSync('userName') || '家长'
  279. this.currentUserId = uni.getStorageSync('userId')
  280. // FIX: 同步 Vuex store 的 currentView 和 currentChildId
  281. if (this.$store.state && this.$store.state.currentView) {
  282. if (this.$store.state.currentView === 'member' && this.$store.state.currentChildId) {
  283. this.activeChildId = this.$store.state.currentChildId
  284. }
  285. }
  286. }
  287. this.loadSectionConfig()
  288. if (this.isLoggedIn) {
  289. this.loadChildren()
  290. this.loadFamilyMembersVisible()
  291. }
  292. // 游客也能浏览活动和商品
  293. this.loadDimensionActivities()
  294. this.loadDimensionProducts()
  295. // 游客也能浏览文章
  296. this.loadFeaturedArticles()
  297. this._watchPageReady()
  298. },
  299. methods: {
  300. loadSectionConfig: function() {
  301. var baseSections = ['func_entries']
  302. if (!uni.getStorageSync('token')) {
  303. this.visibleSections = baseSections
  304. return
  305. }
  306. var role = uni.getStorageSync('currentRole') || uni.getStorageSync('role') || null
  307. var self = this
  308. getVisibleSections({ pageKey: 'body', role: role }).then(function(res) {
  309. if (res.code === 200 && res.data) {
  310. var keys = res.data.map(function(s) { return s.sectionKey })
  311. var merged = baseSections.slice()
  312. keys.forEach(function(k) { if (merged.indexOf(k) === -1) merged.push(k) })
  313. self.visibleSections = merged
  314. }
  315. }).catch(function(e) {
  316. self.visibleSections = ['func_entries']
  317. })
  318. },
  319. loadChildren: function() {
  320. var self = this
  321. getChildren().then(function(res) {
  322. if (res.code === 200 && res.data) {
  323. self.children = res.data
  324. var savedChildId = uni.getStorageSync('currentChildId')
  325. var found = false
  326. for (var i = 0; i < self.children.length; i++) {
  327. if (self.children[i].childId === savedChildId) {
  328. self.activeChildId = savedChildId
  329. self.activeChildName = self.children[i].name || self.children[i].nickname || '孩子'
  330. found = true
  331. break
  332. }
  333. }
  334. if (!found && self.children.length > 0) {
  335. self.activeChildId = self.children[0].childId
  336. self.activeChildName = self.children[0].name || self.children[0].nickname || '孩子'
  337. uni.setStorageSync('currentChildId', self.activeChildId)
  338. }
  339. if (self.activeChildId) {
  340. self.loadDashboardData()
  341. }
  342. }
  343. }).catch(function(e) {
  344. console.log('获取孩子列表失败', e)
  345. })
  346. },
  347. loadDashboardData: function() {
  348. // FIX: 不再阻塞于 activeChildId 为空。
  349. // 沙盒数据(家庭级别)始终加载;子维度数据按需加载
  350. this.loadSandboxData()
  351. this.loadHealthDimensions()
  352. if (this.activeChildId) {
  353. this.loadHealthReport()
  354. this.loadEnergyData()
  355. this.loadDimensionTasks()
  356. }
  357. },
  358. loadHealthDimensions: function() {
  359. var memberId = this.activeChildId || this.currentUserId
  360. if (!memberId) {
  361. console.log('[body] loadHealthDimensions skipped: no memberId available')
  362. return
  363. }
  364. var self = this
  365. getDimensionOverview({ memberId: memberId }).then(function(res) {
  366. if (res && res.data) {
  367. self.dimensionData = res.data
  368. console.log('[body] dimensionData loaded:', res.data.dimensions ? res.data.dimensions.length : 0, 'dimensions')
  369. } else if (res) {
  370. console.warn('[body] dimension API error:', res.message || res.code)
  371. }
  372. }).catch(function(e) {
  373. console.error('[body] loadHealthDimensions failed', e)
  374. })
  375. },
  376. loadSandboxData: function() {
  377. var self = this
  378. getFamilyEnergySandbox().then(function(res) {
  379. if (res && res.data) {
  380. self.sandboxData = res.data
  381. }
  382. }).catch(function(e) {
  383. console.log('获取沙盘数据失败', e)
  384. })
  385. },
  386. loadHealthReport: function() {
  387. var self = this
  388. healthRequest('/api/health/report/latest', { childId: this.activeChildId }).then(function(res) {
  389. if (res.data) {
  390. self.latestReport = res.data
  391. }
  392. }).catch(function(e) {
  393. console.log('获取健康报告失败', e)
  394. })
  395. },
  396. loadEnergyData: function() {
  397. var self = this
  398. getEnergyOverview(this.activeChildId).then(function(res) {
  399. if (res && res.data) {
  400. var dims = res.data.dimensions
  401. if (dims && dims.length > 0) {
  402. for (var i = 0; i < dims.length; i++) {
  403. if (dims[i].code === 'body') {
  404. self.dualDimension = dims[i]
  405. break
  406. }
  407. }
  408. }
  409. }
  410. }).catch(function(e) {
  411. console.log('获取能量概览失败', e)
  412. })
  413. },
  414. loadDimensionTasks: function() {
  415. var self = this
  416. if (!this.activeChildId) return
  417. getTodayTasksByCategory(this.activeChildId, 'body').then(function(res) {
  418. if (res && res.data) {
  419. self.dimensionTasks = Array.isArray(res.data) ? res.data.slice(0, 5) : []
  420. }
  421. }).catch(function() { self.dimensionTasks = [] })
  422. },
  423. loadDimensionActivities: function() {
  424. var self = this
  425. getActivityList({ dimensionCode: 'body', page: 1, size: 3 }).then(function(res) {
  426. if (res && res.data) {
  427. var list = Array.isArray(res.data) ? res.data : (res.data.records || [])
  428. self.dimensionActivities = list.slice(0, 3)
  429. }
  430. }).catch(function() { self.dimensionActivities = [] })
  431. },
  432. loadDimensionProducts: function() {
  433. var self = this
  434. getProductsByDomain('body', 1, 4).then(function(res) {
  435. if (res && res.data) {
  436. var list = Array.isArray(res.data) ? res.data : (res.data.records || [])
  437. self.dimensionProducts = list.slice(0, 4)
  438. }
  439. }).catch(function() { self.dimensionProducts = [] })
  440. },
  441. loadFeaturedArticles: function() {
  442. var self = this
  443. getFeaturedArticles({ size: 5 }).then(function(res) {
  444. if (res.code === 200 && res.data) {
  445. var gradientColors = [
  446. 'linear-gradient(135deg, #FF8C42, #FFB074)',
  447. 'linear-gradient(135deg, #FF6B9D, #FF9DBD)',
  448. 'linear-gradient(135deg, #6366F1, #818CF8)',
  449. 'linear-gradient(135deg, #10B981, #34D399)',
  450. 'linear-gradient(135deg, #F59E0B, #FBBF24)'
  451. ]
  452. var list = Array.isArray(res.data) ? res.data : (res.data.records || [])
  453. self.bodyArticles = list.map(function(item, index) {
  454. return {
  455. id: item.id,
  456. category: item.categoryName || '身体健康',
  457. categoryColor: gradientColors[index % gradientColors.length],
  458. title: item.title || '',
  459. summary: item.summary || '',
  460. dimensionWeights: item.dimensionWeights || null,
  461. views: item.viewCount ? String(item.viewCount) : '0',
  462. date: item.publishedAt ? item.publishedAt.slice(0, 10) : ''
  463. }
  464. })
  465. }
  466. }.bind(this)).catch(function() {})
  467. },
  468. onChildChanged: function(child) {
  469. this.activeChildId = child.childId
  470. this.activeChildName = child.name || child.nickname || '孩子'
  471. // FIX: 同步提交到 Vuex store,确保 currentView 和 currentChildId 一致
  472. this.$store.commit('switchToChild', child.childId)
  473. this.loadDashboardData()
  474. },
  475. loadFamilyMembersVisible: function() {
  476. var self = this
  477. getVisibleFamilyMembers().then(function(res) {
  478. self.familyMembersVisible = res.data || []
  479. }).catch(function(e) {
  480. console.log('获取可见家庭成员失败', e)
  481. self.familyMembersVisible = []
  482. })
  483. },
  484. scrollToSection: function(section) {
  485. uni.pageScrollTo({ selector: '#' + section, duration: 300 })
  486. },
  487. onTaskClick: function(task) {
  488. uni.navigateTo({ url: '/pages/tasks/tasks' })
  489. },
  490. goActivityDetail: function(act) {
  491. if (!act || !act.id) return
  492. uni.navigateTo({ url: '/pages/discover-detail/activity-detail/activity-detail?id=' + act.id })
  493. },
  494. goMoreActivities: function() {
  495. uni.navigateTo({ url: '/pages/activity/index' })
  496. },
  497. goProductDetail: function(prod) {
  498. uni.navigateTo({ url: '/pages/discover-detail/product-detail/product-detail?id=' + prod.id })
  499. },
  500. goMoreProducts: function() {
  501. uni.navigateTo({ url: '/pages/shop/index' })
  502. },
  503. goArticleDetail: function(article) {
  504. var id = article.id || article
  505. uni.navigateTo({ url: '/pages/mind-detail/article-detail?id=' + id })
  506. },
  507. goMoreArticles: function() {
  508. uni.navigateTo({ url: '/pages/article-center/index?dimension=body' })
  509. },
  510. goTasks: function() { uni.switchTab({ url: '/pages/tasks/tasks' }) },
  511. goMemberDetail: function(member) {
  512. if (!member || !member.memberId) return
  513. uni.navigateTo({
  514. url: '/pages/member-detail/member-detail?memberId=' + member.memberId + '&memberType=' + (member.memberType || 'child') + '&entrySource=relation-graph&dimensionCode=body'
  515. })
  516. },
  517. goFamilyMembers: function() {
  518. uni.navigateTo({ url: '/pages/profile-extra/family-members' })
  519. },
  520. sectionVisible: function(key) {
  521. return this.visibleSections.length === 0 || this.visibleSections.indexOf(key) !== -1
  522. },
  523. onFuncClick: function(item) {
  524. if (item.needLogin && !this.isLoggedIn) {
  525. uni.showModal({
  526. title: '提示',
  527. content: '请先登录后使用此功能',
  528. success: function(res) {
  529. if (res.confirm) uni.navigateTo({ url: '/pages/login/login' })
  530. }
  531. })
  532. return
  533. }
  534. if (item.page === 'health-dimensions') {
  535. if (!this.activeChildId) {
  536. uni.showToast({ title: '请先选择孩子', icon: 'none' })
  537. return
  538. }
  539. uni.navigateTo({ url: '/pages/body-detail/health-dimensions?childId=' + this.activeChildId })
  540. return
  541. }
  542. if (item.page) uni.navigateTo({ url: item.page })
  543. },
  544. goToHealthReport: function() {
  545. var id = this.activeChildId || uni.getStorageSync('currentChildId')
  546. if (!id) {
  547. uni.showToast({ title: '请先选择成员', icon: 'none' })
  548. return
  549. }
  550. uni.navigateTo({ url: '/pages/body-detail/health-report?childId=' + id })
  551. },
  552. goDimensionDetail: function(dimKey) {
  553. uni.navigateTo({ url: '/pages/body/dimension-detail?dimension=' + dimKey + '&childId=' + this.activeChildId })
  554. },
  555. goToCheckin: function() {
  556. var id = this.activeChildId || uni.getStorageSync('currentChildId')
  557. if (!id) {
  558. uni.showToast({ title: '请先选择成员', icon: 'none' })
  559. return
  560. }
  561. uni.navigateTo({ url: '/pages/body-detail/checkin?childId=' + id })
  562. },
  563. goToNutritionProfile: function() {
  564. var id = this.activeChildId || uni.getStorageSync('currentChildId')
  565. if (!id) {
  566. uni.showToast({ title: '请先选择成员', icon: 'none' })
  567. return
  568. }
  569. uni.navigateTo({ url: '/pages/health/nutrition-profile?childId=' + id })
  570. },
  571. goToUploadReport: function() {
  572. var id = this.activeChildId || uni.getStorageSync('currentChildId') || ''
  573. uni.navigateTo({ url: '/pages/health/report-upload?childId=' + id + '&from=body' })
  574. },
  575. formatDate: function(dateStr) {
  576. if (!dateStr) return '--'
  577. try {
  578. var d = new Date(dateStr)
  579. var y = d.getFullYear()
  580. var m = ('' + (d.getMonth() + 1)).padStart(2, '0')
  581. var day = ('' + d.getDate()).padStart(2, '0')
  582. return y + '-' + m + '-' + day
  583. } catch (e) {
  584. return dateStr
  585. }
  586. },
  587. _watchPageReady() {
  588. var self = this
  589. var unwatch = this.$watch(function() {
  590. if (self.isLoggedIn) {
  591. return !!(self.dualDimension || self.sandboxData || (self.dimensionTasks && self.dimensionTasks.length > 0))
  592. }
  593. return !!(self.dimensionActivities && self.dimensionActivities.length > 0) ||
  594. !!(self.dimensionProducts && self.dimensionProducts.length > 0)
  595. }, function(val) {
  596. if (val) {
  597. if (unwatch) unwatch()
  598. self.showTabTransition = false
  599. }
  600. })
  601. setTimeout(function() {
  602. if (unwatch) unwatch()
  603. self.showTabTransition = false
  604. }, 5000)
  605. }
  606. }
  607. }
  608. </script>
  609. <style scoped>
  610. .body-container {
  611. min-height: 100vh;
  612. background: #f5f7fa;
  613. padding-bottom: 120rpx;
  614. }
  615. /* ===== 功能入口 ===== */
  616. .func-section {
  617. margin: 20rpx 30rpx;
  618. }
  619. .func-grid {
  620. display: flex;
  621. flex-direction: row;
  622. justify-content: space-between;
  623. background: #fff;
  624. border-radius: 20rpx;
  625. padding: 24rpx 16rpx;
  626. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  627. }
  628. .func-item {
  629. display: flex;
  630. flex-direction: column;
  631. align-items: center;
  632. flex: 1;
  633. }
  634. .func-icon-wrap {
  635. width: 80rpx;
  636. height: 80rpx;
  637. border-radius: 40rpx;
  638. background: linear-gradient(135deg, #D6EAF8, #EBF2FA);
  639. display: flex;
  640. align-items: center;
  641. justify-content: center;
  642. margin-bottom: 10rpx;
  643. }
  644. .func-icon {
  645. font-size: 40rpx;
  646. }
  647. .func-label {
  648. font-size: 22rpx;
  649. color: #666;
  650. font-weight: 500;
  651. }
  652. /* ===== 通用区块 ===== */
  653. .section {
  654. margin: 20rpx 30rpx;
  655. }
  656. .section-header {
  657. display: flex;
  658. flex-direction: row;
  659. align-items: center;
  660. justify-content: space-between;
  661. margin-bottom: 16rpx;
  662. }
  663. .section-title {
  664. font-size: 30rpx;
  665. font-weight: bold;
  666. color: #333;
  667. }
  668. .avg-badge {
  669. font-size: 20rpx;
  670. color: #F97316;
  671. background: #FFF7ED;
  672. padding: 4rpx 12rpx;
  673. border-radius: 20rpx;
  674. margin-left: 12rpx;
  675. }
  676. .section-more {
  677. font-size: 24rpx;
  678. color: #5B9BD5;
  679. }
  680. /* ===== 健康报告 ===== */
  681. .report-card {
  682. background: #fff;
  683. border-radius: 20rpx;
  684. padding: 24rpx;
  685. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  686. }
  687. .report-type-tag {
  688. display: inline-block;
  689. background: #E8F5E9;
  690. color: #2E7D32;
  691. font-size: 22rpx;
  692. padding: 4rpx 16rpx;
  693. border-radius: 20rpx;
  694. margin-bottom: 16rpx;
  695. }
  696. .report-score-row {
  697. display: flex;
  698. flex-direction: row;
  699. align-items: center;
  700. }
  701. .score-circle {
  702. width: 140rpx;
  703. height: 140rpx;
  704. border-radius: 70rpx;
  705. background: linear-gradient(135deg, #E3F2FD, #BBDEFB);
  706. display: flex;
  707. flex-direction: column;
  708. align-items: center;
  709. justify-content: center;
  710. margin-right: 24rpx;
  711. }
  712. .score-value {
  713. font-size: 48rpx;
  714. font-weight: bold;
  715. color: #1565C0;
  716. }
  717. .score-label {
  718. font-size: 20rpx;
  719. color: #64B5F6;
  720. }
  721. .report-meta {
  722. flex: 1;
  723. }
  724. .meta-item {
  725. display: flex;
  726. flex-direction: row;
  727. align-items: center;
  728. margin-bottom: 12rpx;
  729. }
  730. .meta-label {
  731. font-size: 24rpx;
  732. color: #666;
  733. width: 140rpx;
  734. }
  735. .meta-value {
  736. font-size: 26rpx;
  737. color: #333;
  738. font-weight: 500;
  739. }
  740. .report-date {
  741. font-size: 22rpx;
  742. color: #bbb;
  743. margin-top: 16rpx;
  744. }
  745. .report-empty {
  746. background: #fff;
  747. border-radius: 20rpx;
  748. padding: 40rpx;
  749. text-align: center;
  750. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  751. }
  752. .empty-tip {
  753. font-size: 28rpx;
  754. color: #999;
  755. display: block;
  756. }
  757. .empty-sub {
  758. font-size: 24rpx;
  759. color: #ccc;
  760. display: block;
  761. margin-top: 8rpx;
  762. }
  763. /* ===== 快捷操作 ===== */
  764. .quick-actions {
  765. display: flex;
  766. flex-direction: row;
  767. margin-top: 30rpx;
  768. }
  769. .action-btn {
  770. flex: 1;
  771. background: #fff;
  772. border-radius: 16rpx;
  773. padding: 24rpx;
  774. display: flex;
  775. flex-direction: column;
  776. align-items: center;
  777. margin-right: 20rpx;
  778. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  779. }
  780. .action-btn:last-child {
  781. margin-right: 0;
  782. }
  783. .action-icon {
  784. font-size: 48rpx;
  785. margin-bottom: 8rpx;
  786. }
  787. .action-text {
  788. font-size: 26rpx;
  789. color: #666;
  790. }
  791. /* ===== 底部 ===== */
  792. .bottom-spacer {
  793. height: 120rpx;
  794. }
  795. .func-item:active, .action-btn:active {
  796. opacity: 0.7;
  797. }
  798. /* ===== 精准营养 ===== */
  799. .nutrition-section {
  800. margin-top: 20rpx;
  801. }
  802. .nutrition-report-card {
  803. display: flex;
  804. flex-direction: row;
  805. align-items: center;
  806. background: linear-gradient(135deg, #E8F5E9, #F1F8E9);
  807. border-radius: 20rpx;
  808. padding: 28rpx 24rpx;
  809. margin-bottom: 20rpx;
  810. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  811. }
  812. .nutrition-report-left {
  813. width: 100rpx;
  814. height: 100rpx;
  815. background: rgba(255,255,255,0.7);
  816. border-radius: 20rpx;
  817. display: flex;
  818. align-items: center;
  819. justify-content: center;
  820. margin-right: 20rpx;
  821. flex-shrink: 0;
  822. }
  823. .nutrition-icon-large {
  824. font-size: 52rpx;
  825. }
  826. .nutrition-report-right {
  827. flex: 1;
  828. }
  829. .nutrition-title {
  830. font-size: 30rpx;
  831. font-weight: bold;
  832. color: #2E7D32;
  833. display: block;
  834. margin-bottom: 6rpx;
  835. }
  836. .nutrition-desc {
  837. font-size: 22rpx;
  838. color: #558B2F;
  839. line-height: 1.5;
  840. display: block;
  841. margin-bottom: 10rpx;
  842. }
  843. .nutrition-report-tags {
  844. display: flex;
  845. flex-direction: row;
  846. gap: 10rpx;
  847. }
  848. .nutrition-report-tags .tag {
  849. font-size: 20rpx;
  850. color: #33691E;
  851. background: rgba(255,255,255,0.6);
  852. padding: 4rpx 14rpx;
  853. border-radius: 20rpx;
  854. }
  855. .nutrition-arrow {
  856. font-size: 40rpx;
  857. color: #A5D6A7;
  858. margin-left: 12rpx;
  859. }
  860. .nutrition-links {
  861. margin-bottom: 20rpx;
  862. }
  863. .links-label {
  864. font-size: 26rpx;
  865. font-weight: bold;
  866. color: #333;
  867. display: block;
  868. margin-bottom: 12rpx;
  869. }
  870. .links-row {
  871. display: flex;
  872. flex-direction: row;
  873. gap: 16rpx;
  874. }
  875. .link-item {
  876. flex: 1;
  877. display: flex;
  878. flex-direction: row;
  879. align-items: center;
  880. background: #fff;
  881. border-radius: 16rpx;
  882. padding: 20rpx 18rpx;
  883. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  884. gap: 12rpx;
  885. }
  886. .link-item:active {
  887. opacity: 0.7;
  888. }
  889. .link-icon {
  890. font-size: 36rpx;
  891. flex-shrink: 0;
  892. }
  893. .link-texts {
  894. flex: 1;
  895. }
  896. .link-name {
  897. font-size: 24rpx;
  898. font-weight: 500;
  899. color: #333;
  900. display: block;
  901. margin-bottom: 4rpx;
  902. }
  903. .link-desc {
  904. font-size: 20rpx;
  905. color: #999;
  906. display: block;
  907. }
  908. .link-arrow {
  909. font-size: 32rpx;
  910. color: #CCC;
  911. flex-shrink: 0;
  912. }
  913. /* ===== 推荐阅读 ===== */
  914. .article-list {
  915. display: flex;
  916. flex-direction: column;
  917. gap: 16rpx;
  918. }
  919. .article-card {
  920. background: #fff;
  921. border-radius: 16rpx;
  922. padding: 24rpx;
  923. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  924. }
  925. .article-card:active {
  926. opacity: 0.8;
  927. }
  928. .article-category {
  929. display: inline-block;
  930. padding: 4rpx 14rpx;
  931. border-radius: 8rpx;
  932. margin-bottom: 10rpx;
  933. }
  934. .article-category-text {
  935. font-size: 20rpx;
  936. color: #fff;
  937. }
  938. .article-title {
  939. display: block;
  940. font-size: 28rpx;
  941. font-weight: bold;
  942. color: #333;
  943. margin-bottom: 8rpx;
  944. line-height: 1.4;
  945. }
  946. .article-summary {
  947. display: block;
  948. font-size: 24rpx;
  949. color: #888;
  950. line-height: 1.5;
  951. margin-bottom: 12rpx;
  952. overflow: hidden;
  953. text-overflow: ellipsis;
  954. display: -webkit-box;
  955. -webkit-line-clamp: 2;
  956. -webkit-box-orient: vertical;
  957. }
  958. .article-meta {
  959. display: flex;
  960. align-items: center;
  961. gap: 16rpx;
  962. }
  963. .meta-item {
  964. display: flex;
  965. align-items: center;
  966. gap: 4rpx;
  967. }
  968. .meta-icon {
  969. font-size: 24rpx;
  970. }
  971. .meta-text {
  972. font-size: 22rpx;
  973. color: #999;
  974. }
  975. .article-date {
  976. font-size: 22rpx;
  977. color: #bbb;
  978. }
  979. </style>