Kaynağa Gözat

feat(frontend): 自检结果页新增一键加入今日微行动

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
E2E Test Bot 2 ay önce
ebeveyn
işleme
8bcbbd4451
1 değiştirilmiş dosya ile 88 ekleme ve 1 silme
  1. 88 1
      cfc-frontend/pages/family/self-check-result.vue

+ 88 - 1
cfc-frontend/pages/family/self-check-result.vue

@@ -109,6 +109,16 @@
             <text class="scr-advice-action-label">本周行动</text>
             <text class="scr-advice-action-text">{{ adv.action }}</text>
           </view>
+
+          <!-- 一键加入今日微行动(微行动×五维联动) -->
+          <view class="scr-micro-row" v-if="joinedDims[adv.dimension]">
+            <text class="scr-micro-done">✅ 今日微行动已完成,能量已入账</text>
+          </view>
+          <view class="scr-micro-row" v-else>
+            <button class="scr-micro-btn" :loading="joiningDim === adv.dimension" :disabled="joiningDim !== ''" @click="joinMicroAction(adv)">
+              ⚡ 加入今日微行动
+            </button>
+          </view>
         </view>
       </view>
 
@@ -131,6 +141,7 @@
 
 <script>
 import { getSelfCheckLatest, getSelfCheckHistory } from '@/utils/api'
+import { microActionToday, microActionComplete } from '@/utils/api'
 import { parseDate } from '@/utils/format.js'
 
 export default {
@@ -150,7 +161,10 @@ export default {
         healthy: '健康',
         attention: '留意',
         tense: '紧绷'
-      }
+      },
+      // 今日微行动联动状态
+      joiningDim: '',
+      joinedDims: {}
     }
   },
   computed: {
@@ -332,6 +346,51 @@ export default {
         uni.showToast({ title: '暂无历史记录', icon: 'none' })
       })
     },
+    joinMicroAction: function(adv) {
+      var self = this
+      if (!adv || !adv.dimension || this.joiningDim) return
+      var memberId = this.result && this.result.familyMemberId
+      if (!memberId) {
+        uni.showToast({ title: '未找到家庭成员信息', icon: 'none' })
+        return
+      }
+      this.joiningDim = adv.dimension
+      microActionToday({ memberId: memberId, dimensionCode: adv.dimension }).then(function(res) {
+        if (res.code !== 200) {
+          self.joiningDim = ''
+          uni.showToast({ title: (res && res.message) || '获取微行动失败', icon: 'none' })
+          return
+        }
+        var data = res.data || {}
+        if (data.completed) {
+          self.joiningDim = ''
+          self.$set(self.joinedDims, adv.dimension, true)
+          uni.showToast({ title: '今日微行动已完成', icon: 'none' })
+          return
+        }
+        var action = data.action
+        if (!action || !action.id) {
+          self.joiningDim = ''
+          uni.showToast({ title: '今日暂无该维度微行动', icon: 'none' })
+          return
+        }
+        microActionComplete({ memberId: memberId, actionId: action.id }).then(function(res2) {
+          self.joiningDim = ''
+          if (res2.code === 200) {
+            self.$set(self.joinedDims, adv.dimension, true)
+            uni.showToast({ title: '已加入今日微行动,能量+1', icon: 'success' })
+          } else {
+            uni.showToast({ title: (res2 && res2.message) || '加入失败', icon: 'none' })
+          }
+        }).catch(function() {
+          self.joiningDim = ''
+          uni.showToast({ title: '加入失败', icon: 'none' })
+        })
+      }).catch(function() {
+        self.joiningDim = ''
+        uni.showToast({ title: '获取微行动失败', icon: 'none' })
+      })
+    },
     retake: function() {
       uni.redirectTo({ url: '/pages/family/self-check' })
     }
@@ -627,6 +686,34 @@ export default {
   color: #333;
   line-height: 1.5;
 }
+/* 一键加入今日微行动 */
+.scr-micro-row {
+  display: flex;
+  margin-top: 14rpx;
+}
+.scr-micro-btn {
+  flex: 1;
+  height: 72rpx;
+  line-height: 72rpx;
+  font-size: 26rpx;
+  font-weight: 600;
+  color: #fff;
+  background: linear-gradient(135deg, #10B981, #34D399);
+  border-radius: 36rpx;
+  border: none;
+}
+.scr-micro-btn::after {
+  border: none;
+}
+.scr-micro-done {
+  flex: 1;
+  text-align: center;
+  font-size: 24rpx;
+  color: #10B981;
+  background: #E8F8F1;
+  border-radius: 12rpx;
+  padding: 16rpx 0;
+}
 
 /* 全部健康 */
 .scr-all-healthy {