diff --git a/msh_single_uniapp/pages/tool/nutrition-knowledge.vue b/msh_single_uniapp/pages/tool/nutrition-knowledge.vue index e7fff13..8e15b43 100644 --- a/msh_single_uniapp/pages/tool/nutrition-knowledge.vue +++ b/msh_single_uniapp/pages/tool/nutrition-knowledge.vue @@ -36,7 +36,7 @@ class="nutrient-card" v-for="(item, index) in nutrientList" :key="index" - @click="goToNutrientDetail(item)" + @click="goToNutrientDetail" data-nutrient-index="{{ index }}" > {{ item.icon }} @@ -65,7 +65,7 @@ class="knowledge-item" v-for="(item, index) in (guideList || [])" :key="item.knowledgeId || item.id || index" - @click="goToDetail(item)" + @click="goToDetail" data-item-id="{{ item.id }}" data-item-kid="{{ item.knowledgeId }}" > @@ -96,7 +96,7 @@ class="knowledge-item" v-for="(item, index) in (articleList || [])" :key="item.knowledgeId || item.id || index" - @click="goToDetail(item)" + @click="goToDetail" data-item-id="{{ item.id }}" data-item-kid="{{ item.knowledgeId }}" > @@ -263,24 +263,24 @@ export default { this.currentTab = tab; await this.loadKnowledgeList(); }, - goToNutrientDetail(item) { + goToNutrientDetail(event) { + const index = event.currentTarget.dataset.nutrientIndex; + const item = this.nutrientList[index]; + if (!item) return; uni.navigateTo({ url: `/pages/tool/nutrient-detail?name=${item.name}` }) }, - goToDetail(item) { - if (!item) { - uni.showToast({ title: '暂无详情', icon: 'none' }); - return; - } - // 确保 knowledgeId 或 id 存在才跳转,否则提示暂无详情 - const id = item.knowledgeId ?? item.id ?? item.knowledge_id; - if (id === undefined || id === null || id === '' || (typeof id === 'number' && isNaN(id))) { - uni.showToast({ title: '暂无详情', icon: 'none' }); + goToDetail(event) { + const id = event.currentTarget.dataset.itemId; + const knowledgeId = event.currentTarget.dataset.itemKid; + const finalId = knowledgeId || id; + if (!finalId) { + uni.showToast({ title: "暂无详情", icon: "none" }); return; } uni.navigateTo({ - url: `/pages/tool/knowledge-detail?id=${id}` + url: `/pages/tool/knowledge-detail?id=${finalId}` }); } }