index.vue 31 KB

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