exercise-record.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <view class="exercise-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="exercise-types">
  11. <view class="ex-type-item" v-for="et in exerciseTypes" :key="et.value"
  12. :class="{ 'ex-type-active': selectedType === et.value }"
  13. @click="selectedType = et.value">
  14. <text class="ex-type-icon">{{ et.icon }}</text>
  15. <text class="ex-type-label">{{ et.label }}</text>
  16. </view>
  17. </view>
  18. <view class="input-row">
  19. <text class="input-label">时长(分钟)</text>
  20. <input class="input-field" v-model="duration" type="number" placeholder="输入运动时长" />
  21. </view>
  22. <view class="input-row">
  23. <text class="input-label">强度</text>
  24. <view class="intensity-options">
  25. <text class="intensity-item" v-for="v in ['低','中','高']" :key="v"
  26. :class="{ 'intensity-active': intensity === v }" @click="intensity = v">{{ v }}</text>
  27. </view>
  28. </view>
  29. <view class="input-row">
  30. <text class="input-label">备注</text>
  31. <input class="input-field" v-model="remark" placeholder="可选" />
  32. </view>
  33. <view class="submit-btn" @click="submitExercise">保存记录</view>
  34. </view>
  35. <view class="section-card">
  36. <view class="section-title">今日运动摘要</view>
  37. <view class="today-summary">
  38. <text class="summary-stat">总时长:<text class="stat-value">{{ todayTotalMinutes }} 分钟</text></text>
  39. <text class="summary-stat">消耗:<text class="stat-value">{{ todayCalories }} kcal</text></text>
  40. </view>
  41. </view>
  42. <view class="section-card">
  43. <view class="section-title">历史记录</view>
  44. <view class="history-list">
  45. <view class="history-item" v-for="item in exerciseHistory" :key="item.id">
  46. <text class="history-icon">{{ getTypeIcon(item.exerciseType) }}</text>
  47. <view class="history-info">
  48. <text class="history-name">{{ item.exerciseType }}</text>
  49. <text class="history-meta">{{ item.durationMinutes }}分钟 · {{ item.intensity || '中' }}强度</text>
  50. </view>
  51. <text class="history-time">{{ item.createdAt ? item.createdAt.substring(5,16) : '' }}</text>
  52. </view>
  53. <view class="history-empty" v-if="exerciseHistory.length === 0"><text>暂无记录</text></view>
  54. </view>
  55. </view>
  56. <view class="bottom-spacer"></view>
  57. </view>
  58. </template>
  59. <script>
  60. import config from '@/config.js'
  61. export default {
  62. data() {
  63. return {
  64. childId: null,
  65. selectedType: 'running',
  66. duration: '',
  67. intensity: '中',
  68. remark: '',
  69. exerciseHistory: [],
  70. exerciseTypes: [
  71. { icon: '🏃', label: '跑步', value: 'running' },
  72. { icon: '🚴', label: '骑行', value: 'cycling' },
  73. { icon: '🏊', label: '游泳', value: 'swimming' },
  74. { icon: '🤸', label: '跳绳', value: 'jumping_rope' },
  75. { icon: '⚽', label: '球类', value: 'ball_games' },
  76. { icon: '🧘', label: '拉伸', value: 'stretching' }
  77. ]
  78. }
  79. },
  80. computed: {
  81. todayTotalMinutes: function() { return 0 },
  82. todayCalories: function() { return 0 }
  83. },
  84. onLoad: function(options) {
  85. this.childId = options.childId ? parseInt(options.childId) : null
  86. if (this.childId) this.loadHistory()
  87. },
  88. methods: {
  89. submitExercise: function() {
  90. if (!this.duration || parseInt(this.duration) <= 0) {
  91. uni.showToast({ title: '请输入有效时长', icon: 'none' })
  92. return
  93. }
  94. uni.showLoading({ title: '保存中...' })
  95. healthRequest('/api/health/exercise/create', {
  96. childId: this.childId,
  97. memberId: this.childId,
  98. exerciseType: this.selectedType,
  99. durationMinutes: parseInt(this.duration),
  100. intensity: this.intensity,
  101. remark: this.remark
  102. }).then(function() {
  103. uni.hideLoading()
  104. uni.showToast({ title: '保存成功', icon: 'success' })
  105. this.duration = ''
  106. this.remark = ''
  107. this.loadHistory()
  108. }.bind(this)).catch(function() {
  109. uni.hideLoading()
  110. uni.showToast({ title: '保存失败', icon: 'none' })
  111. })
  112. },
  113. loadHistory: function() {
  114. var self = this
  115. healthRequest('/api/health/exercise/list', { childId: this.childId }).then(function(res) {
  116. if (res.data) self.exerciseHistory = res.data
  117. }).catch(function() {})
  118. },
  119. getTypeIcon: function(type) {
  120. var map = { running: '🏃', cycling: '🚴', swimming: '🏊', jumping_rope: '🤸', ball_games: '⚽', stretching: '🧘' }
  121. return map[type] || '🏃'
  122. },
  123. goBack: function() { uni.navigateBack() }
  124. }
  125. }
  126. function healthRequest(url, data) {
  127. var token = uni.getStorageSync('token')
  128. return new Promise(function(resolve, reject) {
  129. uni.request({
  130. url: config.API_BASE_URL + url,
  131. method: 'POST',
  132. data: data,
  133. header: { 'Content-Type': 'application/json', 'Authorization': token ? 'Bearer ' + token : '' },
  134. success: function(res) { if (res.data.code === 200) resolve(res.data); else reject(res.data) },
  135. fail: function(err) { reject(err) }
  136. })
  137. })
  138. }
  139. </script>
  140. <style scoped>
  141. .exercise-container { min-height: 100vh; background: #f5f7fa; padding-bottom: 60rpx; }
  142. .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; }
  143. .nav-back { font-size: 32rpx; color: #5B9BD5; }
  144. .nav-title { font-size: 32rpx; font-weight: bold; color: #333; }
  145. .nav-placeholder { width: 80rpx; }
  146. .section-card { margin: 20rpx 30rpx; background: #fff; border-radius: 20rpx; padding: 24rpx; box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06); }
  147. .section-title { font-size: 30rpx; font-weight: bold; color: #333; margin-bottom: 20rpx; }
  148. .exercise-types { display: flex; flex-direction: row; flex-wrap: wrap; margin-bottom: 20rpx; }
  149. .ex-type-item { display: flex; flex-direction: column; align-items: center; padding: 16rpx 24rpx; border-radius: 16rpx; background: #f0f0f0; margin: 0 12rpx 12rpx 0; min-width: 100rpx; }
  150. .ex-type-active { background: #E8F5E9; border: 2rpx solid #4CAF50; }
  151. .ex-type-icon { font-size: 36rpx; }
  152. .ex-type-label { font-size: 22rpx; color: #666; margin-top: 6rpx; }
  153. .input-row { display: flex; flex-direction: row; align-items: center; margin-bottom: 16rpx; }
  154. .input-label { font-size: 26rpx; color: #666; width: 140rpx; flex-shrink: 0; }
  155. .input-field { flex: 1; background: #f5f7fa; border-radius: 12rpx; padding: 14rpx 16rpx; font-size: 28rpx; }
  156. .intensity-options { display: flex; flex-direction: row; }
  157. .intensity-item { padding: 8rpx 24rpx; border-radius: 12rpx; background: #f0f0f0; font-size: 26rpx; color: #666; margin-right: 12rpx; }
  158. .intensity-active { background: #FFF3E0; color: #E65100; }
  159. .submit-btn { background: linear-gradient(135deg, #4CAF50, #66BB6A); color: #fff; font-size: 32rpx; font-weight: bold; text-align: center; padding: 22rpx; border-radius: 40rpx; margin-top: 16rpx; }
  160. .today-summary { display: flex; flex-direction: row; justify-content: space-around; }
  161. .summary-stat { font-size: 26rpx; color: #666; }
  162. .stat-value { font-size: 32rpx; color: #4CAF50; font-weight: bold; }
  163. .history-list { display: flex; flex-direction: column; }
  164. .history-item { display: flex; flex-direction: row; align-items: center; padding: 14rpx 0; border-bottom: 1rpx solid #f5f5f5; }
  165. .history-icon { font-size: 32rpx; margin-right: 16rpx; }
  166. .history-info { flex: 1; }
  167. .history-name { font-size: 28rpx; color: #333; }
  168. .history-meta { font-size: 22rpx; color: #999; }
  169. .history-time { font-size: 22rpx; color: #999; }
  170. .history-empty { text-align: center; padding: 30rpx; color: #999; font-size: 26rpx; }
  171. .bottom-spacer { height: 60rpx; }
  172. </style>