yudao-init/src/views/copilot/energy/components/ElecCost.vue

129 lines
3.0 KiB
Vue
Raw Normal View History

2024-04-29 17:00:53 +08:00
<!--
filename: ElecCost.vue
author: liubin
date: 2024-04-29 16:37:01
description: 电能耗
-->
<template>
2024-04-30 09:35:44 +08:00
<LineChartBase
v-if="1"
:legend="legend"
:series="series"
:xAxis="xAxis"
in="elecCost"
class="elec-cost"
/>
<BarChartBase
v-else
:legend="legend"
:series="series"
:xAxis="xAxis"
in="elecCost"
class="elec-cost"
/>
2024-04-29 17:00:53 +08:00
</template>
<script>
2024-04-30 09:35:44 +08:00
import BarChartBaseVue from "@/views/copilot/components/BarChartBase.vue";
import LineChartBaseVue from "@/views/copilot/components/LineChartBase.vue";
2024-04-29 17:00:53 +08:00
export default {
name: "ElecCost",
2024-04-30 09:35:44 +08:00
components: {
BarChartBase: BarChartBaseVue,
LineChartBase: LineChartBaseVue,
},
props: {
period: {
type: String,
default: "日",
},
},
2024-04-29 17:00:53 +08:00
data() {
2024-04-30 09:35:44 +08:00
// 城市数组的顺序必须是固定的
const cities = ["瑞昌", "邯郸", "株洲", "佳木斯", "成都", "凯盛", "蚌埠"];
return {
xAxis: cities,
};
},
computed: {
legend() {
switch (this.period) {
case "日":
return [{ label: "昨日", color: "#12f7f1" }];
case "周":
return [{ label: "本周", color: "#12f7f1" }];
case "月": {
const year = new Date().getFullYear();
const month = new Date().getMonth() + 1;
return [
{ label: `${year - 1}${month}`, color: "#12f7f1" },
{ label: `${year}${month}`, color: "#58adfa" },
];
}
case "年": {
const year = new Date().getFullYear();
return [
{ label: `${year - 1}`, color: "#12f7f1" },
{ label: `${year}`, color: "#58adfa" },
];
}
default:
return [
{ label: `${year - 1}`, color: "#12f7f1" },
{ label: `${year}`, color: "#58adfa" },
];
}
},
series() {
const { ftoInvest } = this.$store.getters.copilot.yield;
let dataList = null;
switch (this.period) {
case "日":
case "周":
dataList = ftoInvest?.current;
break;
default:
dataList = [];
dataList[0] = ftoInvest?.pervious;
dataList[1] = ftoInvest?.current;
}
return getTemplate(this.period, dataList);
},
2024-04-29 17:00:53 +08:00
},
methods: {},
};
2024-04-30 09:35:44 +08:00
function getTemplate(period, dataList) {
const year = new Date().getFullYear();
const month = new Date().getMonth() + 1;
return period == "日" || period == "周"
? [
{
name: period == "日" ? "昨日" : "本周",
data: dataList ?? [],
},
]
: [
{
name: period == "年" ? `${year - 1}` : `${year - 1}${month}`,
data: dataList ? dataList[0] : [],
},
{
name: period == "年" ? `${year}` : `${year}${month}`,
data: dataList ? dataList[1] : [],
// : Array.from({ length: 7 }, () => Math.floor(Math.random() * 1000)),
},
];
}
2024-04-29 17:00:53 +08:00
</script>
<style scoped lang="scss">
.elec-cost {
flex: 1;
}
</style>