修复健康信息
This commit is contained in:
@ -0,0 +1,180 @@
|
||||
<template>
|
||||
<div :class="className" :style="{ height: height, width: width }" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import echarts from "echarts";
|
||||
import VueScrollTo from "vue-scrollto";
|
||||
require("@/utils/echarts/myShine");
|
||||
import resize from "@/views/dashboard/mixins/resize";
|
||||
import { createNamespacedHelpers } from "vuex";
|
||||
const { mapMutations } = createNamespacedHelpers("recipes");
|
||||
const animationDuration = 6000;
|
||||
|
||||
export default {
|
||||
mixins: [resize],
|
||||
props: {
|
||||
className: {
|
||||
type: String,
|
||||
default: "chart",
|
||||
},
|
||||
width: {
|
||||
type: String,
|
||||
default: "100%",
|
||||
},
|
||||
height: {
|
||||
type: String,
|
||||
default: "300px",
|
||||
},
|
||||
data: {
|
||||
type: Array,
|
||||
default: [],
|
||||
},
|
||||
max: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
chart: null,
|
||||
nameDict: {
|
||||
pHeat: "蛋白质",
|
||||
fHeat: "脂肪",
|
||||
cHeat: "碳水",
|
||||
},
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
this.$nextTick(() => {
|
||||
this.initChart();
|
||||
});
|
||||
},
|
||||
beforeDestroy() {
|
||||
if (!this.chart) {
|
||||
return;
|
||||
}
|
||||
this.chart.dispose();
|
||||
this.chart = null;
|
||||
},
|
||||
updated() {
|
||||
// console.log("updated");
|
||||
},
|
||||
methods: {
|
||||
...mapMutations(["setCurrentDay"]),
|
||||
initChart() {
|
||||
this.chart = echarts.init(this.$el, "myShine");
|
||||
this.chart.on("click", this.handleOnClick);
|
||||
this.updateChart(this.data.length > 0 ? this.data : {});
|
||||
},
|
||||
updateChart(source) {
|
||||
// console.log(this.max);
|
||||
this.chart.clear();
|
||||
this.chart.setOption({
|
||||
title: {
|
||||
text: "营养统计",
|
||||
},
|
||||
tooltip: {
|
||||
trigger: "axis",
|
||||
// appendToBody: true,
|
||||
formatter: (params) => {
|
||||
// console.log(params);
|
||||
const [param] = params;
|
||||
const { name } = param;
|
||||
let totalHeat = 0;
|
||||
const tooltips = params.reduce(
|
||||
(arr, cur) => {
|
||||
const { value, seriesName } = cur;
|
||||
const nutriName = this.nameDict[seriesName];
|
||||
totalHeat += value[seriesName];
|
||||
const heatVal = value[seriesName].toFixed(1);
|
||||
const weightVal = value[
|
||||
`${seriesName.substring(0, 1)}Weight`
|
||||
].toFixed(1);
|
||||
arr.push(
|
||||
`${cur.marker} ${nutriName}:${weightVal}克(${heatVal}千卡)`
|
||||
);
|
||||
return arr;
|
||||
},
|
||||
[name]
|
||||
);
|
||||
tooltips[0] += ` - 共${totalHeat.toFixed(1)}千卡`;
|
||||
return tooltips.join("</br>");
|
||||
},
|
||||
},
|
||||
dataset: {
|
||||
dimensions: [
|
||||
"name",
|
||||
"pWeight",
|
||||
"pHeat",
|
||||
"fWeight",
|
||||
"fHeat",
|
||||
"cWeight",
|
||||
"cHeat",
|
||||
],
|
||||
source,
|
||||
},
|
||||
grid: {
|
||||
top: 50,
|
||||
left: 10,
|
||||
right: 50,
|
||||
bottom: 10,
|
||||
containLabel: true,
|
||||
},
|
||||
xAxis: {
|
||||
type: "category",
|
||||
// axisLabel: {
|
||||
// rotate: 45,
|
||||
// },
|
||||
},
|
||||
yAxis: {
|
||||
type: "value",
|
||||
name: "热量/千卡",
|
||||
nameTextStyle: {
|
||||
color: "#262626",
|
||||
fontSize: 12,
|
||||
},
|
||||
},
|
||||
series: ["pHeat", "fHeat", "cHeat"].map((dim, idx) => ({
|
||||
name: dim,
|
||||
type: "bar",
|
||||
barWidth: 24,
|
||||
stack: "bar",
|
||||
encode: {
|
||||
y: dim,
|
||||
x: 0,
|
||||
},
|
||||
markLine: {
|
||||
data: [{ name: "BMR", yAxis: this.max ? this.max - 400 : 0 }],
|
||||
symbol: "none",
|
||||
lineStyle: {
|
||||
color: "#d96969",
|
||||
},
|
||||
},
|
||||
itemStyle: {
|
||||
borderWidth: 2,
|
||||
borderColor: "#fff",
|
||||
},
|
||||
})),
|
||||
});
|
||||
},
|
||||
handleOnClick(params) {
|
||||
// console.log(params);
|
||||
const { dataIndex } = params;
|
||||
this.setCurrentDay({ currentDay: dataIndex });
|
||||
VueScrollTo.scrollTo(`#recipes${dataIndex}`, 500, {
|
||||
container: "#recipes_content",
|
||||
});
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
data(newVal, oldVal) {
|
||||
if (newVal) {
|
||||
this.$nextTick(() => {
|
||||
this.updateChart(newVal);
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
@ -0,0 +1,226 @@
|
||||
<template>
|
||||
<div
|
||||
:class="`aspect_pie_chart_wrapper ${className || ''}`"
|
||||
:style="{ height: height, width: width }"
|
||||
>
|
||||
<div ref="echart" :style="{ height: height, width: '100px' }" />
|
||||
<div>
|
||||
<el-table
|
||||
:data="mData"
|
||||
size="mini"
|
||||
border
|
||||
:cell-style="{ padding: '2px 0' }"
|
||||
:header-cell-style="{ padding: '4px 0', height: 'unset' }"
|
||||
class="small_table"
|
||||
>
|
||||
<el-table-column label="营养" prop="type" align="center" width="60" />
|
||||
<el-table-column label="蛋白质" prop="p" align="center" width="65" />
|
||||
<el-table-column label="脂肪" prop="f" align="center" width="65" />
|
||||
<el-table-column label="碳水" prop="c" align="center" width="65" />
|
||||
</el-table>
|
||||
<div class="summary">
|
||||
<div style="font-size: 12px; color: #606266">总热量约等于</div>
|
||||
<div style="color: #515a6e; font-weight: bold">
|
||||
{{ totalHeat.toFixed(1) }}千卡
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
style="text-align: right; margin-top: 4px"
|
||||
v-if="recipesData.length > 1"
|
||||
>
|
||||
<el-button size="mini" type="text" @click="backToAll"
|
||||
>查看全部</el-button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import echarts from "echarts";
|
||||
require("@/utils/echarts/myShine");
|
||||
import resize from "@/views/dashboard/mixins/resize";
|
||||
import TextInfo from "@/components/TextInfo";
|
||||
import { createNamespacedHelpers } from "vuex";
|
||||
const { mapMutations, mapState } = createNamespacedHelpers("recipes");
|
||||
|
||||
export default {
|
||||
mixins: [resize],
|
||||
components: {
|
||||
TextInfo,
|
||||
},
|
||||
props: {
|
||||
className: {
|
||||
type: String,
|
||||
default: "chart",
|
||||
},
|
||||
width: {
|
||||
type: String,
|
||||
default: "100%",
|
||||
},
|
||||
height: {
|
||||
type: String,
|
||||
default: "300px",
|
||||
},
|
||||
data: {
|
||||
type: Array,
|
||||
default: [],
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
chart: null,
|
||||
totalHeat: 0,
|
||||
nameDict: {
|
||||
p: "蛋白质",
|
||||
f: "脂肪",
|
||||
c: "碳水",
|
||||
},
|
||||
typeDict: {
|
||||
Weight: "摄入量",
|
||||
Rate: "供能比",
|
||||
},
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
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[`${cur}Weight`].toFixed(1)}克`;
|
||||
return obj;
|
||||
}, {}),
|
||||
}));
|
||||
// console.log(mData);
|
||||
return mData;
|
||||
},
|
||||
...mapState(["recipesData"]),
|
||||
},
|
||||
mounted() {
|
||||
this.$nextTick(() => {
|
||||
this.initChart();
|
||||
});
|
||||
},
|
||||
beforeDestroy() {
|
||||
if (!this.chart) {
|
||||
return;
|
||||
}
|
||||
this.chart.dispose();
|
||||
this.chart = null;
|
||||
},
|
||||
methods: {
|
||||
initChart() {
|
||||
this.chart = echarts.init(this.$refs.echart, "myShine");
|
||||
this.updateChart(this.data.length > 0 ? this.data[0] : {});
|
||||
},
|
||||
backToAll() {
|
||||
this.resetCurrentDay({ currentDay: -1 });
|
||||
},
|
||||
updateChart(data) {
|
||||
this.chart.clear();
|
||||
this.chart.setOption({
|
||||
title: {
|
||||
text: "营养分析",
|
||||
subtext: data.name,
|
||||
},
|
||||
tooltip: {
|
||||
position: "right",
|
||||
trigger: "item",
|
||||
// appendToBody: true,
|
||||
formatter: (params) => {
|
||||
const {
|
||||
name,
|
||||
marker,
|
||||
percent,
|
||||
data: { value, oriData, dim },
|
||||
} = params;
|
||||
return [
|
||||
`${marker} ${name}`,
|
||||
`摄入量:${oriData[`${dim}Weight`].toFixed(1)}克`,
|
||||
`摄入热量:${value.toFixed(1)}千卡`,
|
||||
`供能比:${percent}%`,
|
||||
].join("</br>");
|
||||
},
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: data.name,
|
||||
type: "pie",
|
||||
radius: [0, 40],
|
||||
center: ["50%", "55%"],
|
||||
data: ["p", "f", "c"].map((dim) => ({
|
||||
dim,
|
||||
value: data[`${dim}Heat`],
|
||||
name: this.nameDict[dim],
|
||||
oriData: data,
|
||||
})),
|
||||
// labelLine: {
|
||||
// length: 5,
|
||||
// length2: 5,
|
||||
// },
|
||||
label: {
|
||||
show: true,
|
||||
position: "inside",
|
||||
color: "#fff",
|
||||
fontSize: 10,
|
||||
fontWeight: "bold",
|
||||
},
|
||||
itemStyle: {
|
||||
borderWidth: 1,
|
||||
borderColor: "#fff",
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
},
|
||||
...mapMutations(["resetCurrentDay"]),
|
||||
},
|
||||
watch: {
|
||||
data(newVal, oldVal) {
|
||||
if (newVal) {
|
||||
this.$nextTick(() => {
|
||||
this.updateChart(newVal[0]);
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.aspect_pie_chart_wrapper {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
|
||||
& > div:nth-child(1) {
|
||||
// width: 200px
|
||||
}
|
||||
|
||||
// & > div:nth-child(2) {
|
||||
.small_table {
|
||||
.my_cell {
|
||||
padding: 2px 0 !important;
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
.summary {
|
||||
padding: 2px;
|
||||
border-bottom: 1px solid #dfe6ec;
|
||||
border-left: 1px solid #dfe6ec;
|
||||
border-right: 1px solid #dfe6ec;
|
||||
|
||||
& > div {
|
||||
padding: 3px;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
@ -0,0 +1,89 @@
|
||||
<template>
|
||||
<div class="template_info_wrapper">
|
||||
<h2>{{ data.name }}</h2>
|
||||
<TextInfo title="营养师" :value="data.nutritionist" />
|
||||
<TextInfo
|
||||
title="营养师助理"
|
||||
:value="data.nutriAssis"
|
||||
style="margin-top: 24px"
|
||||
/>
|
||||
<div class="remark_info">
|
||||
<span class="info_title">备注:</span>
|
||||
<el-input
|
||||
type="textarea"
|
||||
:rows="8"
|
||||
placeholder="请输入内容"
|
||||
v-model="data.remark"
|
||||
>
|
||||
</el-input>
|
||||
</div>
|
||||
<div style="margin-top: 12px; text-align: right">
|
||||
<el-button v-if="change" type="primary" size="mini" @click="handleSubmit"
|
||||
>提交</el-button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import TextInfo from "@/components/TextInfo";
|
||||
import { updateRecipesTemplate } from "@/api/custom/recipesTemplate";
|
||||
export default {
|
||||
name: "TemplateInfoView",
|
||||
props: {
|
||||
data: {
|
||||
type: Object,
|
||||
default: () => ({
|
||||
id: "",
|
||||
name: "",
|
||||
nutritionist: "",
|
||||
nutriAssis: "",
|
||||
remark: "",
|
||||
}),
|
||||
},
|
||||
},
|
||||
components: {
|
||||
TextInfo,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
oriRemark: "",
|
||||
change: false,
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
"data.remark": function (val, oldVal) {
|
||||
if (!oldVal && val) {
|
||||
this.oriRemark = val;
|
||||
}
|
||||
this.change = this.oriRemark !== val;
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
handleSubmit() {
|
||||
const { remark, id } = this.data;
|
||||
updateRecipesTemplate({ id, remark }).then((res) => {
|
||||
if (res.code === 200) {
|
||||
this.$message.success("修改成功");
|
||||
this.change = false;
|
||||
this.oriRemark = remark;
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.template_info_wrapper {
|
||||
.remark_info {
|
||||
font-size: 14px;
|
||||
margin-top: 24px;
|
||||
display: flex;
|
||||
|
||||
.info_title {
|
||||
color: #8c8c8c;
|
||||
flex: 0 0 48px;
|
||||
width: auto;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
78
stdiet-ui/src/views/custom/recipesBuild/InfoView/index.vue
Normal file
78
stdiet-ui/src/views/custom/recipesBuild/InfoView/index.vue
Normal file
@ -0,0 +1,78 @@
|
||||
<template>
|
||||
<div class="recipes_build_info_view_wrapper">
|
||||
<div class="top" v-if="!!recipesData.length">
|
||||
<BarChart
|
||||
v-if="analyseData.length > 1"
|
||||
:data="analyseData"
|
||||
height="160px"
|
||||
width="100%"
|
||||
:max="max"
|
||||
/>
|
||||
<PieChart
|
||||
v-if="analyseData.length === 1"
|
||||
:data="analyseData"
|
||||
height="160px"
|
||||
width="100%"
|
||||
/>
|
||||
</div>
|
||||
<div class="content">
|
||||
<TemplateInfoView v-if="!!temId" :data="templateInfo" />
|
||||
<HealthyView :data="healthyData" v-else-if="healthyDataType === 0" dev />
|
||||
<BodySignView :data="healthyData" v-else dev />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { createNamespacedHelpers } from "vuex";
|
||||
const {
|
||||
mapActions,
|
||||
mapState,
|
||||
mapGetters,
|
||||
} = createNamespacedHelpers("recipes");
|
||||
import BarChart from "./BarChart";
|
||||
import PieChart from "./PieChart";
|
||||
import TemplateInfoView from "./TemplateInfoView";
|
||||
import HealthyView from "@/components/HealthyView";
|
||||
import BodySignView from "@/components/BodySignView";
|
||||
export default {
|
||||
name: "InfoView",
|
||||
data() {
|
||||
const { temId } = this.$route.query;
|
||||
return { temId };
|
||||
},
|
||||
components: {
|
||||
BarChart,
|
||||
PieChart,
|
||||
HealthyView,
|
||||
BodySignView,
|
||||
TemplateInfoView,
|
||||
},
|
||||
computed: {
|
||||
max() {
|
||||
const { basicBMR } = this.healthyData || {};
|
||||
return basicBMR
|
||||
? parseFloat(basicBMR.substring(0, basicBMR.indexOf("千卡")))
|
||||
: 0;
|
||||
},
|
||||
...mapState([
|
||||
"recipesData",
|
||||
"healthyData",
|
||||
"healthyDataType",
|
||||
"templateInfo",
|
||||
]),
|
||||
...mapGetters(["analyseData"]),
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.recipes_build_info_view_wrapper {
|
||||
.top {
|
||||
height: 160px;
|
||||
}
|
||||
|
||||
.content {
|
||||
overflow: auto;
|
||||
height: calc(100% - 160px);
|
||||
}
|
||||
}
|
||||
</style>
|
Reference in New Issue
Block a user