优化展示

This commit is contained in:
2025-11-27 20:49:05 +08:00
parent 7166d5049f
commit 93f66d844c

View File

@@ -58,7 +58,13 @@
</div> </div>
<div v-else-if="compareResult.length > 0" class="table-wrapper"> <div v-else-if="compareResult.length > 0" class="table-wrapper">
<el-table :data="compareResult" style="width: 100%" border> <el-table :data="compareResult" style="width: 100%" border>
<el-table-column prop="nutrientName" label="营养素" fixed /> <el-table-column label="营养素" fixed>
<template #default="scope">
<el-tooltip :content="nutrientsDescriptionMap[scope.row.nutrientName]" placement="top">
<span>{{ scope.row.nutrientName }}</span>
</el-tooltip>
</template>
</el-table-column>
<el-table-column :label="currentRecipe.name"> <el-table-column :label="currentRecipe.name">
<template #default="scope"> <template #default="scope">
<span :style="{ color: scope.row.currentRecipeValue > scope.row.compareRecipeValue ? 'green' : (scope.row.currentRecipeValue < scope.row.compareRecipeValue ? 'red' : 'inherit') }"> <span :style="{ color: scope.row.currentRecipeValue > scope.row.compareRecipeValue ? 'green' : (scope.row.currentRecipeValue < scope.row.compareRecipeValue ? 'red' : 'inherit') }">
@@ -111,7 +117,7 @@
<script> <script>
import { ref, watch, computed } from 'vue'; import { ref, watch, computed } from 'vue';
import { getRecipes, getRecipeById, getPigTypes, getPigTypeById, getRawMaterialById } from '../../api/feed'; import { getNutrients, getRecipes, getRecipeById, getPigTypes, getPigTypeById, getRawMaterialById } from '../../api/feed';
import { ElMessage } from 'element-plus'; import { ElMessage } from 'element-plus';
import { Check, Close } from '@element-plus/icons-vue'; import { Check, Close } from '@element-plus/icons-vue';
@@ -140,6 +146,7 @@ export default {
const compareResult = ref([]); const compareResult = ref([]);
const compareRecipeName = ref(''); const compareRecipeName = ref('');
const pigTypeName = ref(''); const pigTypeName = ref('');
const nutrientsDescriptionMap = ref({}); // 新增:存储营养素描述的映射
const handleClose = () => { const handleClose = () => {
emit('update:visible', false); emit('update:visible', false);
@@ -182,6 +189,19 @@ export default {
} }
}; };
// 新增:获取所有营养素列表及其描述
const fetchNutrientsDescriptions = async () => {
try {
const response = await getNutrients({ page_size: 999 });
nutrientsDescriptionMap.value = response.data.list.reduce((map, nutrient) => {
map[nutrient.name] = nutrient.description;
return map;
}, {});
} catch (err) {
ElMessage.error('获取营养素描述失败: ' + (err.message || '未知错误'));
}
};
// 计算配方的营养成分汇总 // 计算配方的营养成分汇总
const calculateRecipeNutrientSummary = async (recipe) => { const calculateRecipeNutrientSummary = async (recipe) => {
const summary = new Map(); const summary = new Map();
@@ -297,6 +317,7 @@ export default {
if (newVal) { if (newVal) {
fetchRecipeList(); fetchRecipeList();
fetchPigTypeList(); fetchPigTypeList();
fetchNutrientsDescriptions(); // 新增:在对话框显示时获取营养素描述
} }
}, { immediate: true }); }, { immediate: true });
@@ -314,6 +335,7 @@ export default {
handleClose, handleClose,
canCompare, canCompare,
startCompare, startCompare,
nutrientsDescriptionMap, // 新增:返回 nutrientsDescriptionMap
}; };
}, },
}; };