index.vue 31 KB

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