health-report.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  1. <template>
  2. <view class="report-container">
  3. <!-- 椤堕儴瀵艰埅 -->
  4. <view class="nav-bar">
  5. <text class="nav-back" @click="goBack">鈥?杩斿洖</text>
  6. <text class="nav-title">鍋ュ悍鎶ュ憡璇︽儏</text>
  7. <view class="nav-placeholder"></view>
  8. </view>
  9. <!-- 鎶ュ憡澶撮儴 -->
  10. <view class="report-header" v-if="report">
  11. <view class="report-type-tag">{{ reportTypeLabel }}</view>
  12. <view class="report-scores">
  13. <view class="score-item">
  14. <view class="score-circle-lg">
  15. <text class="score-num">{{ report.overallScore || '--' }}</text>
  16. <text class="score-unit">鍒?/text>
  17. </view>
  18. <text class="score-label">缁煎悎璇勫垎</text>
  19. </view>
  20. <view class="score-item" v-if="report.gutHealthScore">
  21. <view class="score-circle-lg score-circle-green">
  22. <text class="score-num">{{ report.gutHealthScore }}</text>
  23. <text class="score-unit">鍒?/text>
  24. </view>
  25. <text class="score-label">鑲犻亾鍋ュ悍</text>
  26. </view>
  27. </view>
  28. <view class="report-info-row" v-if="report.gutAge || report.gutType">
  29. <text class="info-chip" v-if="report.gutAge">鑲犻亾骞撮緞锛歿{ report.gutAge }}</text>
  30. <text class="info-chip" v-if="report.gutType">鑲犻亾鍒嗗瀷锛歿{ report.gutType }}</text>
  31. </view>
  32. <text class="report-date">鎶ュ憡鏃ユ湡锛歿{ formatDate(report.reportDate) }}</text>
  33. </view>
  34. <!-- ===== 璇勫垎鍙��鍖栭潰鏉?(浠呰弻缇ゆ姤鍛? ===== -->
  35. <view class="score-dashboard" v-if="report && report.reportType === 'gut_flora'">
  36. <view class="main-scores">
  37. <view class="main-score-item" v-for="item in mainScores" :key="item.key">
  38. <view class="score-ring-wrap">
  39. <svg width="140" height="140" viewBox="0 0 120 120">
  40. <circle cx="60" cy="60" r="50" fill="none" stroke="#EEEEEE" stroke-width="8"/>
  41. <circle cx="60" cy="60" r="50" fill="none" v-bind:stroke="item.color" stroke-width="8" v-bind:stroke-dasharray="item.circumference" v-bind:stroke-dashoffset="item.offset" stroke-linecap="round" transform="rotate(-90 60 60)"/>
  42. <text x="60" y="52" text-anchor="middle" font-size="32" font-weight="bold" fill="#333">{{ item.score }}</text>
  43. <text x="60" y="72" text-anchor="middle" font-size="14" fill="#999">鍒?/text>
  44. </svg>
  45. </view>
  46. <text class="main-score-label">{{ item.label }}</text>
  47. </view>
  48. </view>
  49. <view class="flora-score-row" v-if="hasFloraScores">
  50. <view class="flora-score-item" v-for="item in floraScores" :key="item.key">
  51. <view class="flora-score-circle" v-bind:style="{ background: item.color }">
  52. <text class="flora-score-num">{{ item.score }}</text>
  53. </view>
  54. <text class="flora-score-label">{{ item.label }}</text>
  55. </view>
  56. </view>
  57. </view>
  58. <!-- 鎸囨爣鍒楄〃 -->
  59. <view class="section">
  60. <view class="section-title">
  61. <text>鎸囨爣鏄庣粏</text>
  62. <text class="section-sub">鍏?{{ indicators.length }} 椤?/text>
  63. </view>
  64. <!-- 鎸夊垎绫诲垎缁?-->
  65. <view class="category-group" v-for="group in groupedIndicators" :key="group.name">
  66. <view class="category-header">
  67. <text class="category-name">{{ group.name }}</text>
  68. <text class="category-count">{{ group.items.length }}椤?/text>
  69. </view>
  70. <view class="indicator-card" v-for="ind in group.items" :key="ind._idx">
  71. <view class="ind-header">
  72. <text class="ind-name">{{ ind.indicatorName }}</text>
  73. <view class="ind-status" :class="ind._cls">
  74. <text>{{ ind._label }}</text>
  75. </view>
  76. </view>
  77. <view class="ind-body">
  78. <view class="ind-value-wrap">
  79. <text class="ind-value">{{ ind.indicatorValue || '--' }}</text>
  80. <text class="ind-unit">{{ ind.unit || '' }}</text>
  81. </view>
  82. <text class="ind-ref">鍙傝€冨€硷細{{ ind.refRange || '鏆傛棤' }}</text>
  83. </view>
  84. </view>
  85. </view>
  86. <view class="empty-indicators" v-if="indicators.length === 0 && !loading">
  87. <text>鏆傛棤鎸囨爣鏁版嵁</text>
  88. </view>
  89. </view>
  90. <!-- ===== 钀ュ吇缂轰箯鍒嗘瀽 ===== -->
  91. <view class="section" v-if="deficiencyRecords && deficiencyRecords.length > 0">
  92. <view class="section-title">
  93. <text>馃敩 钀ュ吇缂轰箯鍒嗘瀽</text>
  94. <text class="section-sub">{{ deficiencyRecords.length }}椤?/text>
  95. </view>
  96. <view class="deficiency-list">
  97. <view class="deficiency-card" v-for="dr in deficiencyRecords" :key="dr.nutrient">
  98. <view class="deficiency-header">
  99. <text class="deficiency-nutrient">{{ dr.nutrient }}</text>
  100. <view class="deficiency-type-tag" :class="'dtype-' + dr.deficiencyType">
  101. <text>{{ dr.deficiencyTypeLabel }}</text>
  102. </view>
  103. </view>
  104. <view class="deficiency-severity-row">
  105. <view class="severity-bar">
  106. <view class="severity-fill" :style="{ width: (dr.severity * 100) + '%', background: dr.severityColor }"></view>
  107. </view>
  108. <text class="severity-val">{{ dr.severity }}</text>
  109. </view>
  110. <view class="deficiency-meta" v-if="dr.indicatorName">
  111. <text class="meta-label">鍏宠仈鎸囨爣锛?/text>
  112. <text class="meta-value">{{ dr.indicatorName }} ({{ dr.indicatorValue }})</text>
  113. </view>
  114. <view class="deficiency-foods" v-if="dr.foodSuggestions">
  115. <text class="foods-label">鎺ㄨ崘椋熺墿锛?/text>
  116. <text class="foods-value">{{ dr.foodSuggestions }}</text>
  117. </view>
  118. </view>
  119. </view>
  120. </view>
  121. <!-- ===== 椋熸潗鎺ㄨ崘 ===== -->
  122. <view class="section" v-if="foods && foods.length > 0">
  123. <view class="section-title">
  124. <text>馃� 椋熸潗鎺ㄨ崘</text>
  125. <text class="section-sub">鍏?{{ foods.length }} 椤?/text>
  126. </view>
  127. <view class="food-list">
  128. <view class="food-card" v-for="food in foods" :key="food.id">
  129. <view class="food-header">
  130. <text class="food-name">{{ food.name }}</text>
  131. <view class="food-score" :class="food.scoreClass">
  132. <text>{{ food.score || '--' }}</text>
  133. </view>
  134. </view>
  135. <view class="food-meta" v-if="food.category">
  136. <text class="food-category">{{ food.category }}</text>
  137. </view>
  138. <view class="food-nutrition" v-if="food.energyKj || food.protein || food.fat || food.carbs">
  139. <view class="nutrition-item" v-if="food.energyKj">
  140. <text class="n-label">鑳介噺</text>
  141. <text class="n-value">{{ food.energyKj }} kJ</text>
  142. </view>
  143. <view class="nutrition-item" v-if="food.protein">
  144. <text class="n-label">铔嬬櫧璐?/text>
  145. <text class="n-value">{{ food.protein }}g</text>
  146. </view>
  147. <view class="nutrition-item" v-if="food.fat">
  148. <text class="n-label">鑴傝偑</text>
  149. <text class="n-value">{{ food.fat }}g</text>
  150. </view>
  151. <view class="nutrition-item" v-if="food.carbs">
  152. <text class="n-label">纰虫按</text>
  153. <text class="n-value">{{ food.carbs }}g</text>
  154. </view>
  155. </view>
  156. </view>
  157. </view>
  158. </view>
  159. <!-- ===== 浜旂淮闆疯揪鍥?(鑿岀兢鎶ュ憡) ===== -->
  160. <view class="section" v-if="report && report.reportType === 'gut_flora' && radarDimensions.length > 0">
  161. <view class="section-title">
  162. <text>浜旂淮闆疯揪鍥?/text>
  163. </view>
  164. <view class="radar-wrap">
  165. <canvas canvas-id="radarCanvas" id="radarCanvas" class="radar-canvas" @touchstart.prevent></canvas>
  166. </view>
  167. </view>
  168. <!-- 搴曢儴鍗犱綅 -->
  169. <view class="bottom-spacer"></view>
  170. <!-- 钀ュ吇鍒嗘瀽鍏ュ彛鎸夐挳 -->
  171. <view class="nutrition-fab" @click="goNutritionChat" v-if="report">
  172. <text class="fab-icon">馃�</text>
  173. <text class="fab-text">绮惧噯钀ュ吇鍒嗘瀽</text>
  174. </view>
  175. </view>
  176. </template>
  177. <script>
  178. import config from '@/config.js'
  179. import { getDeficiencyAnalysis } from '@/utils/api.js'
  180. const healthRequest = function(url, data) {
  181. var token = uni.getStorageSync('token')
  182. return new Promise(function(resolve, reject) {
  183. uni.request({
  184. url: config.API_BASE_URL + url,
  185. method: 'POST',
  186. data: data,
  187. header: {
  188. 'Content-Type': 'application/json',
  189. 'Authorization': token ? 'Bearer ' + token : ''
  190. },
  191. success: function(res) {
  192. if (res.data.code === 200) {
  193. resolve(res.data)
  194. } else {
  195. reject(res.data)
  196. }
  197. },
  198. fail: function(err) {
  199. reject(err)
  200. }
  201. })
  202. })
  203. }
  204. export default {
  205. data() {
  206. return {
  207. childId: null,
  208. reportId: null,
  209. report: null,
  210. reportDetail: null,
  211. indicators: [],
  212. deficiencyRecords: [],
  213. foods: [],
  214. loading: false
  215. }
  216. },
  217. computed: {
  218. reportTypeLabel: function() {
  219. if (!this.report) return ''
  220. return this.report.reportType === 'gut_flora' ? '鑲犻亾妫€娴嬫姤鍛? : '浣撴�鎶ュ憡'
  221. },
  222. // 棰勮�绠楀垎缁勶紝姣忎釜鎸囨爣闄勫姞 _cls (CSS绫? 鍜?_label (鏄剧ず鏍囩�)
  223. groupedIndicators: function() {
  224. var result = []
  225. var groupMap = {}
  226. var idx = 0
  227. for (var i = 0; i < this.indicators.length; i++) {
  228. var ind = this.indicators[i]
  229. var cat = ind.category || '鍏朵粬'
  230. // Compute status css class
  231. var cls = 'status-normal'
  232. var label = '姝e父'
  233. var status = ind.status || ''
  234. var s = status.toLowerCase()
  235. if (s.indexOf('鍋忛珮') !== -1 || s.indexOf('杩囬珮') !== -1 || s.indexOf('concern') !== -1) {
  236. cls = 'status-warning'
  237. label = '鍋忛珮'
  238. } else if (s.indexOf('鍋忎綆') !== -1 || s.indexOf('杩囦綆') !== -1 || s.indexOf('娉ㄦ剰') !== -1 || s.indexOf('warning') !== -1) {
  239. cls = 'status-warn'
  240. label = '鍋忎綆'
  241. } else if (s.indexOf('姝e父') !== -1 || s.indexOf('normal') !== -1 || s.indexOf('浣庨�闄?) !== -1) {
  242. cls = 'status-normal'
  243. label = '姝e父'
  244. } else if (status) {
  245. label = status
  246. }
  247. ind._cls = cls
  248. ind._label = label
  249. ind._idx = idx
  250. idx++
  251. // Group
  252. if (!groupMap[cat]) {
  253. groupMap[cat] = { name: cat, items: [] }
  254. result.push(groupMap[cat])
  255. }
  256. groupMap[cat].items.push(ind)
  257. }
  258. return result
  259. },
  260. circumference: function() {
  261. return Math.round(2 * Math.PI * 50)
  262. },
  263. mainScores: function() {
  264. if (!this.report) return []
  265. var items = []
  266. var r = this.report
  267. var pairs = [
  268. {key:'overall', label:'缁煎悎璇勫垎', score: r.overallScore, color:'#5B9BD5'},
  269. {key:'gut', label:'鑲犻亾鍋ュ悍', score: r.gutHealthScore, color:'#4CAF50'},
  270. {key:'chronic', label:'鎱㈢梾鎺у埗', score: r.chronicDiseaseScore, color:'#FF9800'},
  271. {key:'nutrition', label:'钀ュ吇鍧囪 ', score: r.nutritionScore, color:'#2196F3'}
  272. ]
  273. var circ = Math.round(2 * Math.PI * 50)
  274. for (var i = 0; i < pairs.length; i++) {
  275. var p = pairs[i]
  276. var s = p.score || 0
  277. items.push({key: p.key, label: p.label, score: s, color: p.color, circumference: circ, offset: Math.round(circ - (s / 100) * circ)})
  278. }
  279. return items
  280. },
  281. hasFloraScores: function() {
  282. if (!this.report) return false
  283. var r = this.report
  284. return (r.balanceScore != null) || (r.diversityScore != null) || (r.beneficialScore != null) || (r.harmfulScore != null) || (r.coreGenusScore != null)
  285. },
  286. floraScores: function() {
  287. if (!this.report) return []
  288. var r = this.report
  289. var items = []
  290. var pairs = [
  291. {key:'balance', label:'鑿岀兢骞宠 ', score: r.balanceScore},
  292. {key:'diversity', label:'鑿岀兢澶氭牱鎬?, score: r.diversityScore},
  293. {key:'beneficial', label:'鏈夌泭鑿?, score: r.beneficialScore},
  294. {key:'harmful', label:'鏈夊�鑿?, score: r.harmfulScore},
  295. {key:'coreGenus', label:'鏍稿績鑿屽睘', score: r.coreGenusScore}
  296. ]
  297. for (var i = 0; i < pairs.length; i++) {
  298. var p = pairs[i]
  299. if (p.score != null) {
  300. var s = p.score
  301. var color = '#4CAF50'
  302. if (s < 30) { color = '#F44336' }
  303. else if (s < 60) { color = '#FFC107' }
  304. items.push({key: p.key, label: p.label, score: s, color: color})
  305. }
  306. }
  307. return items
  308. },
  309. radarDimensions: function() {
  310. if (!this.report) return []
  311. var r = this.report
  312. var dims = []
  313. if (r.overallScore != null) dims.push({ label: '缁煎悎', value: r.overallScore })
  314. if (r.gutHealthScore != null) dims.push({ label: '鑲犻亾', value: r.gutHealthScore })
  315. if (r.nutritionScore != null) dims.push({ label: '钀ュ吇', value: r.nutritionScore })
  316. if (r.chronicDiseaseScore != null) dims.push({ label: '鎱㈢梾', value: r.chronicDiseaseScore })
  317. if (r.gutBalanceScore != null) dims.push({ label: '鑿岀兢骞宠 ', value: r.gutBalanceScore })
  318. return dims
  319. }
  320. },
  321. onLoad: function(options) {
  322. var childId = options.childId
  323. var reportId = options.reportId
  324. this.childId = childId ? parseInt(childId) : null
  325. this.reportId = reportId ? parseInt(reportId) : null
  326. // 濡傛灉娌℃湁浼?childId锛屽皾璇曚粠 storage 璇诲彇锛堝彲鑳芥槸瀹堕暱鑷�繁鐨勶級
  327. if (!this.childId) {
  328. var savedChildId = uni.getStorageSync('currentChildId')
  329. if (savedChildId) this.childId = parseInt(savedChildId)
  330. }
  331. this.loadData()
  332. },
  333. onReady: function() {
  334. if (this.radarDimensions.length >= 3) {
  335. this.drawRadarChart()
  336. }
  337. },
  338. methods: {
  339. loadData: function() {
  340. var self = this
  341. uni.showLoading({ title: '鍔犺浇涓?..' })
  342. // Load report + indicators in parallel
  343. var promises = []
  344. if (this.reportId) {
  345. promises.push(healthRequest('/api/health/report/latest', { childId: this.childId }))
  346. promises.push(healthRequest('/api/health/indicator/list', { reportId: this.reportId }))
  347. } else if (this.childId) {
  348. promises.push(healthRequest('/api/health/report/latest', { childId: this.childId }))
  349. }
  350. Promise.all(promises.map(function(p) {
  351. return p.catch(function(e) { return null })
  352. })).then(function(results) {
  353. uni.hideLoading()
  354. if (results[0] && results[0].data) {
  355. self.report = results[0].data
  356. self.reportId = self.report.id
  357. self.loadDeficiencyRecords()
  358. // Load indicators after getting reportId
  359. if (self.reportId) {
  360. healthRequest('/api/health/indicator/list', { reportId: self.reportId }).then(function(res) {
  361. if (res.data) {
  362. self.indicators = res.data
  363. }
  364. }).catch(function(e) {
  365. console.log('鑾峰彇鎸囨爣澶辫触', e)
  366. })
  367. healthRequest('/api/health/report/detail', { reportId: self.reportId }).then(function(res) {
  368. if (res.data) {
  369. self.reportDetail = res.data
  370. }
  371. }).catch(function(e) {
  372. console.log('鑾峰彇鎶ュ憡璇︽儏澶辫触', e)
  373. })
  374. healthRequest('/api/health/foods', { reportId: self.reportId }).then(function(res) {
  375. if (res.data) {
  376. self.foods = res.data.map(function(f) {
  377. f.scoreClass = self.getFoodScoreClass(f.score)
  378. return f
  379. })
  380. }
  381. }).catch(function(e) {
  382. console.log('鑾峰彇椋熸潗鎺ㄨ崘澶辫触', e)
  383. })
  384. }
  385. }
  386. }).catch(function(e) {
  387. uni.hideLoading()
  388. uni.showToast({ title: '鍔犺浇澶辫触', icon: 'none' })
  389. })
  390. },
  391. goBack: function() {
  392. uni.navigateBack()
  393. },
  394. goNutritionChat: function() {
  395. if (!this.reportId) return
  396. uni.navigateTo({
  397. url: '/pages/ai/chat?mode=nutrition&reportId=' + this.reportId + '&firstMessage=' + encodeURIComponent('璇锋牴鎹�繖浠借弻缇ゆ�娴嬫姤鍛婏紝鍒嗘瀽鎴戝�瀛愮殑钀ュ吇鐘跺喌骞舵彁鍑哄缓璁?)
  398. })
  399. },
  400. loadDeficiencyRecords: function() {
  401. if (!this.childId) return
  402. var self = this
  403. getDeficiencyAnalysis(this.childId).then(function(res) {
  404. if (res.code === 200 && res.data) {
  405. self.deficiencyRecords = res.data.map(function(dr) {
  406. dr.deficiencyTypeLabel = self.getDeficiencyTypeLabel(dr.deficiencyType)
  407. dr.severityColor = self.getSeverityColor(dr.severity)
  408. return dr
  409. })
  410. }
  411. }).catch(function(e) {
  412. console.log('鑾峰彇缂轰箯鍒嗘瀽澶辫触', e)
  413. })
  414. },
  415. getDeficiencyTypeLabel: function(type) {
  416. if (type === 'deficiency') return '缂轰箯'
  417. if (type === 'excess') return '鍋忛珮'
  418. if (type === 'borderline') return '杈圭晫鍊?
  419. return '鏈�垎绫?
  420. },
  421. getSeverityColor: function(severity) {
  422. if (severity >= 0.7) return '#EF4444'
  423. if (severity >= 0.3) return '#F59E0B'
  424. return '#10B981'
  425. },
  426. drawRadarChart: function() {
  427. var dims = this.radarDimensions
  428. if (!dims || dims.length < 3) return
  429. var ctx = uni.createCanvasContext('radarCanvas', this)
  430. var cw = 300
  431. var ch = 300
  432. var cx = cw / 2
  433. var cy = ch / 2
  434. var maxR = 110
  435. var n = dims.length
  436. var angleStep = (2 * Math.PI) / n
  437. for (var level = 1; level <= 5; level++) {
  438. var r = maxR * (level / 5)
  439. ctx.setStrokeStyle('#E5E7EB')
  440. ctx.setLineWidth(1)
  441. ctx.beginPath()
  442. for (var j = 0; j < n; j++) {
  443. var a = j * angleStep - Math.PI / 2
  444. var x = cx + r * Math.cos(a)
  445. var y = cy + r * Math.sin(a)
  446. if (j === 0) ctx.moveTo(x, y)
  447. else ctx.lineTo(x, y)
  448. }
  449. ctx.closePath()
  450. ctx.stroke()
  451. }
  452. for (var k = 0; k < n; k++) {
  453. var a2 = k * angleStep - Math.PI / 2
  454. ctx.beginPath()
  455. ctx.moveTo(cx, cy)
  456. ctx.lineTo(cx + maxR * Math.cos(a2), cy + maxR * Math.sin(a2))
  457. ctx.setStrokeStyle('#E5E7EB')
  458. ctx.setLineWidth(1)
  459. ctx.stroke()
  460. }
  461. ctx.beginPath()
  462. for (var m = 0; m < n; m++) {
  463. var angle = m * angleStep - Math.PI / 2
  464. var val = dims[m].value || 0
  465. var rr = maxR * (val / 100)
  466. var px = cx + rr * Math.cos(angle)
  467. var py = cy + rr * Math.sin(angle)
  468. if (m === 0) ctx.moveTo(px, py)
  469. else ctx.lineTo(px, py)
  470. }
  471. ctx.closePath()
  472. ctx.setFillStyle('rgba(249, 115, 22, 0.2)')
  473. ctx.fill()
  474. ctx.setStrokeStyle('#F97316')
  475. ctx.setLineWidth(2)
  476. ctx.stroke()
  477. for (var q = 0; q < n; q++) {
  478. var angle3 = q * angleStep - Math.PI / 2
  479. var lx = cx + (maxR + 20) * Math.cos(angle3)
  480. var ly = cy + (maxR + 20) * Math.sin(angle3)
  481. ctx.setFontSize(11)
  482. ctx.setFillStyle('#6B7280')
  483. ctx.setTextAlign('center')
  484. ctx.setTextBaseline('middle')
  485. ctx.fillText(dims[q].label + ' ' + (dims[q].value || '--'), lx, ly)
  486. }
  487. ctx.draw()
  488. },
  489. getFoodScoreClass: function(score) {
  490. if (score == null) return 'score-unknown'
  491. if (score >= 80) return 'score-high'
  492. if (score >= 60) return 'score-mid'
  493. return 'score-low'
  494. },
  495. formatDate: function(dateStr) {
  496. if (!dateStr) return '--'
  497. try {
  498. var d = new Date(dateStr)
  499. var y = d.getFullYear()
  500. var m = ('' + (d.getMonth() + 1)).padStart(2, '0')
  501. var day = ('' + d.getDate()).padStart(2, '0')
  502. return y + '-' + m + '-' + day
  503. } catch (e) {
  504. return dateStr
  505. }
  506. }
  507. }
  508. }
  509. </script>
  510. <style scoped>
  511. .report-container {
  512. min-height: 100vh;
  513. background: #f5f7fa;
  514. }
  515. /* ===== 瀵艰埅鏍?===== */
  516. .nav-bar {
  517. position: sticky;
  518. top: 0;
  519. background: #fff;
  520. display: flex;
  521. flex-direction: row;
  522. align-items: center;
  523. justify-content: space-between;
  524. padding: 20rpx 30rpx;
  525. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.06);
  526. z-index: 100;
  527. }
  528. .nav-back {
  529. font-size: 32rpx;
  530. color: #5B9BD5;
  531. }
  532. .nav-title {
  533. font-size: 32rpx;
  534. font-weight: bold;
  535. color: #333;
  536. }
  537. .nav-placeholder {
  538. width: 80rpx;
  539. }
  540. /* ===== 鎶ュ憡澶撮儴 ===== */
  541. .report-header {
  542. background: linear-gradient(135deg, #E3F2FD, #BBDEFB);
  543. margin: 20rpx 30rpx;
  544. border-radius: 20rpx;
  545. padding: 30rpx 24rpx;
  546. }
  547. .report-type-tag {
  548. display: inline-block;
  549. background: #1565C0;
  550. color: #fff;
  551. font-size: 22rpx;
  552. padding: 6rpx 20rpx;
  553. border-radius: 20rpx;
  554. margin-bottom: 20rpx;
  555. }
  556. .report-scores {
  557. display: flex;
  558. flex-direction: row;
  559. margin-bottom: 20rpx;
  560. }
  561. .score-item {
  562. display: flex;
  563. flex-direction: column;
  564. align-items: center;
  565. margin-right: 60rpx;
  566. }
  567. .score-circle-lg {
  568. width: 140rpx;
  569. height: 140rpx;
  570. border-radius: 70rpx;
  571. background: #fff;
  572. display: flex;
  573. flex-direction: column;
  574. align-items: center;
  575. justify-content: center;
  576. margin-bottom: 8rpx;
  577. }
  578. .score-circle-green {
  579. background: #E8F5E9;
  580. }
  581. .score-num {
  582. font-size: 48rpx;
  583. font-weight: bold;
  584. color: #1565C0;
  585. }
  586. .score-circle-green .score-num {
  587. color: #2E7D32;
  588. }
  589. .score-unit {
  590. font-size: 22rpx;
  591. color: #64B5F6;
  592. }
  593. .score-circle-green .score-unit {
  594. color: #81C784;
  595. }
  596. .score-label {
  597. font-size: 24rpx;
  598. color: #666;
  599. }
  600. .report-info-row {
  601. display: flex;
  602. flex-direction: row;
  603. margin-bottom: 16rpx;
  604. }
  605. .info-chip {
  606. background: #fff;
  607. color: #333;
  608. font-size: 24rpx;
  609. padding: 8rpx 20rpx;
  610. border-radius: 20rpx;
  611. margin-right: 16rpx;
  612. }
  613. .report-date {
  614. font-size: 22rpx;
  615. color: #888;
  616. }
  617. /* ===== 鎸囨爣鏄庣粏 ===== */
  618. .section {
  619. margin: 20rpx 30rpx;
  620. }
  621. .section-title {
  622. display: flex;
  623. flex-direction: row;
  624. align-items: baseline;
  625. margin-bottom: 20rpx;
  626. font-size: 30rpx;
  627. font-weight: bold;
  628. color: #333;
  629. }
  630. .section-sub {
  631. font-size: 22rpx;
  632. color: #999;
  633. font-weight: normal;
  634. margin-left: 12rpx;
  635. }
  636. .category-group {
  637. margin-bottom: 30rpx;
  638. }
  639. .category-header {
  640. display: flex;
  641. flex-direction: row;
  642. align-items: center;
  643. justify-content: space-between;
  644. margin-bottom: 12rpx;
  645. }
  646. .category-name {
  647. font-size: 26rpx;
  648. font-weight: bold;
  649. color: #333;
  650. }
  651. .category-count {
  652. font-size: 22rpx;
  653. color: #999;
  654. }
  655. .indicator-card {
  656. background: #fff;
  657. border-radius: 16rpx;
  658. padding: 20rpx;
  659. margin-bottom: 12rpx;
  660. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  661. }
  662. .ind-header {
  663. display: flex;
  664. flex-direction: row;
  665. align-items: center;
  666. justify-content: space-between;
  667. margin-bottom: 12rpx;
  668. }
  669. .ind-name {
  670. font-size: 28rpx;
  671. color: #333;
  672. font-weight: 500;
  673. }
  674. .ind-status {
  675. font-size: 22rpx;
  676. padding: 4rpx 16rpx;
  677. border-radius: 16rpx;
  678. }
  679. .status-normal {
  680. background: #E8F5E9;
  681. color: #2E7D32;
  682. }
  683. .status-warning {
  684. background: #FFF3E0;
  685. color: #E65100;
  686. }
  687. .status-warn {
  688. background: #F3E5F5;
  689. color: #7B1FA2;
  690. }
  691. .ind-body {
  692. display: flex;
  693. flex-direction: row;
  694. align-items: baseline;
  695. justify-content: space-between;
  696. }
  697. .ind-value-wrap {
  698. display: flex;
  699. flex-direction: row;
  700. align-items: baseline;
  701. }
  702. .ind-value {
  703. font-size: 36rpx;
  704. font-weight: bold;
  705. color: #1565C0;
  706. }
  707. .ind-unit {
  708. font-size: 24rpx;
  709. color: #999;
  710. margin-left: 8rpx;
  711. }
  712. .ind-ref {
  713. font-size: 22rpx;
  714. color: #bbb;
  715. }
  716. .empty-indicators {
  717. text-align: center;
  718. padding: 60rpx;
  719. color: #999;
  720. font-size: 28rpx;
  721. }
  722. /* ===== 搴曢儴 ===== */
  723. .bottom-spacer {
  724. height: 130rpx;
  725. }
  726. /* ===== 钀ュ吇鍒嗘瀽鍏ュ彛 FAB ===== */
  727. .nutrition-fab {
  728. position: fixed;
  729. bottom: 40rpx;
  730. left: 50%;
  731. transform: translateX(-50%);
  732. background: linear-gradient(135deg, #43A047, #66BB6A);
  733. color: #fff;
  734. display: flex;
  735. flex-direction: row;
  736. align-items: center;
  737. padding: 20rpx 40rpx;
  738. border-radius: 50rpx;
  739. box-shadow: 0 8rpx 24rpx rgba(67, 160, 71, 0.4);
  740. z-index: 200;
  741. }
  742. .fab-icon {
  743. font-size: 36rpx;
  744. margin-right: 12rpx;
  745. }
  746. .fab-text {
  747. font-size: 30rpx;
  748. font-weight: 600;
  749. }
  750. .score-dashboard {
  751. margin: 20rpx 30rpx;
  752. background: #fff;
  753. border-radius: 20rpx;
  754. padding: 24rpx;
  755. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  756. }
  757. .main-scores {
  758. display: flex;
  759. flex-direction: row;
  760. flex-wrap: wrap;
  761. justify-content: space-around;
  762. }
  763. .main-score-item {
  764. display: flex;
  765. flex-direction: column;
  766. align-items: center;
  767. margin-bottom: 20rpx;
  768. width: 45%;
  769. }
  770. .score-ring-wrap {
  771. margin-bottom: 8rpx;
  772. }
  773. .main-score-label {
  774. font-size: 24rpx;
  775. color: #666;
  776. font-weight: 500;
  777. }
  778. .flora-score-row {
  779. display: flex;
  780. flex-direction: row;
  781. justify-content: space-around;
  782. margin-top: 16rpx;
  783. padding-top: 20rpx;
  784. border-top: 2rpx solid #F0F0F0;
  785. }
  786. .flora-score-item {
  787. display: flex;
  788. flex-direction: column;
  789. align-items: center;
  790. }
  791. .flora-score-circle {
  792. width: 80rpx;
  793. height: 80rpx;
  794. border-radius: 40rpx;
  795. display: flex;
  796. align-items: center;
  797. justify-content: center;
  798. margin-bottom: 8rpx;
  799. }
  800. .flora-score-num {
  801. font-size: 28rpx;
  802. font-weight: bold;
  803. color: #fff;
  804. }
  805. .flora-score-label {
  806. font-size: 20rpx;
  807. color: #888;
  808. }
  809. /* ===== 钀ュ吇缂轰箯鍒嗘瀽 ===== */
  810. .deficiency-list {
  811. display: flex;
  812. flex-direction: column;
  813. }
  814. .deficiency-card {
  815. background: #FAFAFA;
  816. border-radius: 16rpx;
  817. padding: 20rpx;
  818. margin-bottom: 12rpx;
  819. }
  820. .deficiency-header {
  821. display: flex;
  822. flex-direction: row;
  823. align-items: center;
  824. justify-content: space-between;
  825. margin-bottom: 12rpx;
  826. }
  827. .deficiency-nutrient {
  828. font-size: 28rpx;
  829. font-weight: bold;
  830. color: #333;
  831. }
  832. .deficiency-type-tag {
  833. font-size: 22rpx;
  834. padding: 4rpx 16rpx;
  835. border-radius: 16rpx;
  836. background: #FFF3E0;
  837. color: #E65100;
  838. }
  839. .dtype-deficiency {
  840. background: #FEE2E2;
  841. color: #DC2626;
  842. }
  843. .dtype-excess {
  844. background: #FFF3E0;
  845. color: #E65100;
  846. }
  847. .dtype-borderline {
  848. background: #FEF3C7;
  849. color: #D97706;
  850. }
  851. .dtype-unclassified {
  852. background: #F3F4F6;
  853. color: #6B7280;
  854. }
  855. .deficiency-severity-row {
  856. display: flex;
  857. flex-direction: row;
  858. align-items: center;
  859. margin-bottom: 8rpx;
  860. }
  861. .severity-bar {
  862. flex: 1;
  863. height: 12rpx;
  864. background: #F3F4F6;
  865. border-radius: 6rpx;
  866. overflow: hidden;
  867. margin-right: 16rpx;
  868. }
  869. .severity-fill {
  870. height: 100%;
  871. border-radius: 6rpx;
  872. }
  873. .severity-val {
  874. font-size: 24rpx;
  875. color: #9CA3AF;
  876. width: 60rpx;
  877. text-align: right;
  878. }
  879. .deficiency-meta {
  880. font-size: 22rpx;
  881. color: #6B7280;
  882. margin-bottom: 6rpx;
  883. }
  884. .deficiency-foods {
  885. font-size: 22rpx;
  886. color: #374151;
  887. margin-top: 8rpx;
  888. }
  889. .foods-label {
  890. color: #9CA3AF;
  891. }
  892. .foods-value {
  893. color: #2E7D32;
  894. }
  895. /* ===== 闆疯揪鍥?===== */
  896. .radar-wrap {
  897. display: flex;
  898. justify-content: center;
  899. align-items: center;
  900. }
  901. .radar-canvas {
  902. width: 300px;
  903. height: 300px;
  904. margin: 0 auto;
  905. }
  906. /* ===== 椋熸潗鎺ㄨ崘 ===== */
  907. .food-list {
  908. display: flex;
  909. flex-direction: column;
  910. }
  911. .food-card {
  912. background: #fff;
  913. border-radius: 16rpx;
  914. padding: 20rpx;
  915. margin-bottom: 12rpx;
  916. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  917. }
  918. .food-header {
  919. display: flex;
  920. flex-direction: row;
  921. align-items: center;
  922. justify-content: space-between;
  923. margin-bottom: 8rpx;
  924. }
  925. .food-name {
  926. font-size: 28rpx;
  927. font-weight: bold;
  928. color: #333;
  929. }
  930. .food-score {
  931. font-size: 24rpx;
  932. padding: 4rpx 16rpx;
  933. border-radius: 16rpx;
  934. font-weight: 600;
  935. }
  936. .score-high {
  937. background: #DCFCE7;
  938. color: #16A34A;
  939. }
  940. .score-mid {
  941. background: #FEF3C7;
  942. color: #D97706;
  943. }
  944. .score-low {
  945. background: #FEE2E2;
  946. color: #DC2626;
  947. }
  948. .score-unknown {
  949. background: #F3F4F6;
  950. color: #6B7280;
  951. }
  952. .food-meta {
  953. margin-bottom: 8rpx;
  954. }
  955. .food-category {
  956. font-size: 22rpx;
  957. color: #6B7280;
  958. background: #F3F4F6;
  959. padding: 2rpx 12rpx;
  960. border-radius: 12rpx;
  961. }
  962. .food-nutrition {
  963. display: flex;
  964. flex-direction: row;
  965. flex-wrap: wrap;
  966. gap: 16rpx;
  967. margin-top: 8rpx;
  968. }
  969. .nutrition-item {
  970. display: flex;
  971. flex-direction: column;
  972. align-items: center;
  973. min-width: 100rpx;
  974. }
  975. .n-label {
  976. font-size: 20rpx;
  977. color: #9CA3AF;
  978. }
  979. .n-value {
  980. font-size: 24rpx;
  981. color: #374151;
  982. font-weight: 500;
  983. }
  984. </style>