Files
emsfront/src/views/ems/dzjk/tjbb/glqx/index.vue

152 lines
3.6 KiB
Vue
Raw Normal View History

<template>
<el-card
shadow="always"
class="common-card-container time-range-card"
style="margin-top: 20px"
>
<div slot="header" class="time-range-header">
<span class="card-title">功率曲线</span>
<date-range-select
ref="dateRangeSelect"
@reset="resetTime"
@updateDate="updateDate"
/>
</div>
<div class="card-main" v-loading="loading">
<div id="glqxEchart" style="height: 310px"></div>
</div>
</el-card>
</template>
<script>
import * as echarts from "echarts";
import resize from "@/mixins/ems/resize";
2025-07-09 23:52:19 +08:00
import getQuerySiteId from "@/mixins/ems/getQuerySiteId";
import { getPcsNameList, getPowerData } from "@/api/ems/dzjk";
import { formatDate } from "@/filters/ems";
import DateRangeSelect from "@/components/Ems/DateRangeSelect/index.vue";
export default {
name: "DzjkTjbbGlqx",
components: { DateRangeSelect },
mixins: [resize, getQuerySiteId],
data() {
return {
pickerOptions: {
disabledDate(time) {
return time.getTime() > Date.now();
},
},
dateRange: [],
loading: false,
dateRangeInit: true,
};
},
methods: {
// 更新时间范围 重置图表
updateDate(data) {
this.dateRange = data || [];
this.getData();
},
resetTime() {
this.dateRangeInit = true;
2025-09-26 14:47:45 +08:00
},
getData() {
const { siteId } = this;
let [start = "", end = ""] = this.dateRange || [];
//接口调用完成之后 设置图表、结束loading
this.loading = true;
if (this.dateRangeInit) {
start = "";
end = "";
this.dateRangeInit = false;
2025-09-25 17:30:16 +08:00
}
getPowerData({
siteId,
startDate: formatDate(start),
endDate: formatDate(end),
})
.then((response) => {
this.setOption(response?.data || []);
})
.finally(() => {
this.loading = false;
});
},
2025-07-09 23:52:19 +08:00
setOption(data) {
const source = [["日期", "电网功率", "负载功率", "储能功率", "光伏功率"]];
data.forEach((item) => {
source.push([
item.statisDate,
item.gridPower,
item.loadPower,
item.storagePower,
item.pvPower,
]);
});
this.chart.setOption(
{
grid: {
containLabel: true,
},
legend: {
left: "center",
bottom: "15",
},
tooltip: {
trigger: "axis",
axisPointer: {
// 坐标轴指示器,坐标轴触发有效
type: "shadow", // 默认为直线,可选为:'line' | 'shadow'
},
2025-09-14 23:33:53 +08:00
},
textStyle: {
color: "#333333",
2025-09-14 23:33:53 +08:00
},
xAxis: {
type: "category",
2025-09-14 23:33:53 +08:00
},
yAxis: {
type: "value",
},
dataset: { source },
series: [
{
type: "line",
},
{
type: "line",
},
{
type: "line",
},
{
type: "line",
},
],
},
true
);
},
initChart() {
if (this.chart) return;
this.chart = echarts.init(document.querySelector("#glqxEchart"));
},
init() {
this.$nextTick(() => {
this.dateRangeInit = true;
this.initChart();
this.$refs.dateRangeSelect.init();
});
2025-07-09 23:52:19 +08:00
},
},
2025-09-26 14:47:45 +08:00
beforeDestroy() {
if (!this.chart) {
return;
}
this.chart.dispose();
this.chart = null;
},
};
</script>