index.vue 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088
  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. this.showTabTransition = true
  303. var token = uni.getStorageSync('token')
  304. this.isLoggedIn = !!token
  305. if (this.isLoggedIn) {
  306. this.role = uni.getStorageSync('currentRole') || uni.getStorageSync('role') || null
  307. this.userName = uni.getStorageSync('nickname') || uni.getStorageSync('userName') || '家长'
  308. }
  309. this.loadSectionConfig()
  310. if (this.isLoggedIn) {
  311. this.loadChildren()
  312. this.loadFamilyMembersVisible()
  313. this.loadRelationshipHealth()
  314. }
  315. // 游客也能浏览活动和商品
  316. this.loadDimensionActivities()
  317. this.loadDimensionProducts()
  318. // 游客也能浏览文章
  319. this.loadFeaturedArticles()
  320. this._watchPageReady()
  321. },
  322. methods: {
  323. loadSectionConfig: function() {
  324. var baseSections = ['func_entries']
  325. if (!uni.getStorageSync('token')) {
  326. this.visibleSections = baseSections
  327. return
  328. }
  329. var role = uni.getStorageSync('currentRole') || uni.getStorageSync('role') || null
  330. var self = this
  331. getVisibleSections({ pageKey: 'body', role: role }).then(function(res) {
  332. if (res.code === 200 && res.data) {
  333. var keys = res.data.map(function(s) { return s.sectionKey })
  334. var merged = baseSections.slice()
  335. keys.forEach(function(k) { if (merged.indexOf(k) === -1) merged.push(k) })
  336. self.visibleSections = merged
  337. }
  338. }).catch(function(e) {
  339. self.visibleSections = ['func_entries']
  340. })
  341. },
  342. loadChildren: function() {
  343. var self = this
  344. getChildren().then(function(res) {
  345. if (res.code === 200 && res.data) {
  346. self.children = res.data
  347. var savedChildId = uni.getStorageSync('currentChildId')
  348. var found = false
  349. for (var i = 0; i < self.children.length; i++) {
  350. if (self.children[i].childId === savedChildId) {
  351. self.activeChildId = savedChildId
  352. self.activeChildName = self.children[i].name || self.children[i].nickname || '孩子'
  353. found = true
  354. break
  355. }
  356. }
  357. if (!found && self.children.length > 0) {
  358. self.activeChildId = self.children[0].childId
  359. self.activeChildName = self.children[0].name || self.children[0].nickname || '孩子'
  360. uni.setStorageSync('currentChildId', self.activeChildId)
  361. }
  362. if (self.activeChildId) {
  363. self.loadDashboardData()
  364. }
  365. self.loadContacts()
  366. }
  367. }).catch(function(e) {
  368. console.log('获取孩子列表失败', e)
  369. })
  370. },
  371. loadDashboardData: function() {
  372. if (!this.activeChildId) return
  373. this.loadHealthReport()
  374. this.loadEnergyData()
  375. this.loadDimensionTasks()
  376. this.loadDimensionActivities()
  377. this.loadDimensionProducts()
  378. this.loadSandboxData()
  379. this.loadHealthDimensions()
  380. },
  381. loadHealthDimensions: function() {
  382. var self = this
  383. getDimensionOverview({ memberId: this.activeChildId }).then(function(res) {
  384. if (res && res.data) {
  385. self.dimensionData = res.data
  386. }
  387. }).catch(function(e) {
  388. console.log('获取维度概览失败', e)
  389. })
  390. },
  391. loadSandboxData: function() {
  392. var self = this
  393. getFamilyEnergySandbox().then(function(res) {
  394. if (res && res.data) {
  395. self.sandboxData = res.data
  396. }
  397. }).catch(function(e) {
  398. console.log('获取沙盘数据失败', e)
  399. })
  400. },
  401. loadHealthReport: function() {
  402. var self = this
  403. healthRequest('/api/health/report/latest', { childId: this.activeChildId }).then(function(res) {
  404. if (res.data) {
  405. self.latestReport = res.data
  406. }
  407. }).catch(function(e) {
  408. console.log('获取健康报告失败', e)
  409. })
  410. },
  411. loadEnergyData: function() {
  412. var self = this
  413. getEnergyOverview(this.activeChildId).then(function(res) {
  414. if (res && res.data) {
  415. var dims = res.data.dimensions
  416. if (dims && dims.length > 0) {
  417. for (var i = 0; i < dims.length; i++) {
  418. if (dims[i].code === 'body') {
  419. self.dualDimension = dims[i]
  420. break
  421. }
  422. }
  423. }
  424. }
  425. }).catch(function(e) {
  426. console.log('获取能量概览失败', e)
  427. })
  428. },
  429. loadDimensionTasks: function() {
  430. var self = this
  431. if (!this.activeChildId) return
  432. getTodayTasksByCategory(this.activeChildId, 'body').then(function(res) {
  433. if (res && res.data) {
  434. self.dimensionTasks = Array.isArray(res.data) ? res.data.slice(0, 5) : []
  435. }
  436. }).catch(function() { self.dimensionTasks = [] })
  437. },
  438. loadDimensionActivities: function() {
  439. var self = this
  440. getActivityList({ dimensionCode: 'body', page: 1, size: 3 }).then(function(res) {
  441. if (res && res.data) {
  442. var list = Array.isArray(res.data) ? res.data : (res.data.records || [])
  443. self.dimensionActivities = list.slice(0, 3)
  444. }
  445. }).catch(function() { self.dimensionActivities = [] })
  446. },
  447. loadDimensionProducts: function() {
  448. var self = this
  449. getProductsByDomain('body', 1, 4).then(function(res) {
  450. if (res && res.data) {
  451. var list = Array.isArray(res.data) ? res.data : (res.data.records || [])
  452. self.dimensionProducts = list.slice(0, 4)
  453. }
  454. }).catch(function() { self.dimensionProducts = [] })
  455. },
  456. loadFeaturedArticles: function() {
  457. var self = this
  458. getFeaturedArticles({ size: 5 }).then(function(res) {
  459. if (res.code === 200 && res.data) {
  460. var gradientColors = [
  461. 'linear-gradient(135deg, #FF8C42, #FFB074)',
  462. 'linear-gradient(135deg, #FF6B9D, #FF9DBD)',
  463. 'linear-gradient(135deg, #6366F1, #818CF8)',
  464. 'linear-gradient(135deg, #10B981, #34D399)',
  465. 'linear-gradient(135deg, #F59E0B, #FBBF24)'
  466. ]
  467. var list = Array.isArray(res.data) ? res.data : (res.data.records || [])
  468. self.bodyArticles = list.map(function(item, index) {
  469. return {
  470. id: item.id,
  471. category: item.categoryName || '身体健康',
  472. categoryColor: gradientColors[index % gradientColors.length],
  473. title: item.title || '',
  474. summary: item.summary || '',
  475. views: item.viewCount ? String(item.viewCount) : '0',
  476. date: item.publishedAt ? item.publishedAt.slice(0, 10) : ''
  477. }
  478. })
  479. }
  480. }.bind(this)).catch(function() {})
  481. },
  482. onChildChanged: function(child) {
  483. this.activeChildId = child.childId
  484. this.activeChildName = child.name || child.nickname || '孩子'
  485. this.loadDashboardData()
  486. },
  487. loadFamilyMembersVisible: function() {
  488. var self = this
  489. getVisibleFamilyMembers().then(function(res) {
  490. self.familyMembersVisible = res.data || []
  491. }).catch(function(e) {
  492. console.log('获取可见家庭成员失败', e)
  493. self.familyMembersVisible = []
  494. })
  495. },
  496. scrollToSection: function(section) {
  497. uni.pageScrollTo({ selector: '#' + section, duration: 300 })
  498. },
  499. onTaskClick: function(task) {
  500. uni.navigateTo({ url: '/pages/tasks/tasks' })
  501. },
  502. goActivityDetail: function(act) {
  503. uni.navigateTo({ url: '/pages/discover-detail/activity-detail/activity-detail?id=' + act.id })
  504. },
  505. goMoreActivities: function() {
  506. uni.navigateTo({ url: '/pages/activity/index' })
  507. },
  508. goProductDetail: function(prod) {
  509. uni.navigateTo({ url: '/pages/discover-detail/product-detail/product-detail?id=' + prod.id })
  510. },
  511. goMoreProducts: function() {
  512. uni.navigateTo({ url: '/pages/shop/index' })
  513. },
  514. goArticleDetail: function(article) {
  515. var id = article.id || article
  516. uni.navigateTo({ url: '/pages/mind-detail/article-detail?id=' + id })
  517. },
  518. goMoreArticles: function() {
  519. uni.navigateTo({ url: '/pages/mind-detail/articles' })
  520. },
  521. goTasks: function() { uni.switchTab({ url: '/pages/tasks/tasks' }) },
  522. goMemberDetail: function(member) {
  523. if (!member || !member.memberId) return
  524. uni.navigateTo({
  525. url: '/pages/body-detail/member-body-detail?childId=' + member.memberId
  526. })
  527. },
  528. sectionVisible: function(key) {
  529. return this.visibleSections.length === 0 || this.visibleSections.indexOf(key) !== -1
  530. },
  531. onFuncClick: function(item) {
  532. if (item.needLogin && !this.isLoggedIn) {
  533. uni.showModal({
  534. title: '提示',
  535. content: '请先登录后使用此功能',
  536. success: function(res) {
  537. if (res.confirm) uni.navigateTo({ url: '/pages/login/login' })
  538. }
  539. })
  540. return
  541. }
  542. if (item.page === 'health-dimensions') {
  543. if (!this.activeChildId) {
  544. uni.showToast({ title: '请先选择孩子', icon: 'none' })
  545. return
  546. }
  547. uni.navigateTo({ url: '/pages/body-detail/health-dimensions?childId=' + this.activeChildId })
  548. return
  549. }
  550. if (item.page) uni.navigateTo({ url: item.page })
  551. },
  552. goToHealthReport: function() {
  553. if (!this.activeChildId) {
  554. uni.showToast({ title: '请先选择孩子', icon: 'none' })
  555. return
  556. }
  557. uni.navigateTo({ url: '/pages/body-detail/health-report?childId=' + this.activeChildId })
  558. },
  559. goDimensionDetail: function(dimKey) {
  560. uni.navigateTo({ url: '/pages/body/dimension-detail?dimension=' + dimKey + '&childId=' + this.activeChildId })
  561. },
  562. goToCheckin: function() {
  563. if (!this.activeChildId) {
  564. uni.showToast({ title: '请先选择孩子', icon: 'none' })
  565. return
  566. }
  567. uni.navigateTo({ url: '/pages/body-detail/checkin?childId=' + this.activeChildId })
  568. },
  569. goToNutritionProfile: function() {
  570. if (!this.activeChildId) {
  571. uni.showToast({ title: '请先选择孩子', icon: 'none' })
  572. return
  573. }
  574. uni.navigateTo({ url: '/pages/health/nutrition-profile?childId=' + this.activeChildId })
  575. },
  576. goToUploadReport: function() {
  577. // 使用当前选中孩子;如果 loadChildren 异步未完成则尝试从 storage 读取
  578. var id = this.activeChildId || uni.getStorageSync('currentChildId') || ''
  579. uni.navigateTo({ url: '/pages/health/report-upload?childId=' + id + '&from=body' })
  580. },
  581. // ===== 重要关系 =====
  582. loadContacts: function() {
  583. var self = this
  584. getContactList({}).then(function(res) {
  585. if (res.code === 200 && res.data) {
  586. self.contactList = Array.isArray(res.data) ? res.data : []
  587. }
  588. }).catch(function(e) {
  589. console.log('获取联系人失败', e)
  590. })
  591. },
  592. loadRelationshipHealth: function() {
  593. var self = this
  594. getHealthAlerts({}).then(function(res) {
  595. if (res.code === 200 && res.data) {
  596. self.healthAlerts = Array.isArray(res.data) ? res.data : []
  597. }
  598. }).catch(function() {
  599. self.healthAlerts = []
  600. })
  601. getMilestones({}, 30).then(function(res) {
  602. if (res.code === 200 && res.data) {
  603. self.milestones = Array.isArray(res.data) ? res.data : []
  604. }
  605. }).catch(function() {
  606. self.milestones = []
  607. })
  608. },
  609. onContactClick: function(item) {
  610. uni.navigateTo({ url: '/pages/body-detail/contact-detail?id=' + item.id })
  611. },
  612. onShowImport: function() {
  613. uni.showToast({ title: '导入通讯录', icon: 'none' })
  614. },
  615. goInteractionLog: function(memberId) {
  616. if (memberId) {
  617. uni.navigateTo({ url: '/pages/body-detail/interaction-log?memberId=' + memberId })
  618. } else {
  619. uni.navigateTo({ url: '/pages/body-detail/interaction-log' })
  620. }
  621. },
  622. goRelationshipQuestionnaire: function() {
  623. uni.navigateTo({ url: '/pages/body-detail/relationship-questionnaire' })
  624. },
  625. formatDate: function(dateStr) {
  626. if (!dateStr) return '--'
  627. try {
  628. var d = new Date(dateStr)
  629. var y = d.getFullYear()
  630. var m = ('' + (d.getMonth() + 1)).padStart(2, '0')
  631. var day = ('' + d.getDate()).padStart(2, '0')
  632. return y + '-' + m + '-' + day
  633. } catch (e) {
  634. return dateStr
  635. }
  636. },
  637. _watchPageReady() {
  638. var self = this
  639. var unwatch = this.$watch(function() {
  640. if (self.isLoggedIn) {
  641. return !!(self.dualDimension || self.sandboxData || (self.dimensionTasks && self.dimensionTasks.length > 0))
  642. }
  643. return !!(self.dimensionActivities && self.dimensionActivities.length > 0) ||
  644. !!(self.dimensionProducts && self.dimensionProducts.length > 0)
  645. }, function(val) {
  646. if (val) {
  647. if (unwatch) unwatch()
  648. self.showTabTransition = false
  649. }
  650. })
  651. setTimeout(function() {
  652. if (unwatch) unwatch()
  653. self.showTabTransition = false
  654. }, 5000)
  655. }
  656. }
  657. }
  658. </script>
  659. <style scoped>
  660. .body-container {
  661. min-height: 100vh;
  662. background: #f5f7fa;
  663. padding-bottom: 120rpx;
  664. }
  665. /* ===== 功能入口 ===== */
  666. .func-section {
  667. margin: 20rpx 30rpx;
  668. }
  669. .func-grid {
  670. display: flex;
  671. flex-direction: row;
  672. justify-content: space-between;
  673. background: #fff;
  674. border-radius: 20rpx;
  675. padding: 24rpx 16rpx;
  676. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  677. }
  678. .func-item {
  679. display: flex;
  680. flex-direction: column;
  681. align-items: center;
  682. flex: 1;
  683. }
  684. .func-icon-wrap {
  685. width: 80rpx;
  686. height: 80rpx;
  687. border-radius: 40rpx;
  688. background: linear-gradient(135deg, #D6EAF8, #EBF2FA);
  689. display: flex;
  690. align-items: center;
  691. justify-content: center;
  692. margin-bottom: 10rpx;
  693. }
  694. .func-icon {
  695. font-size: 40rpx;
  696. }
  697. .func-label {
  698. font-size: 22rpx;
  699. color: #666;
  700. font-weight: 500;
  701. }
  702. /* ===== 通用区块 ===== */
  703. .section {
  704. margin: 20rpx 30rpx;
  705. }
  706. .section-header {
  707. display: flex;
  708. flex-direction: row;
  709. align-items: center;
  710. justify-content: space-between;
  711. margin-bottom: 16rpx;
  712. }
  713. .section-title {
  714. font-size: 30rpx;
  715. font-weight: bold;
  716. color: #333;
  717. }
  718. .avg-badge {
  719. font-size: 20rpx;
  720. color: #F97316;
  721. background: #FFF7ED;
  722. padding: 4rpx 12rpx;
  723. border-radius: 20rpx;
  724. margin-left: 12rpx;
  725. }
  726. .section-more {
  727. font-size: 24rpx;
  728. color: #5B9BD5;
  729. }
  730. /* ===== 健康报告 ===== */
  731. .report-card {
  732. background: #fff;
  733. border-radius: 20rpx;
  734. padding: 24rpx;
  735. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  736. }
  737. .report-type-tag {
  738. display: inline-block;
  739. background: #E8F5E9;
  740. color: #2E7D32;
  741. font-size: 22rpx;
  742. padding: 4rpx 16rpx;
  743. border-radius: 20rpx;
  744. margin-bottom: 16rpx;
  745. }
  746. .report-score-row {
  747. display: flex;
  748. flex-direction: row;
  749. align-items: center;
  750. }
  751. .score-circle {
  752. width: 140rpx;
  753. height: 140rpx;
  754. border-radius: 70rpx;
  755. background: linear-gradient(135deg, #E3F2FD, #BBDEFB);
  756. display: flex;
  757. flex-direction: column;
  758. align-items: center;
  759. justify-content: center;
  760. margin-right: 24rpx;
  761. }
  762. .score-value {
  763. font-size: 48rpx;
  764. font-weight: bold;
  765. color: #1565C0;
  766. }
  767. .score-label {
  768. font-size: 20rpx;
  769. color: #64B5F6;
  770. }
  771. .report-meta {
  772. flex: 1;
  773. }
  774. .meta-item {
  775. display: flex;
  776. flex-direction: row;
  777. align-items: center;
  778. margin-bottom: 12rpx;
  779. }
  780. .meta-label {
  781. font-size: 24rpx;
  782. color: #666;
  783. width: 140rpx;
  784. }
  785. .meta-value {
  786. font-size: 26rpx;
  787. color: #333;
  788. font-weight: 500;
  789. }
  790. .report-date {
  791. font-size: 22rpx;
  792. color: #bbb;
  793. margin-top: 16rpx;
  794. }
  795. .report-empty {
  796. background: #fff;
  797. border-radius: 20rpx;
  798. padding: 40rpx;
  799. text-align: center;
  800. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  801. }
  802. .empty-tip {
  803. font-size: 28rpx;
  804. color: #999;
  805. display: block;
  806. }
  807. .empty-sub {
  808. font-size: 24rpx;
  809. color: #ccc;
  810. display: block;
  811. margin-top: 8rpx;
  812. }
  813. /* ===== 健康小贴士 ===== */
  814. .tips-list {
  815. display: flex;
  816. flex-direction: column;
  817. }
  818. .tip-card {
  819. background: #fff;
  820. border-radius: 20rpx;
  821. padding: 24rpx;
  822. margin-bottom: 16rpx;
  823. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  824. }
  825. .tip-title {
  826. font-size: 28rpx;
  827. font-weight: bold;
  828. color: #333;
  829. display: block;
  830. margin-bottom: 10rpx;
  831. }
  832. .tip-summary {
  833. font-size: 24rpx;
  834. color: #888;
  835. line-height: 1.5;
  836. display: block;
  837. }
  838. /* ===== 快捷操作 ===== */
  839. .quick-actions {
  840. display: flex;
  841. flex-direction: row;
  842. margin-top: 30rpx;
  843. }
  844. .action-btn {
  845. flex: 1;
  846. background: #fff;
  847. border-radius: 16rpx;
  848. padding: 24rpx;
  849. display: flex;
  850. flex-direction: column;
  851. align-items: center;
  852. margin-right: 20rpx;
  853. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  854. }
  855. .action-btn:last-child {
  856. margin-right: 0;
  857. }
  858. .action-icon {
  859. font-size: 48rpx;
  860. margin-bottom: 8rpx;
  861. }
  862. .action-text {
  863. font-size: 26rpx;
  864. color: #666;
  865. }
  866. /* ===== 底部 ===== */
  867. .bottom-spacer {
  868. height: 120rpx;
  869. }
  870. .func-item:active, .action-btn:active {
  871. opacity: 0.7;
  872. }
  873. /* ===== 精准营养 ===== */
  874. .nutrition-section {
  875. margin-top: 20rpx;
  876. }
  877. .nutrition-report-card {
  878. display: flex;
  879. flex-direction: row;
  880. align-items: center;
  881. background: linear-gradient(135deg, #E8F5E9, #F1F8E9);
  882. border-radius: 20rpx;
  883. padding: 28rpx 24rpx;
  884. margin-bottom: 20rpx;
  885. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  886. }
  887. .nutrition-report-left {
  888. width: 100rpx;
  889. height: 100rpx;
  890. background: rgba(255,255,255,0.7);
  891. border-radius: 20rpx;
  892. display: flex;
  893. align-items: center;
  894. justify-content: center;
  895. margin-right: 20rpx;
  896. flex-shrink: 0;
  897. }
  898. .nutrition-icon-large {
  899. font-size: 52rpx;
  900. }
  901. .nutrition-report-right {
  902. flex: 1;
  903. }
  904. .nutrition-title {
  905. font-size: 30rpx;
  906. font-weight: bold;
  907. color: #2E7D32;
  908. display: block;
  909. margin-bottom: 6rpx;
  910. }
  911. .nutrition-desc {
  912. font-size: 22rpx;
  913. color: #558B2F;
  914. line-height: 1.5;
  915. display: block;
  916. margin-bottom: 10rpx;
  917. }
  918. .nutrition-report-tags {
  919. display: flex;
  920. flex-direction: row;
  921. gap: 10rpx;
  922. }
  923. .nutrition-report-tags .tag {
  924. font-size: 20rpx;
  925. color: #33691E;
  926. background: rgba(255,255,255,0.6);
  927. padding: 4rpx 14rpx;
  928. border-radius: 20rpx;
  929. }
  930. .nutrition-arrow {
  931. font-size: 40rpx;
  932. color: #A5D6A7;
  933. margin-left: 12rpx;
  934. }
  935. .nutrition-links {
  936. margin-bottom: 20rpx;
  937. }
  938. .links-label {
  939. font-size: 26rpx;
  940. font-weight: bold;
  941. color: #333;
  942. display: block;
  943. margin-bottom: 12rpx;
  944. }
  945. .links-row {
  946. display: flex;
  947. flex-direction: row;
  948. gap: 16rpx;
  949. }
  950. .link-item {
  951. flex: 1;
  952. display: flex;
  953. flex-direction: row;
  954. align-items: center;
  955. background: #fff;
  956. border-radius: 16rpx;
  957. padding: 20rpx 18rpx;
  958. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  959. gap: 12rpx;
  960. }
  961. .link-item:active {
  962. opacity: 0.7;
  963. }
  964. .link-icon {
  965. font-size: 36rpx;
  966. flex-shrink: 0;
  967. }
  968. .link-texts {
  969. flex: 1;
  970. }
  971. .link-name {
  972. font-size: 24rpx;
  973. font-weight: 500;
  974. color: #333;
  975. display: block;
  976. margin-bottom: 4rpx;
  977. }
  978. .link-desc {
  979. font-size: 20rpx;
  980. color: #999;
  981. display: block;
  982. }
  983. .link-arrow {
  984. font-size: 32rpx;
  985. color: #CCC;
  986. flex-shrink: 0;
  987. }
  988. /* ===== 推荐阅读 ===== */
  989. .article-list {
  990. display: flex;
  991. flex-direction: column;
  992. gap: 16rpx;
  993. }
  994. .article-card {
  995. background: #fff;
  996. border-radius: 16rpx;
  997. padding: 24rpx;
  998. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  999. }
  1000. .article-card:active {
  1001. opacity: 0.8;
  1002. }
  1003. .article-category {
  1004. display: inline-block;
  1005. padding: 4rpx 14rpx;
  1006. border-radius: 8rpx;
  1007. margin-bottom: 10rpx;
  1008. }
  1009. .article-category-text {
  1010. font-size: 20rpx;
  1011. color: #fff;
  1012. }
  1013. .article-title {
  1014. display: block;
  1015. font-size: 28rpx;
  1016. font-weight: bold;
  1017. color: #333;
  1018. margin-bottom: 8rpx;
  1019. line-height: 1.4;
  1020. }
  1021. .article-summary {
  1022. display: block;
  1023. font-size: 24rpx;
  1024. color: #888;
  1025. line-height: 1.5;
  1026. margin-bottom: 12rpx;
  1027. overflow: hidden;
  1028. text-overflow: ellipsis;
  1029. display: -webkit-box;
  1030. -webkit-line-clamp: 2;
  1031. -webkit-box-orient: vertical;
  1032. }
  1033. .article-meta {
  1034. display: flex;
  1035. align-items: center;
  1036. gap: 16rpx;
  1037. }
  1038. .meta-item {
  1039. display: flex;
  1040. align-items: center;
  1041. gap: 4rpx;
  1042. }
  1043. .meta-icon {
  1044. font-size: 24rpx;
  1045. }
  1046. .meta-text {
  1047. font-size: 22rpx;
  1048. color: #999;
  1049. }
  1050. .article-date {
  1051. font-size: 22rpx;
  1052. color: #bbb;
  1053. }
  1054. </style>