Files
emsfront/src/views/ems/dzjk/sbjk/ssyx/DcpjwdChart.vue

143 lines
3.5 KiB
Vue
Raw Normal View History

2025-06-18 01:01:17 +08:00
<template>
2025-09-27 14:50:20 +08:00
<el-card
shadow="always"
class="common-card-container common-card-container-body-no-padding"
>
2025-06-18 01:01:17 +08:00
<div slot="header">
<span class="card-title">电池平均温度</span>
</div>
2026-02-15 16:24:29 +08:00
<div ref="chartRef" style="height: 360px" />
2025-06-18 01:01:17 +08:00
</el-card>
</template>
<style scoped lang="scss"></style>
<script>
2025-09-27 14:50:20 +08:00
import * as echarts from "echarts";
import resize from "@/mixins/ems/resize";
2026-02-15 16:24:29 +08:00
import { getPointConfigCurve } from "@/api/ems/site";
2025-06-18 01:01:17 +08:00
export default {
mixins: [resize],
2026-02-15 16:24:29 +08:00
props: {
displayData: {
type: Array,
default: () => []
}
},
2025-06-18 01:01:17 +08:00
data() {
return {
2025-09-27 14:50:20 +08:00
chart: null,
};
2025-06-18 01:01:17 +08:00
},
mounted() {
2026-02-15 16:24:29 +08:00
this.chart = echarts.init(this.$refs.chartRef);
2025-06-18 01:01:17 +08:00
},
beforeDestroy() {
if (!this.chart) {
2025-09-27 14:50:20 +08:00
return;
2025-06-18 01:01:17 +08:00
}
2025-09-27 14:50:20 +08:00
this.chart.dispose();
this.chart = null;
2025-06-18 01:01:17 +08:00
},
methods: {
2025-11-25 17:56:12 +08:00
init(siteId,timeRange) {
const [startTime='', endTime=''] = timeRange;
const query = {
siteId,
rangeType: "custom",
startTime: this.normalizeDateTime(startTime, false),
endTime: this.normalizeDateTime(endTime, true)
};
const rows = (this.displayData || []).filter(
2026-02-15 16:24:29 +08:00
(item) =>
item &&
item.fieldCode === "SBJK_SSYX__curveBatteryAveTemp" &&
item.useFixedDisplay !== 1 &&
item.dataPoint
);
const tasks = rows.map((row) => {
const pointId = String(row.dataPoint || "").trim();
if(!pointId) return Promise.resolve(null);
return getPointConfigCurve({
...query,
pointId
}).then((response) => {
const list = response?.data || [];
return {
name: (row.deviceName || "") + (row.fieldName || row.fieldCode || pointId),
data: list
.map((item) => [this.parseToTimestamp(item.dataTime), Number(item.pointValue)])
.filter((item) => item[0] && !Number.isNaN(item[1]))
};
}).catch(() => null);
});
Promise.all(tasks).then((series) => {
this.setOption((series || []).filter(Boolean));
});
2025-06-18 01:01:17 +08:00
},
2026-02-15 16:24:29 +08:00
normalizeDateTime(value, endOfDay) {
const raw = String(value || "").trim();
if (!raw) return "";
if (raw.includes(" ")) return raw;
return `${raw} ${endOfDay ? "23:59:59" : "00:00:00"}`;
},
parseToTimestamp(value) {
if (!value) return null;
const t = new Date(value).getTime();
return Number.isNaN(t) ? null : t;
},
setOption(seriesData = []) {
this.chart && this.chart.setOption({
2025-09-27 14:50:20 +08:00
legend: {
left: "center",
top: "5",
itemWidth: 10,
itemHeight: 5,
textStyle: {
fontSize: 9,
},
2025-06-18 01:01:17 +08:00
},
grid: {
2025-09-27 14:50:20 +08:00
containLabel: true,
},
tooltip: {
2025-11-26 17:50:06 +08:00
show:true,
2025-09-27 14:50:20 +08:00
trigger: "axis",
axisPointer: {
2026-02-15 16:24:29 +08:00
type: "cross",
2025-11-26 17:50:06 +08:00
}
},
2025-09-27 14:50:20 +08:00
textStyle: {
color: "#333333",
2025-06-18 01:01:17 +08:00
},
2026-02-15 16:24:29 +08:00
xAxis: { type: "time" },
2025-06-18 01:01:17 +08:00
yAxis: {
2025-09-27 14:50:20 +08:00
type: "value",
2025-06-18 01:01:17 +08:00
},
dataZoom: [
{
2025-09-27 14:50:20 +08:00
type: "inside",
start: 0,
2025-09-27 14:50:20 +08:00
end: 100,
},
{
start: 0,
2025-09-27 14:50:20 +08:00
end: 100,
},
],
series: seriesData.map(item => ({
type: "line",
name: item.name,
showSymbol: false,
smooth: true,
areaStyle: {
opacity: 0.35
2025-09-27 14:50:20 +08:00
},
data: item.data
})),
},true);
2025-09-27 14:50:20 +08:00
},
},
};
2025-06-18 01:01:17 +08:00
</script>