Files
admin-govern/src/views/govern/device/control/tabs/components/harmonicSpectrum.vue

282 lines
9.7 KiB
Vue
Raw Normal View History

2024-07-23 17:28:31 +08:00
<!-- 谐波频谱 -->
2024-07-22 10:35:01 +08:00
<template>
2024-09-27 16:22:34 +08:00
<div class="harmonic" :style="heightTop">
2024-07-23 17:28:31 +08:00
<div class="harmonic_select">
2024-09-27 16:22:34 +08:00
<el-form :model="searchForm" id="history_select">
2024-07-23 17:28:31 +08:00
<el-form-item label="稳态指标">
2024-09-27 16:22:34 +08:00
<el-select multiple collapse-tags collapse-tags-tooltip v-model="searchForm.index"
placeholder="请选择统计指标">
<el-option v-for="item in indexOptions" :key="item.id" :label="item.name"
:value="item.id"></el-option>
2024-07-23 17:28:31 +08:00
</el-select>
</el-form-item>
2024-09-27 16:22:34 +08:00
<el-button type="primary" :loading="loading" @click="init">查询</el-button>
2024-07-23 17:28:31 +08:00
</el-form>
2024-09-27 16:22:34 +08:00
2024-07-23 17:28:31 +08:00
</div>
2024-08-01 15:01:32 +08:00
<div class="harmonic_body" v-loading="loading">
2024-09-27 16:22:34 +08:00
<div class="harmonic_body_charts" :style="{ height: height }" v-for="(item, index) in chartsList"
:key="index">
2024-08-01 15:01:32 +08:00
<p class="charts_title">
{{
indexOptions.find((item: any) => {
return item.id == searchForm.index[index]
})?.name
}}
</p>
<MyEchart :ref="setChildRef(index)" :options="item.echartsData"></MyEchart>
2024-07-23 17:28:31 +08:00
</div>
</div>
2024-07-22 10:35:01 +08:00
</div>
</template>
<script lang="ts" setup>
2024-07-23 17:28:31 +08:00
import { ref, onMounted, watch } from 'vue'
import { queryByCode, queryByid, queryCsDictTree } from '@/api/system-boot/dictTree'
import { queryStatistical } from '@/api/system-boot/csstatisticalset'
import MyEchart from '@/components/echarts/MyEchart.vue'
2024-07-31 10:42:04 +08:00
import { getDeviceHarmonicSpectrumData, getRealTimeTableList } from '@/api/cs-device-boot/EquipmentDelivery.ts'
2024-09-27 16:22:34 +08:00
import { mainHeight } from '@/utils/layout'
2024-10-10 09:56:34 +08:00
import { yMethod } from '@/utils/echartMethod'
2024-08-01 15:01:32 +08:00
const searchForm: any = ref({})
2024-07-23 17:28:31 +08:00
searchForm.value = {
index: []
}
//统计指标
const indexOptions: any = ref([])
const legendDictList: any = ref([])
queryByCode('portable-harmonic').then(res => {
queryCsDictTree(res.data.id).then(item => {
indexOptions.value = item.data
searchForm.value.index[0] = indexOptions.value[0].id
})
queryStatistical(res.data.id).then(vv => {
legendDictList.value = vv.data
})
})
2024-09-27 16:22:34 +08:00
const heightTop = mainHeight(275)
let height: any = mainHeight(275).height
2024-07-31 10:42:04 +08:00
//谐波频谱参数
2024-08-01 15:01:32 +08:00
const params: any = ref({})
2024-07-31 10:42:04 +08:00
const getHarmonicSpectrumParams = (val: any) => {
params.value = val
2024-08-01 15:01:32 +08:00
init()
2024-07-31 10:42:04 +08:00
}
2024-08-01 15:01:32 +08:00
const chartsList: any = ref([])
const loading = ref(false)
// 为每个子组件实例设置ref
const setChildRef = (index: any) => {
return `child-${index}`
}
const childRefs = {}
2024-07-23 17:28:31 +08:00
const init = () => {
2024-08-01 15:01:32 +08:00
loading.value = true
params.value.list = []
searchForm.value.index.map((item: any) => {
params.value.list.push({ statisticalId: item })
2024-07-23 17:28:31 +08:00
})
2024-08-01 15:01:32 +08:00
//查询谐波频谱
getDeviceHarmonicSpectrumData(params.value).then(res => {
2024-10-10 09:56:34 +08:00
res.data.length > 3 ? height = mainHeight(275, 3).height : height = mainHeight(275, res.data.length).height
2024-08-01 15:01:32 +08:00
chartsList.value = res.data
//数据根据相别组装成新数组
chartsList.value.map((item: any) => {
item.countList = []
item.thdDataVOS = item.thdDataVOS.reduce((acc: any, current: any) => {
const existing = acc.find((redu: any) => redu.phase == current.phase)
if (existing) {
existing.list.push(current)
} else {
acc.push({
phase: current.phase,
list: [current]
})
}
return acc
}, [])
return
})
2024-07-23 17:28:31 +08:00
2024-09-27 16:22:34 +08:00
2024-08-01 15:01:32 +08:00
//循环渲染图表
chartsList.value &&
chartsList.value.map((item: any, index: any) => {
const refName = setChildRef(index)
childRefs[refName] = ref(null) // 初始化ref
item.echartsData = {
options: {
title: [
{
left: '10%',
top: 0
// text: item.showName
2024-07-23 17:28:31 +08:00
}
2024-08-01 15:01:32 +08:00
],
2024-09-27 16:22:34 +08:00
// grid: {
// top: '16%',
// bottom: '15%', //也可设置left和right设置距离来控制图表的大小
// left: '3%',
// right: '4%'
// },
2024-08-01 15:01:32 +08:00
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
label: {
show: false
}
2024-07-23 17:28:31 +08:00
}
},
2024-08-01 15:01:32 +08:00
legend: {
data: [],
top: '2%',
right: '2%'
2024-07-23 17:28:31 +08:00
},
2024-08-01 15:01:32 +08:00
xAxis: {
name: '次数',
data: [],
axisLine: {
show: true, //隐藏X轴轴线
lineStyle: {
color: '#000'
}
},
axisTick: {
show: true //隐藏X轴刻度
},
axisPointer: {
type: 'shadow'
},
axisLabel: {
show: true,
textStyle: {
color: '#000' //X轴文字颜色
}
},
boundaryGap: false
2024-07-23 17:28:31 +08:00
},
2024-10-10 09:56:34 +08:00
yAxis:
{
type: 'value',
name:
item.thdDataVOS.length != 0 &&
item.thdDataVOS[0].list &&
item.thdDataVOS[0].list[0].unit,
splitLine: {
show: false
},
axisTick: {
show: true
},
axisLine: {
show: true,
lineStyle: {
color: '#000'
2024-08-01 15:01:32 +08:00
}
2024-10-10 09:56:34 +08:00
},
splitNumber: 5,
minInterval: 1,
}
,
2024-08-01 15:01:32 +08:00
series: []
2024-07-23 17:28:31 +08:00
}
2024-08-01 15:01:32 +08:00
}
//横轴数据
item.echartsData.options.xAxis.data =
item.thdDataVOS.length != 0 &&
item.thdDataVOS[0].list &&
item.thdDataVOS[0].list.map((ss: any) => {
return ss.frequency + '次'
})
2024-10-10 09:56:34 +08:00
let aar: any = []
2024-08-01 15:01:32 +08:00
//y轴数据
item.thdDataVOS.map((vv: any) => {
item.echartsData.options.series.push({
name: vv.phase + '相',
2024-07-23 17:28:31 +08:00
type: 'line',
2024-08-01 15:01:32 +08:00
barMaxWidth: 24, //使用的 y 轴的 index在单个图表实例中存在多个 y轴的时候有用
2024-07-23 17:28:31 +08:00
itemStyle: {
// normal: {
barBorderRadius: [3, 3, 0, 0]
2024-08-01 15:01:32 +08:00
// color: '#00CC99'
// }e
2024-07-23 17:28:31 +08:00
},
2024-08-01 15:01:32 +08:00
data: vv.list.map((vvs: any) => {
2024-10-10 09:56:34 +08:00
aar.push(vvs.statisticalData)
2024-08-01 15:01:32 +08:00
return vvs.statisticalData
}),
2024-07-31 10:42:04 +08:00
smooth: true, // 这里设置平滑曲线
2024-07-23 17:28:31 +08:00
symbol: 'none' // 设置为 'none' 去掉折点小圆
2024-08-01 15:01:32 +08:00
})
//legend数据
item.echartsData.options.legend.data.push(vv.phase + '相')
})
2024-10-10 09:56:34 +08:00
let [min, max] = yMethod(aar)
item.echartsData.options.yAxis.max = max
item.echartsData.options.yAxis.min = min
2024-08-01 15:01:32 +08:00
})
loading.value = false
})
return
2024-07-23 17:28:31 +08:00
}
watch(
() => searchForm.value.index,
(val: any, oldval: any) => {
if (val && val.length != 0) {
2024-08-01 15:01:32 +08:00
// init()
2024-07-23 17:28:31 +08:00
}
},
{
deep: true,
immediate: true
}
)
2024-09-27 16:22:34 +08:00
onMounted(() => { })
2024-07-31 10:42:04 +08:00
defineExpose({ getHarmonicSpectrumParams })
2024-07-22 10:35:01 +08:00
</script>
<style lang="scss" scoped>
2024-07-23 17:28:31 +08:00
.harmonic {
width: 100%;
2024-09-27 16:22:34 +08:00
// height: 100%;
2024-07-23 17:28:31 +08:00
display: flex;
flex-direction: column;
position: relative;
2024-09-27 16:22:34 +08:00
2024-07-23 17:28:31 +08:00
.harmonic_select {
width: 50%;
height: 30px;
display: flex;
position: absolute;
2024-09-27 16:22:34 +08:00
top: -32px;
2024-07-23 17:28:31 +08:00
left: 0;
justify-content: flex-start;
2024-09-27 16:22:34 +08:00
2024-07-23 17:28:31 +08:00
.el-button {
margin-left: 10px;
}
}
2024-09-27 16:22:34 +08:00
2024-07-23 17:28:31 +08:00
.harmonic_body {
flex: 1;
overflow-y: auto;
2024-09-27 16:22:34 +08:00
// padding-bottom: 200px;
2024-07-23 17:28:31 +08:00
.harmonic_body_charts {
2024-09-27 16:22:34 +08:00
// margin: 15px 0;
2024-07-31 10:42:04 +08:00
border: 1px solid #eee;
2024-08-01 15:01:32 +08:00
position: relative;
2024-09-27 16:22:34 +08:00
2024-08-01 15:01:32 +08:00
.charts_title {
position: absolute;
top: 10px;
left: 10%;
font-size: 18px;
font-weight: 800;
}
2024-07-23 17:28:31 +08:00
}
}
2024-07-22 10:35:01 +08:00
}
</style>