exercise-index.vue 12 KB

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