MicroActionCard.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <view class="micro-action-card" :style="{ '--font-scale': fontScale }">
  3. <view class="mac-header">
  4. <text class="mac-title">☕️ 今天的小行动</text>
  5. <text class="mac-status" v-if="completed">已完成 ✅</text>
  6. <text class="mac-status" v-else>点击完成 +1能量</text>
  7. </view>
  8. <view class="mac-body">
  9. <template v-if="loading">
  10. <view class="mac-loading">
  11. <text class="mac-loading-text">加载中...</text>
  12. </view>
  13. </template>
  14. <template v-else-if="completed">
  15. <view class="mac-done">
  16. <view class="mac-done-icon">✓</view>
  17. <text class="mac-done-text">今日微行动已完成</text>
  18. </view>
  19. <text class="mac-energy">+1 身能量</text>
  20. </template>
  21. <template v-else-if="!action">
  22. <view class="mac-empty">
  23. <text class="mac-empty-text">所有行动已就绪</text>
  24. </view>
  25. </template>
  26. <template v-else>
  27. <view class="mac-action-display">
  28. <text class="mac-action-icon">{{ action.icon }}</text>
  29. <text class="mac-action-name">{{ action.name }}</text>
  30. <text class="mac-action-desc">{{ action.description }}</text>
  31. </view>
  32. <view class="mac-action-btn" @click="doComplete">
  33. <text class="mac-btn-text">完成</text>
  34. </view>
  35. </template>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import api from '@/utils/api.js'
  41. import fontScaleMixin from '@/mixins/font-scale.js'
  42. export default {
  43. mixins: [fontScaleMixin],
  44. props: {
  45. memberId: { type: Number, default: null }
  46. },
  47. data: function() {
  48. return {
  49. action: null,
  50. completed: false,
  51. loading: false
  52. }
  53. },
  54. created: function() {
  55. this.loadTodayAction()
  56. },
  57. methods: {
  58. loadTodayAction: function() {
  59. if (!this.memberId) return
  60. var self = this
  61. this.loading = true
  62. api.microActionToday({ memberId: self.memberId }).then(function(res) {
  63. self.loading = false
  64. if (res.data) {
  65. self.action = res.data.action
  66. self.completed = res.data.completed
  67. }
  68. }).catch(function() {
  69. self.loading = false
  70. self.action = null
  71. })
  72. },
  73. doComplete: function() {
  74. if (!this.memberId) {
  75. uni.showToast({ title: '请先选择家庭成员', icon: 'none' })
  76. return
  77. }
  78. if (!this.action) return
  79. if (this.loading) return
  80. var self = this
  81. this.loading = true
  82. api.microActionComplete({
  83. memberId: self.memberId,
  84. actionId: self.action.id
  85. }).then(function(res) {
  86. self.loading = false
  87. if (res.code === 200) {
  88. self.completed = true
  89. uni.showToast({ title: '太棒了!+1能量', icon: 'none' })
  90. self.$emit('completed')
  91. }
  92. }).catch(function(err) {
  93. self.loading = false
  94. // Error already shown by api.js interceptor
  95. })
  96. }
  97. },
  98. watch: {
  99. memberId: function() {
  100. this.action = null
  101. this.completed = false
  102. this.loadTodayAction()
  103. }
  104. }
  105. }
  106. </script>
  107. <style scoped lang="scss">
  108. .micro-action-card {
  109. background: linear-gradient(135deg, $uni-primary-pale, $facade-brand-tint-2);
  110. border-radius: 24rpx;
  111. padding: 24rpx;
  112. margin: 20rpx 20rpx 0 20rpx;
  113. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  114. border: 1rpx solid $brand-primary-light-2;
  115. }
  116. .mac-header {
  117. display: flex;
  118. justify-content: space-between;
  119. align-items: center;
  120. margin-bottom: 16rpx;
  121. }
  122. .mac-title { font-size: calc(28rpx * var(--font-scale, 1)); font-weight: 700; color: $mat-orange-deep; }
  123. .mac-status { font-size: calc(22rpx * var(--font-scale, 1)); color: $brand-primary-dark; }
  124. .mac-body { display: flex; flex-direction: column; align-items: center; }
  125. .mac-loading { padding: 20rpx 0; }
  126. .mac-loading-text { font-size: calc(24rpx * var(--font-scale, 1)); color: $facade-text-muted; }
  127. .mac-done {
  128. display: flex;
  129. align-items: center;
  130. gap: 12rpx;
  131. padding: 12rpx 0;
  132. }
  133. .mac-done-icon {
  134. width: 48rpx;
  135. height: 48rpx;
  136. border-radius: 24rpx;
  137. background: linear-gradient(135deg, $status-success, $status-success-light-3);
  138. color: $app-surface;
  139. font-size: calc(24rpx * var(--font-scale, 1));
  140. display: flex;
  141. align-items: center;
  142. justify-content: center;
  143. }
  144. .mac-done-text { font-size: calc(28rpx * var(--font-scale, 1)); color: $status-success; font-weight: 600; }
  145. .mac-energy { font-size: calc(22rpx * var(--font-scale, 1)); color: $facade-text-muted; margin-top: 6rpx; }
  146. .mac-empty { padding: 20rpx 0; }
  147. .mac-empty-text { font-size: calc(24rpx * var(--font-scale, 1)); color: $facade-text-muted; }
  148. .mac-action-display {
  149. display: flex;
  150. flex-direction: column;
  151. align-items: center;
  152. padding: 12rpx 0;
  153. gap: 8rpx;
  154. }
  155. .mac-action-icon { font-size: calc($uni-font-size-5xl * var(--font-scale, 1)); }
  156. .mac-action-name { font-size: calc(36rpx * var(--font-scale, 1)); font-weight: 700; color: $facade-text-strong; }
  157. .mac-action-desc { font-size: calc(24rpx * var(--font-scale, 1)); color: $facade-text-faint; text-align: center; }
  158. .mac-action-btn {
  159. background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
  160. color: $app-surface;
  161. font-size: calc(28rpx * var(--font-scale, 1));
  162. font-weight: 600;
  163. padding: 16rpx 80rpx;
  164. border-radius: 24rpx;
  165. margin-top: 16rpx;
  166. }
  167. .mac-action-btn:active { opacity: 0.8; }
  168. .mac-btn-text { color: $app-surface; }
  169. </style>