修复热量饼图

This commit is contained in:
huangdeliang 2021-03-18 19:52:10 +08:00
parent 2d1eef6436
commit 47f77bcc6f
2 changed files with 11 additions and 8 deletions
stdiet-ui/src
store/modules
views/custom/recipesBuild/InfoView/PieChart

@ -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 =>

@ -38,7 +38,7 @@
<div class="summary">
<div style="font-size: 12px; color: #606266">总热量约等于</div>
<div style="color: #515a6e; font-weight: bold">
{{ totalHeat.toFixed(1) }}千卡
{{ data[0] ? data[0].totalHeat.toFixed(1) : 0 }}千卡
</div>
</div>
</div>
@ -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',
},
},