exercise-index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <template>
  2. <scroll-view class="content" scroll-y :style="{ '--font-scale': fontScale }">
  3. <view class="card">
  4. <view class="card-accent"></view>
  5. <view class="card-body">
  6. <text class="card-title">每日运动建议</text>
  7. <view class="info-list">
  8. <view class="info-item">
  9. <text class="info-age">3-6 岁(学龄前)</text>
  10. <text class="info-desc">每天至少 60 分钟中等强度运动,以游戏和趣味活动为主,如跑步、跳跃、球类游戏。</text>
  11. </view>
  12. <view class="info-item">
  13. <text class="info-age">6-12 岁(学龄期)</text>
  14. <text class="info-desc">每天 60 分钟以上中等强度运动,每周至少 3 次高强度有氧运动,如游泳、骑自行车、跳绳。</text>
  15. </view>
  16. <view class="info-item">
  17. <text class="info-age">12-18 岁(青少年)</text>
  18. <text class="info-desc">每天 60 分钟中高强度运动,每周 3 次力量训练,培养终身运动习惯。</text>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="card">
  24. <view class="card-accent"></view>
  25. <view class="card-body">
  26. <text class="card-title">运动类型推荐</text>
  27. <view class="info-list">
  28. <view class="info-item">
  29. <text class="info-age">🏃 有氧运动</text>
  30. <text class="info-desc">提高心肺功能,增强耐力。推荐:跑步、游泳、骑自行车、跳绳、球类运动。</text>
  31. </view>
  32. <view class="info-item">
  33. <text class="info-age">💪 力量训练</text>
  34. <text class="info-desc">增强肌肉力量和骨骼密度。推荐:俯卧撑、仰卧起坐、深蹲、弹力带训练。</text>
  35. </view>
  36. <view class="info-item">
  37. <text class="info-age">🧘 柔韧性训练</text>
  38. <text class="info-desc">改善身体灵活性,预防运动损伤。推荐:拉伸、瑜伽、舞蹈、体操。</text>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. <view class="card">
  44. <view class="card-accent"></view>
  45. <view class="card-body">
  46. <text class="card-title">运动安全提示</text>
  47. <view class="info-list">
  48. <view class="info-item">
  49. <text class="info-age">做好热身</text>
  50. <text class="info-desc">运动前进行 5-10 分钟动态热身,如慢跑、关节活动,预防肌肉拉伤。</text>
  51. </view>
  52. <view class="info-item">
  53. <text class="info-age">补充水分</text>
  54. <text class="info-desc">运动前中后适量饮水,每 15-20 分钟补充 100-150ml 水,避免脱水。</text>
  55. </view>
  56. <view class="info-item">
  57. <text class="info-age">正确姿势</text>
  58. <text class="info-desc">保持正确运动姿势,避免过度训练。如有不适立即停止,必要时就医。</text>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. <!-- 记录运动表单 -->
  64. <view class="card">
  65. <view class="card-accent"></view>
  66. <view class="card-body">
  67. <text class="card-title">记录运动</text>
  68. <view class="form-group">
  69. <text class="form-label">运动类型 *</text>
  70. <view class="tag-row">
  71. <TagChip v-for="t in exerciseTypes" :key="t.value" :label="t.label" variant="body"
  72. :active="form.exerciseType === t.value"
  73. @select="form.exerciseType = t.value" />
  74. </view>
  75. </view>
  76. <view class="form-group">
  77. <text class="form-label">时长(分钟)*</text>
  78. <input class="form-input" type="number" v-model="form.durationMinutes" placeholder="请输入运动时长" />
  79. </view>
  80. <view class="form-group">
  81. <text class="form-label">强度</text>
  82. <view class="tag-row">
  83. <TagChip v-for="s in intensityOptions" :key="s.value" :label="s.label" variant="body"
  84. :active="form.intensity === s.value"
  85. @select="form.intensity = s.value" />
  86. </view>
  87. </view>
  88. <view class="form-group">
  89. <text class="form-label">消耗卡路里(选填)</text>
  90. <input class="form-input" type="number" v-model="form.caloriesBurned" placeholder="估算消耗的卡路里" />
  91. </view>
  92. <view class="form-group">
  93. <text class="form-label">备注(选填)</text>
  94. <input class="form-input" v-model="form.remark" placeholder="记录运动感受..." />
  95. </view>
  96. <view class="submit-btn" @click="doCheckin">
  97. <text>{{ submitting ? '提交中...' : '提交打卡' }}</text>
  98. </view>
  99. </view>
  100. </view>
  101. <!-- 历史记录 -->
  102. <view class="card">
  103. <view class="card-accent"></view>
  104. <view class="card-body">
  105. <text class="card-title">运动记录</text>
  106. <view class="history-list" v-if="history.length > 0">
  107. <view class="history-item" v-for="item in history" :key="item.id">
  108. <view class="history-left">
  109. <text class="history-type">{{ item.exerciseType }}</text>
  110. <text class="history-duration">{{ item.durationMinutes }}分钟</text>
  111. </view>
  112. <view class="history-right">
  113. <text class="history-date">{{ formatDate(item.createdAt) }}</text>
  114. </view>
  115. </view>
  116. </view>
  117. <view class="empty-state" v-else>
  118. <text>还没有运动记录</text>
  119. </view>
  120. </view>
  121. </view>
  122. </scroll-view>
  123. </template>
  124. <script>
  125. import config from '@/config.js'
  126. import { parseDate } from '@/utils/format.js'
  127. import TagChip from '@/components/TagChip.vue'
  128. import fontScaleMixin from '@/mixins/font-scale.js'
  129. export default {
  130. mixins: [fontScaleMixin],
  131. components: { TagChip },
  132. data() {
  133. return {
  134. memberId: null,
  135. submitting: false,
  136. history: [],
  137. exerciseTypes: [
  138. { label: '跑步', value: 'running' },
  139. { label: '游泳', value: 'swimming' },
  140. { label: '骑行', value: 'cycling' },
  141. { label: '跳绳', value: 'jump_rope' },
  142. { label: '球类', value: 'ball_game' },
  143. { label: '力量训练', value: 'strength' },
  144. { label: '其他', value: 'other' }
  145. ],
  146. intensityOptions: [
  147. { label: '低强度', value: 'low' },
  148. { label: '中等', value: 'medium' },
  149. { label: '高强度', value: 'high' }
  150. ],
  151. form: {
  152. exerciseType: '',
  153. durationMinutes: '',
  154. intensity: 'medium',
  155. caloriesBurned: '',
  156. remark: ''
  157. }
  158. }
  159. },
  160. onLoad: function() {
  161. var role = uni.getStorageSync('currentRole') || uni.getStorageSync('role') || 'parent'
  162. // child 角色:memberId 由后端从 JWT 获取 currentMemberId,前端无需传
  163. if (role !== 'child') {
  164. this.memberId = uni.getStorageSync('currentChildId') || null
  165. }
  166. this.loadHistory()
  167. },
  168. methods: {
  169. goBack: function() {
  170. uni.navigateBack()
  171. },
  172. formatDate: function(dateStr) {
  173. if (!dateStr) return ''
  174. var d = parseDate(dateStr)
  175. if (!d) return dateStr
  176. var m = (d.getMonth() + 1).toString().padStart(2, '0')
  177. var day = d.getDate().toString().padStart(2, '0')
  178. return m + '-' + day
  179. },
  180. loadHistory: function() {
  181. var self = this
  182. var token = uni.getStorageSync('token')
  183. if (!token || !self.memberId) return
  184. uni.request({
  185. url: config.API_BASE_URL + '/api/health/exercise/list',
  186. method: 'POST',
  187. data: { memberId: self.memberId },
  188. header: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token },
  189. success: function(res) {
  190. if (res.data && res.data.code === 200 && res.data.data) {
  191. self.history = res.data.data.slice(0, 10)
  192. }
  193. }
  194. })
  195. },
  196. doCheckin: function() {
  197. var self = this
  198. if (!self.form.exerciseType) {
  199. uni.showToast({ title: '请选择运动类型', icon: 'none' })
  200. return
  201. }
  202. if (!self.form.durationMinutes || parseInt(self.form.durationMinutes) <= 0) {
  203. uni.showToast({ title: '请输入有效时长', icon: 'none' })
  204. return
  205. }
  206. if (!self.memberId) {
  207. uni.showToast({ title: '成员ID无效', icon: 'none' })
  208. return
  209. }
  210. self.submitting = true
  211. var token = uni.getStorageSync('token')
  212. uni.request({
  213. url: config.API_BASE_URL + '/api/health/exercise/create',
  214. method: 'POST',
  215. data: {
  216. memberId: self.memberId,
  217. exerciseType: self.form.exerciseType,
  218. durationMinutes: parseInt(self.form.durationMinutes),
  219. intensity: self.form.intensity,
  220. caloriesBurned: self.form.caloriesBurned ? parseInt(self.form.caloriesBurned) : null,
  221. remark: self.form.remark || ''
  222. },
  223. header: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token },
  224. success: function(res) {
  225. self.submitting = false
  226. if (res.data && res.data.code === 200) {
  227. uni.showToast({ title: '打卡成功', icon: 'success' })
  228. self.form.exerciseType = ''
  229. self.form.durationMinutes = ''
  230. self.form.intensity = 'medium'
  231. self.form.caloriesBurned = ''
  232. self.form.remark = ''
  233. self.loadHistory()
  234. } else {
  235. var msg = (res.data && res.data.message) || '打卡失败'
  236. uni.showToast({ title: msg, icon: 'none' })
  237. }
  238. },
  239. fail: function() {
  240. self.submitting = false
  241. uni.showToast({ title: '网络错误', icon: 'none' })
  242. }
  243. })
  244. }
  245. }
  246. }
  247. </script>
  248. <style scoped lang="scss">
  249. .page {
  250. min-height: 100vh;
  251. background-color: $app-bg;
  252. display: flex;
  253. flex-direction: column;
  254. }
  255. .content {
  256. flex: 1;
  257. padding: $uni-space-page;
  258. }
  259. .card {
  260. display: flex;
  261. background-color: $app-surface;
  262. border-radius: 24rpx;
  263. margin-bottom: $uni-space-lg;
  264. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
  265. overflow: hidden;
  266. }
  267. .card-accent {
  268. width: 8rpx;
  269. background-color: $dim-body;
  270. flex-shrink: 0;
  271. }
  272. .card-body {
  273. flex: 1;
  274. padding: $uni-space-page;
  275. }
  276. .card-title {
  277. font-size: calc(30rpx * var(--font-scale, 1));
  278. font-weight: 600;
  279. color: $facade-text-strong;
  280. margin-bottom: 24rpx;
  281. display: block;
  282. }
  283. .info-list {
  284. display: flex;
  285. flex-direction: column;
  286. gap: 20rpx;
  287. }
  288. .info-item {
  289. display: flex;
  290. flex-direction: column;
  291. gap: 6rpx;
  292. }
  293. .info-age {
  294. font-size: calc(26rpx * var(--font-scale, 1));
  295. font-weight: 500;
  296. color: $dim-body;
  297. display: block;
  298. }
  299. .info-desc {
  300. font-size: calc(24rpx * var(--font-scale, 1));
  301. color: $facade-text-body;
  302. line-height: 1.6;
  303. display: block;
  304. }
  305. .form-group {
  306. margin-bottom: 24rpx;
  307. }
  308. .form-label {
  309. font-size: calc(26rpx * var(--font-scale, 1));
  310. color: $facade-text-strong;
  311. font-weight: 500;
  312. margin-bottom: 12rpx;
  313. display: block;
  314. }
  315. .form-input {
  316. border: 1rpx solid $facade-border-soft;
  317. border-radius: 16rpx;
  318. padding: 16rpx 20rpx;
  319. font-size: calc(26rpx * var(--font-scale, 1));
  320. background-color: $facade-fill-ghost;
  321. width: auto;
  322. }
  323. .tag-row {
  324. display: flex;
  325. flex-wrap: wrap;
  326. gap: 16rpx;
  327. }
  328. .submit-btn {
  329. background-color: $dim-body;
  330. color: $app-surface;
  331. text-align: center;
  332. padding: 22rpx 0;
  333. border-radius: 16rpx;
  334. font-size: calc(28rpx * var(--font-scale, 1));
  335. font-weight: 500;
  336. margin-top: 10rpx;
  337. }
  338. .history-list {
  339. display: flex;
  340. flex-direction: column;
  341. gap: 16rpx;
  342. }
  343. .history-item {
  344. display: flex;
  345. justify-content: space-between;
  346. align-items: center;
  347. padding: 16rpx 0;
  348. border-bottom: 1rpx solid $facade-fill;
  349. }
  350. .history-left {
  351. display: flex;
  352. flex-direction: column;
  353. gap: 4rpx;
  354. }
  355. .history-type {
  356. font-size: calc(26rpx * var(--font-scale, 1));
  357. font-weight: 500;
  358. color: $facade-text-strong;
  359. }
  360. .history-duration {
  361. font-size: calc(22rpx * var(--font-scale, 1));
  362. color: $facade-text-muted;
  363. }
  364. .history-right {
  365. text-align: right;
  366. }
  367. .history-date {
  368. font-size: calc(22rpx * var(--font-scale, 1));
  369. color: $facade-text-muted;
  370. }
  371. .empty-state {
  372. text-align: center;
  373. padding: 40rpx 0;
  374. font-size: calc(26rpx * var(--font-scale, 1));
  375. color: $facade-text-muted;
  376. }
  377. </style>