index.vue 31 KB

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