growth-curve.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <view class="growth-container">
  3. <view class="nav-bar">
  4. <text class="nav-back" @click="goBack">‹ 返回</text>
  5. <text class="nav-title">生长曲线</text>
  6. <view class="nav-placeholder"></view>
  7. </view>
  8. <view class="section-card">
  9. <view class="section-title">当前数据</view>
  10. <view class="current-stats" v-if="latestRecord">
  11. <view class="stat-box">
  12. <text class="stat-val">{{ latestRecord.heightCm || '--' }}</text>
  13. <text class="stat-unit">cm</text>
  14. <text class="stat-label">身高</text>
  15. </view>
  16. <view class="stat-box">
  17. <text class="stat-val">{{ latestRecord.weightKg || '--' }}</text>
  18. <text class="stat-unit">kg</text>
  19. <text class="stat-label">体重</text>
  20. </view>
  21. <view class="stat-box">
  22. <text class="stat-val">{{ latestRecord.bmi || '--' }}</text>
  23. <text class="stat-unit">BMI</text>
  24. <text class="stat-label">指数</text>
  25. </view>
  26. </view>
  27. <view class="current-stats" v-else>
  28. <view class="stat-box"><text class="stat-val">--</text><text class="stat-label">暂无数据</text></view>
  29. </view>
  30. </view>
  31. <view class="section-card">
  32. <view class="section-title">身高趋势</view>
  33. <view class="chart-placeholder">
  34. <view class="chart-svg">
  35. <view class="chart-line" v-for="(pt, idx) in heightPoints" :key="idx"
  36. :style="{ left: pt.x + '%', bottom: pt.y + '%' }">
  37. <view class="chart-dot"></view>
  38. </view>
  39. <view class="chart-axis-y">
  40. <text class="axis-label" v-for="(l, i) in ['150cm','130cm','110cm','90cm']" :key="i"
  41. :style="{ bottom: (i * 25) + '%' }">{{ l }}</text>
  42. </view>
  43. <view class="chart-no-data" v-if="heightPoints.length < 2">
  44. <text>记录更多数据后将显示生长趋势曲线</text>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. <view class="section-card">
  50. <view class="section-title">体重趋势</view>
  51. <view class="chart-placeholder">
  52. <view class="chart-svg">
  53. <view class="chart-line" v-for="(pt, idx) in weightPoints" :key="idx"
  54. :style="{ left: pt.x + '%', bottom: pt.y + '%' }">
  55. <view class="chart-dot"></view>
  56. </view>
  57. <view class="chart-axis-y">
  58. <text class="axis-label" v-for="(l, i) in ['50kg','40kg','30kg','20kg']" :key="i"
  59. :style="{ bottom: (i * 25) + '%' }">{{ l }}</text>
  60. </view>
  61. <view class="chart-no-data" v-if="weightPoints.length < 2">
  62. <text>记录更多数据后将显示体重趋势曲线</text>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. <view class="section-card">
  68. <view class="section-title">生长记录列表</view>
  69. <view class="record-list">
  70. <view class="record-item" v-for="item in growthRecords" :key="item.id">
  71. <view class="record-date">{{ item.recordDate ? item.recordDate.substring(0,10) : '' }}</view>
  72. <view class="record-data">
  73. <text class="data-item" v-if="item.heightCm">{{ item.heightCm }}cm</text>
  74. <text class="data-item" v-if="item.weightKg">{{ item.weightKg }}kg</text>
  75. <text class="data-item" v-if="item.bmi">BMI {{ item.bmi }}</text>
  76. </view>
  77. </view>
  78. <view class="record-empty" v-if="growthRecords.length === 0"><text>暂无生长记录</text></view>
  79. </view>
  80. </view>
  81. <view class="bottom-spacer"></view>
  82. </view>
  83. </template>
  84. <script>
  85. import config from '@/config.js'
  86. export default {
  87. data() {
  88. return {
  89. childId: null,
  90. growthRecords: [],
  91. latestRecord: null
  92. }
  93. },
  94. computed: {
  95. heightPoints: function() {
  96. return this.calcPoints('heightCm')
  97. },
  98. weightPoints: function() {
  99. return this.calcPoints('weightKg')
  100. }
  101. },
  102. onLoad: function(options) {
  103. this.childId = options.childId ? parseInt(options.childId) : null
  104. if (this.childId) this.loadRecords()
  105. },
  106. methods: {
  107. calcPoints: function(field) {
  108. var records = this.growthRecords.slice().reverse()
  109. var values = records.map(function(r) { return parseFloat(r[field]) }).filter(function(v) { return v && v > 0 })
  110. if (values.length < 2) return []
  111. var min = Math.min.apply(null, values)
  112. var max = Math.max.apply(null, values)
  113. var range = max - min || 1
  114. var spacing = 80 / (values.length - 1)
  115. return values.map(function(v, i) {
  116. return { x: 10 + i * spacing, y: 10 + ((v - min) / range) * 70 }
  117. })
  118. },
  119. loadRecords: function() {
  120. var self = this
  121. healthRequest('/api/health/growth/list', { memberId: this.childId }).then(function(res) {
  122. if (res.data) {
  123. self.growthRecords = res.data
  124. if (res.data.length > 0) self.latestRecord = res.data[0]
  125. }
  126. }).catch(function() {
  127. // Use mock data for demo
  128. self.growthRecords = [
  129. { id: 1, recordDate: '2026-01-15', heightCm: 110.5, weightKg: 18.2, bmi: 14.9 },
  130. { id: 2, recordDate: '2026-02-15', heightCm: 111.2, weightKg: 18.5, bmi: 14.9 },
  131. { id: 3, recordDate: '2026-03-15', heightCm: 112.0, weightKg: 19.0, bmi: 15.1 }
  132. ]
  133. self.latestRecord = self.growthRecords[self.growthRecords.length - 1]
  134. })
  135. },
  136. goBack: function() { uni.navigateBack() }
  137. }
  138. }
  139. function healthRequest(url, data) {
  140. var token = uni.getStorageSync('token')
  141. return new Promise(function(resolve, reject) {
  142. uni.request({
  143. url: config.API_BASE_URL + url,
  144. method: 'POST',
  145. data: data,
  146. header: { 'Content-Type': 'application/json', 'Authorization': token ? 'Bearer ' + token : '' },
  147. success: function(res) { if (res.data.code === 200) resolve(res.data); else reject(res.data) },
  148. fail: function(err) { reject(err) }
  149. })
  150. })
  151. }
  152. </script>
  153. <style scoped>
  154. .growth-container { min-height: 100vh; background: #f5f7fa; padding-bottom: 60rpx; }
  155. .nav-bar { position: sticky; top: 0; background: #fff; display: flex; flex-direction: row; align-items: center; justify-content: space-between; padding: 20rpx 30rpx; box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.06); z-index: 100; }
  156. .nav-back { font-size: 32rpx; color: #5B9BD5; }
  157. .nav-title { font-size: 32rpx; font-weight: bold; color: #333; }
  158. .nav-placeholder { width: 80rpx; }
  159. .section-card { margin: 20rpx 30rpx; background: #fff; border-radius: 20rpx; padding: 24rpx; box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06); }
  160. .section-title { font-size: 30rpx; font-weight: bold; color: #333; margin-bottom: 20rpx; }
  161. .current-stats { display: flex; flex-direction: row; justify-content: space-around; }
  162. .stat-box { display: flex; flex-direction: column; align-items: center; }
  163. .stat-val { font-size: 44rpx; font-weight: bold; color: #FF8C42; }
  164. .stat-unit { font-size: 22rpx; color: #999; }
  165. .stat-label { font-size: 24rpx; color: #666; margin-top: 4rpx; }
  166. .chart-placeholder { background: #FFFBEB; border-radius: 16rpx; padding: 20rpx; min-height: 300rpx; position: relative; }
  167. .chart-svg { width: 100%; height: 300rpx; position: relative; }
  168. .chart-line { position: absolute; width: 20rpx; height: 20rpx; }
  169. .chart-dot { width: 16rpx; height: 16rpx; background: #FF8C42; border-radius: 50%; }
  170. .chart-axis-y { position: absolute; left: 0; top: 0; bottom: 30rpx; width: 80rpx; }
  171. .axis-label { position: absolute; font-size: 18rpx; color: #999; }
  172. .chart-no-data { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 24rpx; color: #ccc; text-align: center; }
  173. .record-list { display: flex; flex-direction: column; }
  174. .record-item { display: flex; flex-direction: row; align-items: center; padding: 14rpx 0; border-bottom: 1rpx solid #f5f5f5; }
  175. .record-date { font-size: 24rpx; color: #999; width: 160rpx; flex-shrink: 0; }
  176. .record-data { display: flex; flex-direction: row; flex-wrap: wrap; flex: 1; }
  177. .data-item { font-size: 26rpx; color: #333; margin-right: 16rpx; }
  178. .record-empty { text-align: center; padding: 30rpx; color: #999; font-size: 26rpx; }
  179. .bottom-spacer { height: 60rpx; }
  180. </style>