331 lines
6.1 KiB
Vue
Raw Normal View History

2023-07-12 09:56:31 +08:00
<template>
<Card title="趋势图">
<div class="selectRight">
2023-07-29 17:59:01 +08:00
<el-date-picker
style="width:100%"
v-model="value1"
type="daterange"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
>
</el-date-picker>
2023-07-28 19:43:56 +08:00
<!-- <el-select class="m-2" placeholder="Select" size="small" v-model="receive">
2023-07-12 09:56:31 +08:00
<el-option
v-for="(item, index) in noiseList"
:key="index"
:label="item.label"
:value="item.value"
@click="checkChange(item.value)"
/>
2023-07-28 19:43:56 +08:00
</el-select> -->
2023-07-12 09:56:31 +08:00
</div>
<div id="myEcharts" ref="myEcharts" style="width: 100%; height: 100%"></div>
</Card>
</template>
<script lang="ts" setup>
import { GlobalStore } from "@/stores";
import { selectDustNoiseDataApi } from "@/api/modules/headNoise";
2023-07-29 11:56:50 +08:00
import { onMounted, reactive, ref, onBeforeUnmount } from "vue";
2023-07-12 09:56:31 +08:00
import * as echarts from "echarts";
import Card from "@/components/card.vue";
import mitts from "@/utils/bus"; //兄弟组件传值
const store = GlobalStore();
2023-07-28 19:43:56 +08:00
let dustData_24 = ref([]);
2023-07-29 11:56:50 +08:00
let xData: any = [];
let yData: any = [];
2023-07-28 19:43:56 +08:00
let option = ref({
2023-07-12 09:56:31 +08:00
// backgroundColor: '#071c3a',
title: {
// text: '日用气量分析',
textStyle: {
align: "center",
color: "#fff",
fontSize: 20
},
top: "2%",
left: "center"
},
// legend: {
// color: ["#17B4FA", "#47D8BE", "#F9A589"],
// // data: ['日用气量分析'],
// left: 'center',
// top: "8%",
// textStyle: {
// color: "#ffffff"
// }
// },
tooltip: {
trigger: "axis",
axisPointer: {
lineStyle: {
color: {
type: "linear",
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{
offset: 0,
color: "rgba(0, 255, 233,0)"
},
{
offset: 0.5,
color: "rgba(255, 255, 255,1)"
},
{
offset: 1,
color: "rgba(0, 255, 233,0)"
}
],
global: false
}
}
}
},
grid: {
top: "30%",
left: "12%",
right: "5%",
bottom: "15%"
// containLabel: true
},
xAxis: [
{
type: "category",
axisLine: {
show: true,
lineStyle: {
color: "#14346C"
}
},
splitArea: {
// show: true,
color: "#f00",
lineStyle: {
color: "#f00"
}
},
axisLabel: {
color: "#fff"
},
splitLine: {
show: false
},
boundaryGap: false,
2023-07-29 11:56:50 +08:00
data: xData
2023-07-12 09:56:31 +08:00
}
],
yAxis: [
{
type: "value",
name: "单位:ug/m³",
nameTextStyle: {
color: "#fff",
nameLocation: "start"
},
min: 0,
// max: 140,
splitNumber: 3,
splitLine: {
show: true,
lineStyle: {
color: "#14346C"
}
},
axisLine: {
show: true,
lineStyle: {
color: "#14346C"
}
},
axisLabel: {
show: true,
margin: 20,
textStyle: {
color: "#fff"
}
},
axisTick: {
show: true
}
}
],
series: [
{
type: "line",
// smooth: true, //是否平滑
showAllSymbol: true,
// symbol: 'image://./static/images/guang-circle.png',
symbol: "circle",
2023-07-29 11:56:50 +08:00
symbolSize: 5,
2023-07-12 09:56:31 +08:00
lineStyle: {
normal: {
color: "#fff",
shadowBlur: 0
}
},
label: {
show: false,
position: "top",
textStyle: {
color: "#fff"
}
},
itemStyle: {
color: "#A3EAFF",
borderColor: "#82FBEA",
borderWidth: 5,
shadowColor: "rgba(0, 0, 0, .6)",
shadowBlur: 0
},
lineStyle: {
normal: {
width: 1
}
},
tooltip: {
show: true
},
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(130, 251, 234,0.5)"
},
{
offset: 1,
color: "rgba(130, 251, 234,0.1)"
}
],
false
),
shadowColor: "rgba(130, 251, 234, 0.2",
shadowBlur: 20
}
},
2023-07-29 11:56:50 +08:00
data: yData
2023-07-12 09:56:31 +08:00
}
]
});
const noiseList = [
{
value: 0,
label: "扬尘PM2.5"
},
{
value: 1,
label: "扬尘PM10"
},
{
value: 2,
label: "风速"
},
{
value: 3,
label: "噪声"
}
];
2023-07-28 19:43:56 +08:00
// const labelName = ref("扬尘PM2.5");
let receive = ref("扬尘PM2.5" as any);
2023-07-12 09:56:31 +08:00
function drawChart() {
2023-07-29 11:56:50 +08:00
console.log("趋势图", xData);
console.log("趋势图", yData);
console.log("趋势图", option.value);
2023-07-12 09:56:31 +08:00
let myEchart = echarts.init(document.getElementById("myEcharts"));
2023-07-28 19:43:56 +08:00
myEchart.setOption(option.value);
2023-07-12 09:56:31 +08:00
// window.onresize = function () {
// myEchart.resize();
// }
}
//获取趋势图数据
const getList = async type => {
//当前日期
2023-07-29 11:56:50 +08:00
// let now = new Date();
// let yy = now.getFullYear(); //年
// let mm = now.getMonth() + 1; //月
// let dd = now.getDate(); //日
// let time = yy + "-";
// if (mm < 10) time += "0";
// time += mm + "-";
// if (dd < 10) time += "0";
// time += dd;
2023-07-12 09:56:31 +08:00
const res = await selectDustNoiseDataApi({
2023-07-29 11:56:50 +08:00
// searchDate: time,
deviceId: type,
2023-07-12 09:56:31 +08:00
projectSn: store.sn
});
2023-07-29 11:56:50 +08:00
console.log("左下角趋势图", res.result);
// dustData_24.value = res.result;
res.result.forEach(item => {
xData.push(item.time);
yData.push(item.pm25);
2023-07-12 09:56:31 +08:00
});
2023-07-29 17:59:01 +08:00
drawChart();
2023-07-12 09:56:31 +08:00
};
2023-07-29 11:56:50 +08:00
// const checkChange = type => {
// dustData_24.value.forEach(item => {
// xData.value.push(item.uploadDate.split(" ")[1]);
// yData.value.push(item.pm25);
// // if (type == 0) {
// // yData.value.push(item.pm25);
// // } else if (type == 1) {
// // yData.value.push(item.pm10);
// // } else if (type == 2) {
// // yData.value.push(item.windspeed);
// // } else if (type == 3) {
// // yData.value.push(item.noise);
// // }
// });
// console.log("selectType", type);
// getList(type);
// };
2023-07-12 09:56:31 +08:00
onMounted(async () => {
2023-07-29 11:56:50 +08:00
// checkChange(0);
2023-07-12 09:56:31 +08:00
mitts.on("currentDevDetail", e => {
2023-07-29 11:56:50 +08:00
xData.length = 0;
yData.length = 0;
2023-07-12 09:56:31 +08:00
receive.value = e.deviceId;
getList(e.deviceId);
2023-07-12 09:56:31 +08:00
});
});
// 即时销毁事件总线派发否则会执行两次miits.on造成不必要的内存浪费 7.14 by CJP
onBeforeUnmount(async () => {
mitts.off("currentDevDetail");
2023-07-28 19:43:56 +08:00
echarts.dispose;
});
2023-07-12 09:56:31 +08:00
</script>
<style lang="scss" scoped>
.selectRight {
position: absolute;
2023-07-29 17:59:01 +08:00
left: 12%;
width: 12%;
2023-07-12 09:56:31 +08:00
top: 75%;
z-index: 9;
}
::v-deep .el-input__wrapper {
background: #112d59;
}
::v-deep .el-input__inner {
color: #fff;
}
::v-deep .el-select .el-input .el-select__caret {
color: #fff;
}
</style>