refactor(ems): 重构曲线页面

- 根据设备类型动态显示图表
- 优化图表布局和样式
- 添加无数据提示信息
- 重构图表数据处理逻辑
- 优化图表联动缩放功能
boardTest
zch 3 weeks ago
parent b1c72d6ae9
commit c607c11182

@ -55,11 +55,23 @@
</el-form-item>
</el-form>
<Chart ref="Chart1" class="chart1"/>
<Chart ref="Chart2" class="chart2"/>
<Chart ref="Chart3" class="chart3"/>
<Chart ref="Chart4" class="chart4"/>
<Chart ref="Chart5" class="chart5"/>
<!-- 根据设备类型显示对应的图表 -->
<!-- type=5: 只显示温度 -->
<Chart v-if="selectedDeviceType === 5" ref="Chart2" class="chart-single"/>
<!-- type=6: 显示温度和湿度 -->
<div v-if="selectedDeviceType === 6">
<Chart ref="Chart1" class="chart-half"/>
<Chart ref="Chart2" class="chart-half"/>
</div>
<!-- type=7: 只显示噪声 -->
<Chart v-if="selectedDeviceType === 7" ref="Chart4" class="chart-single"/>
<!-- 未选择设备或其他类型时显示提示 -->
<div v-if="!selectedDeviceType" class="no-data-tip">
<p>请在左侧树中选择具体设备节点查看数据曲线</p>
</div>
</el-col>
</el-row>
@ -96,6 +108,8 @@ export default {
selectMonitorName: null,
//
baseMonitorInfoList: [],
//
selectedDeviceType: null,
//
daterangeRecordTime: [],
//
@ -261,25 +275,58 @@ export default {
/** 节点单击事件 */
handleNodeClick(data) {
// 线
if (data.children && data.children.length > 0) {
this.$message.warning('曲线页面请选择具体设备节点查看数据');
return;
}
// monitorIds使monitorId
this.queryParams.monitorIds = [];
/* this.queryParams.monitorCode = data.code*/
this.queryParams.monitorId = data.code
this.selectMonitorName = data.label
this.handleQuery()
this.queryParams.monitorId = data.code;
this.selectMonitorName = data.label;
//
this.selectedDeviceType = data.type;
console.log('选中设备:', data.label, 'type:', data.type);
this.handleQuery();
},
/** 曲线 */
async getChart() {
if (this.queryParams.monitorId == null) {
if (this.queryParams.monitorId == null || !this.selectedDeviceType) {
return
}
let query = JSON.parse(JSON.stringify(this.queryParams))
// const {data} = await vibrationInstantList(query)
const {data} = await getRecordIotenvInstantList(query)
let option1 = {
//
this.createChartByType(data);
},
//
createChartByType(data) {
switch (this.selectedDeviceType) {
case 5: //
this.createTemperatureChart(data);
break;
case 6: // 湿湿
this.createHumidityChart(data);
this.createTemperatureChart(data);
this.linkCharts(['Chart1', 'Chart2']);
break;
case 7: //
this.createNoiseChart(data);
break;
default:
console.warn('未知的设备类型:', this.selectedDeviceType);
}
},
// 湿
createHumidityChart(data) {
let option = {
title: {
text: this.selectMonitorName + ' 湿度曲线',
x: 'center'
@ -308,25 +355,25 @@ export default {
xAxis: {
data: data.map(e => e.recodeTime),
axisLine: {
show: true, //X线
show: true,
lineStyle: {
color: '#000000'
}
},
axisTick: {
show: true //X
show: true
},
axisLabel: {
show: true,
textStyle: {
color: '#000000' //X
color: '#000000'
}
}
},
yAxis: [
{
type: 'value',
name: '湿度',
name: '湿度(%)',
nameTextStyle: {
color: '#000000'
},
@ -353,27 +400,22 @@ export default {
series: [
{
name: '湿度',
connectNulls: true, //
connectNulls: true,
type: 'line',
smooth: true, //线
showAllSymbol: true, //
symbol: 'circle', //
symbolSize: 10, //
// itemStyle: {
// //线
// color: "#058cff",
// },
// lineStyle: {
// color: "#058cff",
// },
// areaStyle: {
// color: "rgba(5,140,255, 0.2)",
// },
smooth: true,
showAllSymbol: true,
symbol: 'circle',
symbolSize: 10,
data: data.map(e => e.humidity)
},
}
]
}
let option2 = {
};
this.$refs.Chart1.setData(option);
},
//
createTemperatureChart(data) {
let option = {
title: {
text: this.selectMonitorName + ' 温度曲线',
x: 'center'
@ -384,7 +426,6 @@ export default {
left: '10%',
right: '3%'
},
dataZoom: [{
type: 'slider'
}],
@ -403,18 +444,18 @@ export default {
xAxis: {
data: data.map(e => e.recodeTime),
axisLine: {
show: true, //X线
show: true,
lineStyle: {
color: '#000000'
}
},
axisTick: {
show: true //X
show: true
},
axisLabel: {
show: true,
textStyle: {
color: '#000000' //X
color: '#000000'
}
}
},
@ -448,120 +489,22 @@ export default {
series: [
{
name: '温度(℃)',
connectNulls: true, //
connectNulls: true,
type: 'line',
smooth: true, //线
showAllSymbol: true, //
symbol: 'circle', //
symbolSize: 10, //
// itemStyle: {
// //线
// color: "#058cff",
// },
// lineStyle: {
// color: "#058cff",
// },
// areaStyle: {
// color: "rgba(5,140,255, 0.2)",
// },
smooth: true,
showAllSymbol: true,
symbol: 'circle',
symbolSize: 10,
data: data.map(e => e.temperature)
},
}
]
}
// let option3 = {
// title: {
// text: this.selectMonitorName + ' 线',
// x: 'center'
// },
// grid: {
// top: '15%',
// bottom: '10%',
// left: '10%',
// right: '3%'
// },
// tooltip: {
// trigger: 'axis',
// axisPointer: {
// type: 'shadow',
// label: {
// show: true
// }
// }
// },
// dataZoom: [{
// type: 'slider'
// }],
// legend: {
// right: 0
// },
// xAxis: {
// data: data.map(e => e.recodeTime),
// axisLine: {
// show: true, //X线
// lineStyle: {
// color: '#000000'
// }
// },
// axisTick: {
// show: true //X
// },
// axisLabel: {
// show: true,
// textStyle: {
// color: '#000000' //X
// }
// }
// },
// yAxis: [
// {
// type: 'value',
// name: '',
// nameTextStyle: {
// color: '#000000'
// },
// splitLine: {
// show: false
// },
// axisTick: {
// show: true
// },
// axisLine: {
// show: true,
// lineStyle: {
// color: '#000000'
// }
// },
// axisLabel: {
// show: true,
// textStyle: {
// color: '#000000'
// }
// }
// }
// ],
// series: [
// {
// name: '',
// type: 'line',
// smooth: true, //线
// showAllSymbol: true, //
// symbol: 'circle', //
// symbolSize: 10, //
// // itemStyle: {
// // //线
// // color: "#058cff",
// // },
// // lineStyle: {
// // color: "#058cff",
// // },
// // areaStyle: {
// // color: "rgba(5,140,255, 0.2)",
// // },
// data: data.map(e => e.illuminance)
// },
// ]
// }
let option4 = {
};
this.$refs.Chart2.setData(option);
},
//
createNoiseChart(data) {
let option = {
title: {
text: this.selectMonitorName + ' 噪声曲线',
x: 'center'
@ -590,25 +533,25 @@ export default {
xAxis: {
data: data.map(e => e.recodeTime),
axisLine: {
show: true, //X线
show: true,
lineStyle: {
color: '#000000'
}
},
axisTick: {
show: true //X
show: true
},
axisLabel: {
show: true,
textStyle: {
color: '#000000' //X
color: '#000000'
}
}
},
yAxis: [
{
type: 'value',
name: '噪声',
name: '噪声(dB)',
nameTextStyle: {
color: '#000000'
},
@ -635,154 +578,71 @@ export default {
series: [
{
name: '噪声',
connectNulls: true, //
connectNulls: true,
type: 'line',
smooth: true, //线
showAllSymbol: true, //
symbol: 'circle', //
symbolSize: 10, //
// itemStyle: {
// color: "#058cff",
// },
// lineStyle: {
// color: "#058cff",
// },
// areaStyle: {
// color: "rgba(5,140,255, 0.2)",
// },
smooth: true,
showAllSymbol: true,
symbol: 'circle',
symbolSize: 10,
data: data.map(e => e.noise)
},
}
]
}
// let option5 = {
// title: {
// text: this.selectMonitorName + ' 线',
// x: 'center'
// },
// grid: {
// top: '15%',
// bottom: '10%',
// left: '10%',
// right: '3%'
// },
// tooltip: {
// trigger: 'axis',
// axisPointer: {
// type: 'shadow',
// label: {
// show: true
// }
// }
// },
// dataZoom: [{
// type: 'slider'
// }],
// legend: {
// right: 0
// },
// xAxis: {
// data: data.map(e => e.recodeTime),
// axisLine: {
// show: true, //X线
// lineStyle: {
// color: '#000000'
// }
// },
// axisTick: {
// show: true //X
// },
// axisLabel: {
// show: true,
// textStyle: {
// color: '#000000' //X
// }
// }
// },
// yAxis: [
// {
// type: 'value',
// name: '',
// nameTextStyle: {
// color: '#000000'
// },
// splitLine: {
// show: false
// },
// axisTick: {
// show: true
// },
// axisLine: {
// show: true,
// lineStyle: {
// color: '#000000'
// }
// },
// axisLabel: {
// show: true,
// textStyle: {
// color: '#000000'
// }
// }
// }
// ],
// series: [
// {
// name: '',
// type: 'line',
// smooth: true, //线
// showAllSymbol: true, //
// symbol: 'circle', //
// symbolSize: 10, //
// // itemStyle: {
// // color: "#058cff",
// // },
// // lineStyle: {
// // color: "#058cff",
// // },
// // areaStyle: {
// // color: "rgba(5,140,255, 0.2)",
// // },
// data: data.map(e => e.concentration)
// },
// ]
// }
};
this.$refs.Chart4.setData(option);
},
this.$refs.Chart1.setData(option1)
this.$refs.Chart2.setData(option2)
// this.$refs.Chart3.setData(option3)
this.$refs.Chart4.setData(option4)
// this.$refs.Chart5.setData(option5)
echarts.connect(this.$refs.Chart1.chart, this.$refs.Chart2.chart, this.$refs.Chart4.chart)
this.$refs.Chart1.chart.on('datazoom', (e) => {
option2.dataZoom[0].start = e.start
option2.dataZoom[0].end = e.end
this.$refs.Chart2.setData(option2)
option4.dataZoom[0].start = e.start
option4.dataZoom[0].end = e.end
this.$refs.Chart4.setData(option4)
})
this.$refs.Chart2.chart.on('datazoom', (e) => {
option1.dataZoom[0].start = e.start
option1.dataZoom[0].end = e.end
this.$refs.Chart1.setData(option1)
option4.dataZoom[0].start = e.start
option4.dataZoom[0].end = e.end
this.$refs.Chart4.setData(option4)
})
this.$refs.Chart4.chart.on('datazoom', (e) => {
option2.dataZoom[0].start = e.start
option2.dataZoom[0].end = e.end
this.$refs.Chart2.setData(option2)
option1.dataZoom[0].start = e.start
option1.dataZoom[0].end = e.end
this.$refs.Chart4.setData(option1)
})
//
linkCharts(chartRefs) {
if (chartRefs.length < 2) return;
//
const charts = chartRefs.map(ref => this.$refs[ref].chart);
echarts.connect(...charts);
//
chartRefs.forEach((ref, index) => {
this.$refs[ref].chart.on('datazoom', (e) => {
chartRefs.forEach((otherRef, otherIndex) => {
if (index !== otherIndex) {
//
this.$refs[otherRef].chart.dispatchAction({
type: 'dataZoom',
start: e.start,
end: e.end
});
}
});
});
});
}
}
}
</script>
<style scoped>
/* 单个图表样式type=5温度 或 type=7噪声 */
.chart-single {
width: 100%;
height: 60vh;
margin: 20px 0;
}
/* 双图表样式type=6温湿度 */
.chart-half {
width: 50%;
height: 45vh;
display: inline-block;
margin: 10px 0;
}
/* 提示信息样式 */
.no-data-tip {
text-align: center;
padding: 60px 20px;
color: #999;
font-size: 16px;
}
/* 保留原有样式以防兼容性问题 */
.chart1 {
width: 50%;
height: 40vh;

Loading…
Cancel
Save