index.vue 29 KB

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