index.vue 30 KB

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