diff --git a/stdiet-ui/src/store/modules/recipes.js b/stdiet-ui/src/store/modules/recipes.js index 3448e1f42..c5dc6652a 100644 --- a/stdiet-ui/src/store/modules/recipes.js +++ b/stdiet-ui/src/store/modules/recipes.js @@ -517,6 +517,7 @@ const getters = { obj.fHeat = obj.fWeight * 9; obj.cWeight += (igd.weight / 100) * igd.carbonRatio; obj.cHeat = obj.cWeight * 4; + obj.totalHeat = obj.pHeat + obj.fHeat + obj.cHeat; obj[`heat${cur.type}`] += (igd.weight / 100) * igd.proteinRatio * 4 + (igd.weight / 100) * igd.fatRatio * 9 + @@ -532,16 +533,17 @@ const getters = { pHeat: 0, fHeat: 0, cHeat: 0, + totalHeat: 0, heat1: 0, heat2: 0, heat3: 0, heat4: 0, heat5: 0, - heat6: 0, + heat6: 0 } ) ); - // console.log(nutriData); + console.log(nutriData); return nutriData; }, verifyNotRecData: state => diff --git a/stdiet-ui/src/views/custom/recipesBuild/InfoView/PieChart/index.vue b/stdiet-ui/src/views/custom/recipesBuild/InfoView/PieChart/index.vue index 1da5ce55c..3e4eda1bc 100644 --- a/stdiet-ui/src/views/custom/recipesBuild/InfoView/PieChart/index.vue +++ b/stdiet-ui/src/views/custom/recipesBuild/InfoView/PieChart/index.vue @@ -38,7 +38,7 @@
总热量约等于
- {{ totalHeat.toFixed(1) }}千卡 + {{ data[0] ? data[0].totalHeat.toFixed(1) : 0 }}千卡
@@ -82,7 +82,6 @@ export default { data() { return { chart: null, - totalHeat: 0, nameDict: { p: "蛋白质", f: "脂肪", @@ -107,15 +106,15 @@ export default { mData() { const [data] = this.data; if (!data) { - this.totalHeat = 0; return []; } - this.totalHeat = data.cHeat + data.fHeat + data.pHeat; const mData = ["Weight", "Rate"].map((t, idx) => ({ type: this.typeDict[t], ...["p", "f", "c"].reduce((obj, cur) => { obj[cur] = idx - ? `${((data[`${cur}Heat`] / this.totalHeat) * 100).toFixed(2)}%` + ? data.totalHeat === 0 + ? 0 + : `${((data[`${cur}Heat`] / data.totalHeat) * 100).toFixed(2)}%` : `${data[`${cur}Weight`].toFixed(1)}克`; return obj; }, {}), @@ -199,7 +198,9 @@ export default { top: 18, left: 8, style: { - text: `${this.totalHeat.toFixed(1)}千卡`, + text: `${ + data.totalHeat ? data.totalHeat.toFixed(1) : 0 + }千卡`, font: '14px "Microsoft YaHei", sans-serif', }, },