Browse Source

feat(food): S-cfc-501 food.frontend.adjustmentDisplay 前端调整展示转绿

CR-08 前端调整展示(recommendation.vue):
- 食材卡扩展展示配伍/加工/病症权重调整原因(buildAdjustmentReasons 归一化)
- 食谱菜卡透传并展示 processingWarning 与配伍避让提示(含删除回写保留)
- 家庭总览沿用 11-10 聚合口径,仅透传 adjustment 标记

红单测 FoodAdjustmentDisplayContractTest:4 失败 2 通过 → 6 通过 0 失败
zxyj-langgraph 1 hour ago
parent
commit
c90bc94b2e
1 changed files with 93 additions and 2 deletions
  1. 93 2
      cfc-frontend/pages/diet/recommendation.vue

+ 93 - 2
cfc-frontend/pages/diet/recommendation.vue

@@ -97,6 +97,10 @@
                 </text>
               </view>
             </view>
+            <!-- CR-08 第3条:家庭总览沿用 11-10 聚合口径,只透传调整标记 adjustment -->
+            <view class="overview-adjustment" v-if="item.adjustment && item.adjustment !== 'normal'">
+              <text class="overview-adjustment-text" :class="'adjust-mark-' + item.adjustment">调整:{{ item.adjustment }}</text>
+            </view>
           </view>
         </view>
 
@@ -140,6 +144,10 @@
             <view class="adjustment-tip" v-if="item.adjustment === 'boost'">
               <text class="adjustment-tip-text adjustment-tip-boost">✓ 符合饮食习惯偏好</text>
             </view>
+            <!-- CR-08 第1条:扩展展示配伍/加工/病症权重原因(如「× 菠菜(草酸×钙拮抗)」「油炸建议改蒸煮」) -->
+            <view class="adjustment-reasons" v-if="item.adjustmentReasons && item.adjustmentReasons.length > 0">
+              <text class="adjustment-reason-text" v-for="(reason, rIdx) in item.adjustmentReasons" :key="rIdx">{{ reason.text }}</text>
+            </view>
           </view>
         </view>
 
@@ -251,6 +259,14 @@
               <view class="dish-method">
                 <text class="method-text">🍳 {{ dish.method }}</text>
               </view>
+              <!-- CR-08 第2条 / CR-07:加工建议 processingWarning(如「油炸降低维生素 C 50%,建议改蒸煮」) -->
+              <view class="dish-processing-warning" v-if="dish.processingWarning">
+                <text class="processing-warning-text">⚠ {{ dish.processingWarning }}</text>
+              </view>
+              <!-- CR-08 第2条 / CR-07 硬闸门:配伍避让提示(替换失败时提示「已避让忌配伍组合」) -->
+              <view class="dish-pairing-hint" v-if="dish.pairingAvoidHint">
+                <text class="pairing-hint-text">🔗 {{ dish.pairingAvoidHint }}</text>
+              </view>
               <!-- D1①:收敛为单一「🗑 删除」;按钮组合由 dishActions 数据位驱动,便于回退 -->
               <view class="dish-actions" v-if="dishActions === 'delete-only' && !shareMode">
                 <view class="action-btn delete-btn"
@@ -628,7 +644,10 @@ export default {
                 type: dish.type || 'dish',
                 calories: dish.calories || (dish.nutrition && dish.nutrition.calories) || 0,
                 ingredients: ing,
-                method: dish.method || dish.cooking_method || ''
+                method: dish.method || dish.cooking_method || '',
+                // CR-08 第2条 / CR-07:加工建议与配伍避让提示透传
+                processingWarning: dish.processingWarning || '',
+                pairingAvoidHint: dish.pairingAvoidHint || dish.pairingWarning || ''
               }
             })
             self.meals.push({
@@ -771,7 +790,10 @@ export default {
             type: d.type || 'dish',
             calories: d.calories || 0,
             ingredients: ings,
-            method: d.method || ''
+            method: d.method || '',
+            // CR-08 第2条:删除菜品时保留加工/配伍提示,避免回写后丢失
+            processingWarning: d.processingWarning || '',
+            pairingAvoidHint: d.pairingAvoidHint || ''
           })
         }
         payloadMeals.push({
@@ -884,6 +906,23 @@ export default {
         }
       })
     },
+    // CR-08 第1条:聚合配伍/加工/病症权重调整原因,供食材卡扩展展示。
+    // 后端可能下发 pairingReason / processingReason / diseaseReason 独立字段,也可能下发 adjustmentReasons 数组;
+    // 此处统一归一化为 [{ type, text }],缺失则不渲染,保持 11-09 基础 adjustmentReason 不变。
+    buildAdjustmentReasons: function(food) {
+      var reasons = []
+      if (!food) return reasons
+      if (food.pairingReason) {
+        reasons.push({ type: 'pairing', text: '配伍原因:' + food.pairingReason })
+      }
+      if (food.processingReason) {
+        reasons.push({ type: 'processing', text: '加工原因:' + food.processingReason })
+      }
+      if (food.diseaseReason) {
+        reasons.push({ type: 'disease', text: '病症权重:' + food.diseaseReason })
+      }
+      return reasons
+    },
     loadFoods: function() {
       var self = this
       var token = uni.getStorageSync('token')
@@ -908,6 +947,8 @@ export default {
               f.scoreClass = self.getScoreClass(f.score)
               f.statusText = self.getStatusText(f.score)
               f.status = f.score >= 0 ? 'suitable' : 'unsuitable'
+              // CR-08 第1条:扩展配伍/加工/病症权重原因
+              f.adjustmentReasons = self.buildAdjustmentReasons(f)
               return f
             })
           }
@@ -951,6 +992,8 @@ export default {
                   statusText: self.getStatusText(score),
                   status: score >= 0 ? 'suitable' : 'unsuitable',
                   aggregateRule: o.aggregateRule || '',
+                  // CR-08 第3条:11-10 聚合口径不变,仅透传调整标记 adjustment
+                  adjustment: o.adjustment || 'normal',
                   minScore: o.minIndexScore,
                   memberCount: o.memberCount || 0,
                   memberScores: (o.memberScores || []).map(function(s) {
@@ -1010,6 +1053,8 @@ export default {
             statusText: self.getStatusText(score),
             status: score >= 0 ? 'suitable' : 'unsuitable',
             aggregateRule: hasNegative ? 'MIN_NEGATIVE' : 'AVG_POSITIVE',
+            // CR-08 第3条:降级路径同样透传调整标记 adjustment
+            adjustment: food.adjustment || 'normal',
             minScore: minScore,
             memberCount: memberScores.length,
             memberScores: memberScores
@@ -1727,6 +1772,52 @@ export default {
   color: $status-success;
 }
 
+/* CR-08 第1条:食材卡配伍/加工/病症权重扩展原因 */
+.adjustment-reasons {
+  margin-top: 8rpx;
+  align-self: flex-start;
+  max-width: 100%;
+}
+.adjustment-reason-text {
+  display: block;
+  font-size: calc(22rpx * var(--font-scale, 1));
+  line-height: 1.5;
+  color: $mat-red;
+}
+
+/* CR-08 第2条:食谱菜卡加工建议 / 配伍避让提示 */
+.dish-processing-warning,
+.dish-pairing-hint {
+  margin-top: 8rpx;
+}
+.processing-warning-text {
+  font-size: calc(22rpx * var(--font-scale, 1));
+  line-height: 1.5;
+  color: $status-warning;
+}
+.pairing-hint-text {
+  font-size: calc(22rpx * var(--font-scale, 1));
+  line-height: 1.5;
+  color: $status-danger;
+}
+
+/* CR-08 第3条:家庭总览调整标记 */
+.overview-adjustment {
+  margin-top: 8rpx;
+}
+.overview-adjustment-text {
+  font-size: calc(22rpx * var(--font-scale, 1));
+}
+.adjust-mark-blocked {
+  color: $status-danger;
+}
+.adjust-mark-warning {
+  color: $status-warning;
+}
+.adjust-mark-boost {
+  color: $status-success;
+}
+
 /* 空状态 */
 .food-empty-state {
   text-align: center;