meditation-index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <template>
  2. <view class="page">
  3. <!-- 成员选择 -->
  4. <view class="member-selector-card">
  5. <text class="member-label">记录人</text>
  6. <picker mode="selector" :range="memberOptions" :value="selectedMemberIndex" @change="onMemberChange">
  7. <view class="picker-display">{{ memberOptions[selectedMemberIndex] }}</view>
  8. </picker>
  9. </view>
  10. <scroll-view class="content" scroll-y>
  11. <!-- 记录表单 -->
  12. <view class="card">
  13. <view class="card-accent"></view>
  14. <view class="card-body">
  15. <text class="card-title">记录冥想</text>
  16. <view class="form-item">
  17. <text class="form-label">冥想类型</text>
  18. <view class="type-options">
  19. <view class="type-chip" v-for="t in meditationTypes" :key="t.value"
  20. :class="{ 'type-active': meditationType === t.value }"
  21. @click="meditationType = t.value">{{ t.label }}</view>
  22. </view>
  23. </view>
  24. <view class="form-item">
  25. <text class="form-label">时长(分钟)</text>
  26. <input class="form-input" v-model="duration" type="number" placeholder="输入冥想时长" />
  27. </view>
  28. <view class="form-item">
  29. <text class="form-label">感受备注</text>
  30. <textarea class="form-textarea" v-model="remark" placeholder="记录当下的感受(可选)" maxlength="200" />
  31. </view>
  32. <view class="submit-btn" @click="submitMeditation">保存记录</view>
  33. </view>
  34. </view>
  35. <!-- 历史记录 -->
  36. <view class="card">
  37. <view class="card-accent"></view>
  38. <view class="card-body">
  39. <text class="card-title">历史记录</text>
  40. <view class="history-list">
  41. <view class="history-item" v-for="item in history" :key="item.id">
  42. <text class="history-type">{{ getTypeLabel(item.meditationType) }}</text>
  43. <text class="history-duration">{{ item.durationMinutes }} 分钟</text>
  44. <text class="history-date">{{ item.createdAt ? item.createdAt.substring(0,10) : '' }}</text>
  45. </view>
  46. <view class="history-empty" v-if="history.length === 0"><text>暂无冥想记录</text></view>
  47. </view>
  48. </view>
  49. </view>
  50. </scroll-view>
  51. </view>
  52. </template>
  53. <script>
  54. import config from '@/config.js'
  55. import { getChildren } from '@/utils/api.js'
  56. export default {
  57. data() {
  58. return {
  59. memberId: null,
  60. selectedMemberIndex: 0,
  61. memberOptions: ['我自己'],
  62. memberIds: [],
  63. meditationType: 'breathing',
  64. duration: '',
  65. remark: '',
  66. history: [],
  67. meditationTypes: [
  68. { label: '呼吸觉察', value: 'breathing' },
  69. { label: '身体扫描', value: 'body_scan' },
  70. { label: '慈心冥想', value: 'loving_kindness' },
  71. { label: '行走冥想', value: 'walking' },
  72. { label: '正念观察', value: 'mindful_observing' }
  73. ]
  74. }
  75. },
  76. onLoad: function() {
  77. this.loadChildren()
  78. this.loadHistory()
  79. },
  80. methods: {
  81. loadChildren: function() {
  82. var self = this
  83. getChildren().then(function(res) {
  84. if (res.code === 200 && res.data && res.data.length > 0) {
  85. self.memberIds = res.data.map(function(c) { return c.memberId })
  86. self.memberOptions = ['我自己'].concat(res.data.map(function(c) { return c.name || c.nickname || '成员' }))
  87. }
  88. }).catch(function() {})
  89. },
  90. onMemberChange: function(e) {
  91. this.selectedMemberIndex = parseInt(e.detail.value)
  92. if (this.selectedMemberIndex === 0) {
  93. this.memberId = null
  94. } else {
  95. this.memberId = this.memberIds[this.selectedMemberIndex - 1]
  96. }
  97. this.loadHistory()
  98. },
  99. submitMeditation: function() {
  100. if (!this.duration || parseInt(this.duration) <= 0) {
  101. uni.showToast({ title: '请输入有效时长', icon: 'none' })
  102. return
  103. }
  104. var data = {
  105. meditationType: this.meditationType,
  106. durationMinutes: parseInt(this.duration),
  107. remark: this.remark
  108. }
  109. if (this.memberId) {
  110. data.memberId = this.memberId
  111. data.memberId = this.memberId
  112. }
  113. uni.showLoading({ title: '保存中...' })
  114. healthRequest('/api/health/meditation/create', data).then(function() {
  115. uni.hideLoading()
  116. uni.showToast({ title: '保存成功', icon: 'success' })
  117. this.duration = ''
  118. this.remark = ''
  119. this.loadHistory()
  120. }.bind(this)).catch(function() {
  121. uni.hideLoading()
  122. uni.showToast({ title: '保存失败', icon: 'none' })
  123. })
  124. },
  125. loadHistory: function() {
  126. var self = this
  127. var params = {}
  128. if (this.memberId) params.memberId = this.memberId
  129. healthRequest('/api/health/meditation/list', params).then(function(res) {
  130. if (res.data) self.history = res.data
  131. }).catch(function() { self.history = [] })
  132. },
  133. getTypeLabel: function(type) {
  134. var map = { breathing: '呼吸觉察', body_scan: '身体扫描', loving_kindness: '慈心冥想', walking: '行走冥想', mindful_observing: '正念观察' }
  135. return map[type] || type
  136. },
  137. goBack: function() {
  138. uni.navigateBack()
  139. }
  140. }
  141. }
  142. function healthRequest(url, data) {
  143. var token = uni.getStorageSync('token')
  144. return new Promise(function(resolve, reject) {
  145. uni.request({
  146. url: config.API_BASE_URL + url,
  147. method: 'POST',
  148. data: data,
  149. header: { 'Content-Type': 'application/json', 'Authorization': token ? 'Bearer ' + token : '' },
  150. success: function(res) { if (res.data.code === 200) resolve(res.data); else reject(res.data) },
  151. fail: function(err) { reject(err) }
  152. })
  153. })
  154. }
  155. </script>
  156. <style scoped>
  157. .page {
  158. min-height: 100vh;
  159. background-color: #F5F7FA;
  160. display: flex;
  161. flex-direction: column;
  162. }
  163. .content {
  164. flex: 1;
  165. padding: 30rpx;
  166. }
  167. .member-selector-card {
  168. margin: 0 30rpx 20rpx;
  169. background: #fff;
  170. border-radius: 20rpx;
  171. padding: 20rpx 24rpx;
  172. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  173. display: flex;
  174. flex-direction: row;
  175. align-items: center;
  176. justify-content: space-between;
  177. }
  178. .member-label {
  179. font-size: 28rpx;
  180. color: #666;
  181. }
  182. .picker-display {
  183. font-size: 28rpx;
  184. color: #333;
  185. font-weight: 500;
  186. }
  187. .card {
  188. display: flex;
  189. background-color: #FFFFFF;
  190. border-radius: 20rpx;
  191. margin-bottom: 30rpx;
  192. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
  193. overflow: hidden;
  194. }
  195. .card-accent {
  196. width: 8rpx;
  197. background-color: #6366F1;
  198. flex-shrink: 0;
  199. }
  200. .card-body {
  201. flex: 1;
  202. padding: 30rpx;
  203. }
  204. .card-title {
  205. font-size: 30rpx;
  206. font-weight: 600;
  207. color: #333;
  208. margin-bottom: 24rpx;
  209. display: block;
  210. }
  211. .form-item {
  212. margin-bottom: 20rpx;
  213. }
  214. .form-label {
  215. font-size: 26rpx;
  216. color: #666;
  217. display: block;
  218. margin-bottom: 12rpx;
  219. }
  220. .type-options {
  221. display: flex;
  222. flex-direction: row;
  223. flex-wrap: wrap;
  224. }
  225. .type-chip {
  226. padding: 10rpx 24rpx;
  227. border-radius: 24rpx;
  228. font-size: 24rpx;
  229. color: #666;
  230. background: #f0f0f0;
  231. margin-right: 16rpx;
  232. margin-bottom: 12rpx;
  233. }
  234. .type-active {
  235. background: #EDE9FE;
  236. color: #6366F1;
  237. font-weight: 500;
  238. }
  239. .form-input {
  240. width: 100%;
  241. box-sizing: border-box;
  242. height: 80rpx;
  243. padding: 0 24rpx;
  244. border: 2rpx solid #e5e5e5;
  245. border-radius: 12rpx;
  246. font-size: 28rpx;
  247. background: #fafafa;
  248. }
  249. .form-textarea {
  250. width: 100%;
  251. box-sizing: border-box;
  252. height: 160rpx;
  253. padding: 16rpx 24rpx;
  254. border: 2rpx solid #e5e5e5;
  255. border-radius: 12rpx;
  256. font-size: 28rpx;
  257. background: #fafafa;
  258. resize: none;
  259. }
  260. .submit-btn {
  261. background: linear-gradient(135deg, #6366F1, #818CF8);
  262. color: #fff;
  263. font-size: 32rpx;
  264. font-weight: bold;
  265. text-align: center;
  266. padding: 22rpx;
  267. border-radius: 40rpx;
  268. margin-top: 16rpx;
  269. }
  270. .history-list {
  271. display: flex;
  272. flex-direction: column;
  273. }
  274. .history-item {
  275. display: flex;
  276. flex-direction: row;
  277. align-items: center;
  278. padding: 14rpx 0;
  279. border-bottom: 1rpx solid #f5f5f5;
  280. }
  281. .history-type {
  282. font-size: 28rpx;
  283. color: #333;
  284. flex: 1;
  285. }
  286. .history-duration {
  287. font-size: 24rpx;
  288. color: #6366F1;
  289. margin-right: 16rpx;
  290. }
  291. .history-date {
  292. font-size: 22rpx;
  293. color: #999;
  294. }
  295. .history-empty {
  296. text-align: center;
  297. padding: 30rpx;
  298. color: #999;
  299. font-size: 26rpx;
  300. }
  301. </style>