Pārlūkot izejas kodu

fix(diet): 修复食材数据未显示-响应路径修正为res.data,合并重复API调用

E2E Test Bot 4 nedēļas atpakaļ
vecāks
revīzija
c8ff8b97df
1 mainītis faili ar 14 papildinājumiem un 8 dzēšanām
  1. 14 8
      cfc-frontend/pages/diet/index.vue

+ 14 - 8
cfc-frontend/pages/diet/index.vue

@@ -205,8 +205,8 @@ export default {
     this.loadMealSummary()
   },
   onShow: function() {
+    // onLoad 已加载过,onShow 只刷新食材(共餐配置不重复请求)
     this.loadIngredients()
-    this.loadMealSummary()
   },
   methods: {
     navTo: function(url) {
@@ -216,13 +216,13 @@ export default {
       return 'ing-' + (item.id || index)
     },
     loadIngredients: function() {
-      this.ingredientsLoading = true
       var self = this
+      self.ingredientsLoading = true
       getDietIngredients().then(function(res) {
         self.ingredientsLoading = false
-        if (res && res.ingredients) {
-          self.ingredients = res.ingredients
-          if (res.ingredients.length === 0 && !self.uploadPromptShown) {
+        if (res && res.code === 200 && res.data && res.data.ingredients) {
+          self.ingredients = res.data.ingredients
+          if (self.ingredients.length === 0 && !self.uploadPromptShown) {
             self.uploadPromptShown = true
             uni.showModal({
               title: '暂无推荐食材',
@@ -243,10 +243,14 @@ export default {
     },
     refreshIngredients: function() {
       var self = this
+      self.ingredientsLoading = true
       refreshDietIngredients().then(function(res) {
-        if (res && res.ingredients) {
-          self.ingredients = res.ingredients
+        self.ingredientsLoading = false
+        if (res && res.code === 200 && res.data && res.data.ingredients) {
+          self.ingredients = res.data.ingredients
         }
+      }).catch(function() {
+        self.ingredientsLoading = false
       })
     },
     addIngredient: function(index) {
@@ -301,7 +305,9 @@ export default {
         self.mealSummary.dinner = self.parseMembers(results[2])
       })
     },
-    parseMembers: function(config) {
+    parseMembers: function(result) {
+      if (!result || result.code !== 200 || !result.data) return ''
+      var config = result.data
       if (!config || !config.participantMemberIds) return ''
       try {
         var ids = JSON.parse(config.participantMemberIds)