index.vue 31 KB

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