Parcourir la source

fix: ingredient query page - 戒备阈值 <50→<0, 默认正序, 分类点击生效

- 戒备筛选阈值从 f.score < 50 改为 f.score < 0,与后端 getCautionFoods(indexScore < 0) 保持一致
- getScoreClass/getStatusText/buildFamilyOverview 等状态判定全部改为 >= 0 边界
- onLoad 从报告入口进入时默认 sortType='asc',setFilter('unsuitable') 时同步重置 sortType
- 分类 tab key 从英文 (vegetable/fruit/meat/seafood/grain/dairy) 改为中文 (蔬菜/水果/肉禽/水产/谷物/蛋奶),并新增 getCategoryKeywords() 关键词映射覆盖 PDF/ LangGraph 两套数据源分类命名
- 修复分类点击无效问题,确保前端过滤能匹配 DB 中存储的中文分类

closes related category filter bug, aligns with backend semantics
Sisyphus il y a 4 jours
Parent
commit
13868b7e69
1 fichiers modifiés avec 38 ajouts et 18 suppressions
  1. 38 18
      cfc-frontend/pages/diet/food-query.vue

+ 38 - 18
cfc-frontend/pages/diet/food-query.vue

@@ -43,23 +43,23 @@
         <view class="tab-item" :class="{'tab-active': activeCategory === 'all'}" @tap="switchCategory('all')">
           <text>全部</text>
         </view>
-        <view class="tab-item" :class="{'tab-active': activeCategory === 'vegetable'}" @tap="switchCategory('vegetable')">
+        <view class="tab-item" :class="{'tab-active': activeCategory === '蔬菜'}" @tap="switchCategory('蔬菜')">
           <text>蔬菜</text>
         </view>
-        <view class="tab-item" :class="{'tab-active': activeCategory === 'fruit'}" @tap="switchCategory('fruit')">
+        <view class="tab-item" :class="{'tab-active': activeCategory === '水果'}" @tap="switchCategory('水果')">
           <text>水果</text>
         </view>
-        <view class="tab-item" :class="{'tab-active': activeCategory === 'meat'}" @tap="switchCategory('meat')">
+        <view class="tab-item" :class="{'tab-active': activeCategory === '肉禽'}" @tap="switchCategory('肉禽')">
           <text>肉禽</text>
         </view>
-        <view class="tab-item" :class="{'tab-active': activeCategory === 'seafood'}" @tap="switchCategory('seafood')">
+        <view class="tab-item" :class="{'tab-active': activeCategory === '水产'}" @tap="switchCategory('水产')">
           <text>水产</text>
         </view>
-        <view class="tab-item" :class="{'tab-active': activeCategory === 'grain'}" @tap="switchCategory('grain')">
+        <view class="tab-item" :class="{'tab-active': activeCategory === '谷物'}" @tap="switchCategory('谷物')">
           <text>谷物</text>
         </view>
-        <view class="tab-item" :class="{'tab-active': activeCategory === 'dairy'}" @tap="switchCategory('dairy')">
-          <text>乳制品</text>
+        <view class="tab-item" :class="{'tab-active': activeCategory === '蛋奶'}" @tap="switchCategory('蛋奶')">
+          <text>蛋奶</text>
         </view>
       </view>
 
@@ -168,10 +168,15 @@ export default {
         ? self.familyOverview
         : self.allFoods
 
-      // 分类筛选
+      // 分类筛选(食材分类为中文,用关键词集合匹配不同数据源的分类命名)
       if (self.activeCategory !== 'all') {
+        var keywords = self.getCategoryKeywords(self.activeCategory)
         result = result.filter(function(f) {
-          return f.category && f.category.indexOf(self.activeCategory) !== -1
+          if (!f.category) return false
+          for (var ki = 0; ki < keywords.length; ki++) {
+            if (f.category.indexOf(keywords[ki]) !== -1) return true
+          }
+          return false
         })
       }
 
@@ -183,18 +188,18 @@ export default {
         })
       }
 
-      // 适合/戒备筛选
+      // 适合/戒备筛选(戒备 = 推荐指数 < 0)
       if (self.filterType === 'suitable') {
         result = result.filter(function(f) {
-          return f.score >= 50
+          return f.score >= 0
         })
       } else if (self.filterType === 'unsuitable') {
         result = result.filter(function(f) {
-          return f.score < 50
+          return f.score < 0
         })
       }
 
-      // 排序
+      // 排序(戒备模式默认升序,见 setFilter / onLoad 中 sortType 默认值)
       if (self.sortType === 'asc') {
         result = result.slice().sort(function(a, b) {
           return (a.score || 0) - (b.score || 0)
@@ -212,9 +217,10 @@ export default {
     this.reportId = options.reportId ? parseInt(options.reportId) : null
     this.currentMemberId = options.memberId ? parseInt(options.memberId) : null
     
-    // 从报告入口进来时,默认显示戒备模式
+    // 从报告入口进来时,默认显示戒备模式(升序,数值最小的排最前)
     if (this.reportId) {
       this.filterType = 'unsuitable'
+      this.sortType = 'asc'
     }
     
     this.loadMembers()
@@ -269,7 +275,7 @@ export default {
             self.allFoods = res.data.data.map(function(f) {
               f.scoreClass = self.getScoreClass(f.score)
               f.statusText = self.getStatusText(f.score)
-              f.status = f.score >= 50 ? 'suitable' : 'unsuitable'
+              f.status = f.score >= 0 ? 'suitable' : 'unsuitable'
               return f
             })
           }
@@ -336,7 +342,7 @@ export default {
             score: avgScore,
             scoreClass: self.getScoreClass(avgScore),
             statusText: self.getStatusText(avgScore),
-            status: avgScore >= 50 ? 'suitable' : 'unsuitable',
+            status: avgScore >= 0 ? 'suitable' : 'unsuitable',
             memberScores: memberScores
           })
         }
@@ -351,12 +357,12 @@ export default {
     },
     getScoreClass: function(score) {
       if (score === undefined || score === null) return 'neutral'
-      if (score >= 50) return 'good'
+      if (score >= 0) return 'good'
       return 'bad'
     },
     getStatusText: function(score) {
       if (score === undefined || score === null) return '未知'
-      if (score >= 50) return '适合'
+      if (score >= 0) return '适合'
       return '戒备'
     },
     searchFood: function() {
@@ -365,8 +371,22 @@ export default {
     switchCategory: function(category) {
       this.activeCategory = category
     },
+    getCategoryKeywords: function(category) {
+      var map = {
+        '蔬菜': ['蔬菜'],
+        '水果': ['水果'],
+        '肉禽': ['肉类', '肉禽'],
+        '水产': ['水产', '水产品'],
+        '谷物': ['谷物', '主食', '全谷物'],
+        '蛋奶': ['蛋类', '蛋奶', '乳制品']
+      }
+      return map[category] || []
+    },
     setFilter: function(type) {
       this.filterType = type
+      if (type === 'unsuitable') {
+        this.sortType = 'asc'
+      }
     },
     setSort: function(type) {
       this.sortType = type