修复热量饼图

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

View File

@ -517,6 +517,7 @@ const getters = {
obj.fHeat = obj.fWeight * 9; obj.fHeat = obj.fWeight * 9;
obj.cWeight += (igd.weight / 100) * igd.carbonRatio; obj.cWeight += (igd.weight / 100) * igd.carbonRatio;
obj.cHeat = obj.cWeight * 4; obj.cHeat = obj.cWeight * 4;
obj.totalHeat = obj.pHeat + obj.fHeat + obj.cHeat;
obj[`heat${cur.type}`] += obj[`heat${cur.type}`] +=
(igd.weight / 100) * igd.proteinRatio * 4 + (igd.weight / 100) * igd.proteinRatio * 4 +
(igd.weight / 100) * igd.fatRatio * 9 + (igd.weight / 100) * igd.fatRatio * 9 +
@ -532,16 +533,17 @@ const getters = {
pHeat: 0, pHeat: 0,
fHeat: 0, fHeat: 0,
cHeat: 0, cHeat: 0,
totalHeat: 0,
heat1: 0, heat1: 0,
heat2: 0, heat2: 0,
heat3: 0, heat3: 0,
heat4: 0, heat4: 0,
heat5: 0, heat5: 0,
heat6: 0, heat6: 0
} }
) )
); );
// console.log(nutriData); console.log(nutriData);
return nutriData; return nutriData;
}, },
verifyNotRecData: state => verifyNotRecData: state =>

View File

@ -38,7 +38,7 @@
<div class="summary"> <div class="summary">
<div style="font-size: 12px; color: #606266">总热量约等于</div> <div style="font-size: 12px; color: #606266">总热量约等于</div>
<div style="color: #515a6e; font-weight: bold"> <div style="color: #515a6e; font-weight: bold">
{{ totalHeat.toFixed(1) }}千卡 {{ data[0] ? data[0].totalHeat.toFixed(1) : 0 }}千卡
</div> </div>
</div> </div>
</div> </div>
@ -82,7 +82,6 @@ export default {
data() { data() {
return { return {
chart: null, chart: null,
totalHeat: 0,
nameDict: { nameDict: {
p: "蛋白质", p: "蛋白质",
f: "脂肪", f: "脂肪",
@ -107,15 +106,15 @@ export default {
mData() { mData() {
const [data] = this.data; const [data] = this.data;
if (!data) { if (!data) {
this.totalHeat = 0;
return []; return [];
} }
this.totalHeat = data.cHeat + data.fHeat + data.pHeat;
const mData = ["Weight", "Rate"].map((t, idx) => ({ const mData = ["Weight", "Rate"].map((t, idx) => ({
type: this.typeDict[t], type: this.typeDict[t],
...["p", "f", "c"].reduce((obj, cur) => { ...["p", "f", "c"].reduce((obj, cur) => {
obj[cur] = idx 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)}`; : `${data[`${cur}Weight`].toFixed(1)}`;
return obj; return obj;
}, {}), }, {}),
@ -199,7 +198,9 @@ export default {
top: 18, top: 18,
left: 8, left: 8,
style: { style: {
text: `${this.totalHeat.toFixed(1)}千卡`, text: `${
data.totalHeat ? data.totalHeat.toFixed(1) : 0
}千卡`,
font: '14px "Microsoft YaHei", sans-serif', font: '14px "Microsoft YaHei", sans-serif',
}, },
}, },