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

465 lines
14 KiB
Vue
Raw Normal View History

2024-10-21 19:00:52 +08:00
<!-- 实时数据 - 谐波频谱页面 -->
2024-07-22 10:35:01 +08:00
<template>
2024-10-14 20:39:01 +08:00
<div class="realtrend" v-loading="loading">
2024-10-21 19:00:52 +08:00
<el-tabs type="border-card" v-if="tabsList.length != 0" v-model="activeName" @tab-click="handleClick">
2024-07-31 15:23:48 +08:00
<el-tab-pane v-for="(item, index) in tabsList" :label="item.groupName" :name="index" :key="index">
2024-10-14 20:39:01 +08:00
<div>
2024-07-31 10:42:04 +08:00
<div class="realtrend_top">
2024-10-14 15:09:58 +08:00
<!-- <div class="thead">
2024-07-31 10:42:04 +08:00
<ul v-for="(table, tableIndex) in newTableList" :key="tableIndex">
<li>
{{ table[0].value }}
</li>
</ul>
</div>
2024-10-14 15:09:58 +08:00
<div class="table">
2024-07-31 10:42:04 +08:00
<ul v-for="(table, tableIndex) in newTableList" :key="tableIndex">
<span v-for="(key, keys) in table">
<li v-if="keys != 0">
{{ key?.value }}
2024-10-14 20:39:01 +08:00
</li>
2024-07-31 10:42:04 +08:00
</span>
</ul>
2024-10-14 15:09:58 +08:00
</div> -->
2024-10-14 20:39:01 +08:00
<div class="realtrend_table" v-if="Object.keys(tableData).length != 0">
2024-10-14 15:09:58 +08:00
<div class="thead_left">
<p>次数</p>
<p>{{ item.groupName }}</p>
</div>
<div class="thead_right">
<div class="right_cell" v-for="(value, key, index) in tableData" :key="index">
2024-10-21 19:00:52 +08:00
<p v-if="item.groupName.includes('间谐波') && index != 50">{{ index + 0.5 }}</p>
<p v-else>
2024-10-14 20:39:01 +08:00
<span>{{ String(key).replace('data', ' ') }}</span>
2024-10-14 15:09:58 +08:00
</p>
2024-10-14 20:39:01 +08:00
<p>
2024-10-14 15:09:58 +08:00
<span
v-if="
String(key).includes('data') &&
String(key) != 'dataLevel' &&
String(key) != 'dataTime'
"
>
{{ value }}
</span>
</p>
</div>
</div>
2024-07-31 10:42:04 +08:00
</div>
</div>
2024-10-14 20:39:01 +08:00
<div class="tab_info" v-if="Object.keys(tableData).length != 0">
2024-07-31 10:42:04 +08:00
<div class="charts">
<MyEchart ref="barCharts" :options="echartsData" :isInterVal="true"></MyEchart>
2024-07-31 10:42:04 +08:00
</div>
</div>
2024-10-14 20:39:01 +08:00
<el-empty v-else style="margin: 0 auto" />
2024-07-31 10:42:04 +08:00
</div>
</el-tab-pane>
2024-07-22 10:35:01 +08:00
</el-tabs>
2024-10-21 19:00:52 +08:00
<!-- <el-empty v-else/> -->
2024-07-22 10:35:01 +08:00
</div>
</template>
<script lang="ts" setup>
2024-10-14 20:39:01 +08:00
import { ref, onMounted, reactive, nextTick, defineEmits } from 'vue'
2024-07-22 10:35:01 +08:00
import { VxeGridProps, VxeGridPropTypes } from 'vxe-table'
import { defaultAttribute } from '@/components/table/defaultAttribute'
import MyEchart from '@/components/echarts/MyEchart.vue'
2024-07-31 10:42:04 +08:00
import { getDeviceTrendDataGroup, getDeviceTrendData } from '@/api/cs-device-boot/EquipmentDelivery.ts'
2024-07-31 15:23:48 +08:00
const activeName = ref(0)
2024-10-14 20:39:01 +08:00
const emit = defineEmits(['changeTrendType'])
2024-07-31 10:42:04 +08:00
const tableList: any = []
2024-07-22 10:35:01 +08:00
interface RowVO {
[key: string]: any
}
//谐波电压含有率
const gridOptions = ref<VxeGridProps<RowVO>>({
border: true,
showOverflow: true,
showHeader: false,
columns: [],
data: [],
columnConfig: {
resizable: true
},
align: 'center'
})
gridOptions.value = { ...defaultAttribute, ...gridOptions.value }
2024-07-31 10:42:04 +08:00
2024-10-21 19:00:52 +08:00
const tabsList: any = ref([])
const loading: any = ref(true)
2024-07-31 10:42:04 +08:00
//接收参数
const params = ref({})
2024-10-15 15:30:01 +08:00
const open = async (val: any) => {
2024-10-14 20:39:01 +08:00
loading.value = true
2024-10-21 19:00:52 +08:00
//获取指标tab
// await getDeviceTrendDataGroup().then(res => {
// tabsList.value = res.data.reverse()
// if (tabsList.value.length != 0) {
// // activeName.value = tabsList.value[0]?.id
// activeName.value = val.activeTrendName || 0
// }
// params.value = { groupId: tabsList.value[activeName.value]?.id, ...val }
// })
tabsList.value = [
{
id: '6d5470f509ca271d7108a86e83bb283f',
groupName: '谐波电压含有率',
thdDataVOS: null,
thdDataTdVODatas: null
},
{
id: '8dc260f16280184e2b57d26668dc00b1',
groupName: '谐波电流幅值',
thdDataVOS: null,
thdDataTdVODatas: null
},
{
id: 'ae31115b83f02f03a0d3bd65cb017121',
groupName: '间谐波电压含有率',
thdDataVOS: null,
thdDataTdVODatas: null
2024-07-31 10:42:04 +08:00
}
2024-10-21 19:00:52 +08:00
]
if (tabsList.value.length != 0) {
// activeName.value = tabsList.value[0]?.id
activeName.value = val.activeTrendName || 0
}
params.value = { groupId: tabsList.value[activeName.value]?.id, ...val }
2024-10-14 20:39:01 +08:00
init()
2024-10-21 19:00:52 +08:00
setTimeout(() => {
loading.value = false
}, 1500)
2024-07-31 10:42:04 +08:00
return
}
//根据指标tab查询实时趋势
//echarts数据
const chartsData: any = ref([])
const chartsYxiasData: any = ref([])
2024-07-22 10:35:01 +08:00
2024-10-14 15:09:58 +08:00
const echartsData: any = ref([])
const barCharts = ref()
2024-07-31 10:42:04 +08:00
2024-07-22 10:35:01 +08:00
//加载echarts
const init = () => {
2024-10-14 20:39:01 +08:00
let trendData: any = []
for (let key in tableData.value) {
trendData.push({
name: key,
value: tableData.value[key],
count: String(key).replace('data', '')
})
}
let gbData: any = []
for (let key in limitData.value) {
gbData.push({
name: key,
value: limitData.value[key]
})
}
2024-07-31 10:42:04 +08:00
let xAxisList: any = []
chartsData.value.map((item: any, index: any) => {
2024-07-31 15:23:48 +08:00
chartsYxiasData.value.map((vv: any, vvs: any) => {
2024-07-31 10:42:04 +08:00
if (item.phase == vv.phase) {
2024-07-31 15:23:48 +08:00
if (vvs == 0) {
vv.gbList.push(item.internationalValue)
}
2024-07-31 10:42:04 +08:00
vv.phaseList.push(item.statisticalData)
}
})
xAxisList.push(item.frequency + '次')
})
xAxisList = [...new Set(xAxisList)]
echartsData.value = {
options: {
// backgroundColor: '#0f375f',
2024-10-21 19:00:52 +08:00
// dataZoom: [
// {
// type: 'inside',
// height: 13,
// start: 0,
// bottom: '20px',
// end: 20
// },
// {
// start: 0,
// height: 13,
// bottom: '20px',
// end: 20
// }
// ],
2024-07-31 10:42:04 +08:00
grid: {
2024-07-31 15:23:48 +08:00
top: '14%',
2024-09-27 16:22:34 +08:00
bottom: '70px', //也可设置left和right设置距离来控制图表的大小
2024-07-31 10:42:04 +08:00
left: '3%',
right: '5%'
},
2024-09-14 10:32:01 +08:00
// tooltip: {
// trigger: 'axis',
// axisPointer: {
// type: 'cross',
// label: {
// show: false
// }
// }
// },
2024-07-31 10:42:04 +08:00
legend: {
data: [],
itemGap: 15,
type: 'scroll', // 开启滚动分页
// orient: 'vertical', // 垂直排列
right: '3%', // 位置调整
top: 0,
bottom: 20,
width: 400,
height: 50
},
xAxis: {
name: '次数',
2024-10-14 20:39:01 +08:00
data: trendData.map((item: any) => {
2024-10-21 19:00:52 +08:00
return item.count + '次'
2024-10-14 20:39:01 +08:00
}),
2024-07-31 10:42:04 +08:00
axisLine: {
show: true, //隐藏X轴轴线
lineStyle: {
color: '#000'
}
},
axisTick: {
show: true //隐藏X轴刻度
},
axisPointer: {
type: 'shadow'
},
axisLabel: {
show: true,
textStyle: {
color: '#000' //X轴文字颜色
}
}
},
yAxis: [
{
type: 'value',
2024-10-14 20:39:01 +08:00
name: '',
2024-07-31 10:42:04 +08:00
splitLine: {
show: false
},
axisTick: {
show: true
},
axisLine: {
show: true,
lineStyle: {
color: '#000'
}
}
}
],
series: []
}
}
2024-10-14 20:39:01 +08:00
let list: any = [
gbData.map((item: any) => {
return item.value
}),
trendData.map((item: any) => {
return item.value
})
]
let legendList = ['国标限值', tabsList.value[activeName.value]?.groupName]
echartsData.value.options.legend.data = legendList
2024-07-31 10:42:04 +08:00
list.map((item: any, index: any) => {
echartsData.value.options.series.push({
2024-10-14 20:39:01 +08:00
name: legendList[index],
2024-07-31 10:42:04 +08:00
type: 'bar',
barMaxWidth: 16, //使用的 y 轴的 index在单个图表实例中存在多个 y轴的时候有用
itemStyle: {
// normal: {
barBorderRadius: [3, 3, 0, 0],
// color: '#00CC99'
// }e
color: colorList[index]
},
2024-10-14 20:39:01 +08:00
data: item
2024-07-31 10:42:04 +08:00
})
})
2024-10-14 15:09:58 +08:00
if (barCharts.value) {
barCharts.value[activeName.value]?.initChart()
}
2024-07-31 15:23:48 +08:00
return
2024-07-22 10:35:01 +08:00
}
const handleClick = (tab: any, event: any) => {
2024-07-31 15:23:48 +08:00
params.value.groupId = tabsList.value[tab.index].id
2024-10-14 20:39:01 +08:00
emit('changeTrendType', tab.index)
activeName.value = tab.index
2024-07-22 10:35:01 +08:00
init()
}
2024-10-14 15:09:58 +08:00
//获取mqtt传送的实时数据
const mqttMessage: any = ref()
const tableData: any = ref({})
2024-10-21 19:00:52 +08:00
const colorList = ['#DAA520', '#2E8B57', '#A52a2a', '#000']
2024-10-14 15:09:58 +08:00
const setRealTrendData = (val: any) => {
2024-10-21 19:00:52 +08:00
console.log(val, '谐波频谱')
2024-10-14 20:39:01 +08:00
tableData.value = {}
2024-10-14 15:09:58 +08:00
mqttMessage.value = val
for (let key in val) {
if (String(key).includes('data') && String(key) != 'dataLevel' && String(key) != 'dataTime') {
tableData.value[key] = val[key]
2024-10-14 20:39:01 +08:00
delete tableData.value.data1
}
}
2024-10-21 19:00:52 +08:00
if (tableData.value) {
init()
} else {
emit('changeTrendType', activeName.value)
}
2024-10-14 20:39:01 +08:00
}
//获取国标限值
const limitData: any = ref()
const setOverLimitData = (val: any) => {
limitData.value = {}
for (let key in val) {
if (String(key).includes('uharm')) {
limitData.value[key] = val[key]
2024-10-14 15:09:58 +08:00
}
}
}
onMounted(() => {})
2024-10-14 20:39:01 +08:00
defineExpose({ open, setRealTrendData, setOverLimitData })
2024-07-22 10:35:01 +08:00
</script>
<style lang="scss" scoped>
.realtrend {
width: 100%;
height: 100%;
2024-09-27 16:22:34 +08:00
2024-07-31 10:42:04 +08:00
.realtrend_top {
2024-07-22 10:35:01 +08:00
width: 100%;
height: auto;
2024-07-31 10:42:04 +08:00
display: flex;
justify-content: space-between;
align-items: center;
2024-09-27 16:22:34 +08:00
2024-07-31 10:42:04 +08:00
.table {
flex: 1;
// min-height: 80px;
cursor: pointer;
min-height: 90px;
max-height: 170px;
border: 1px solid #eee;
overflow-x: auto;
overflow-y: hidden;
position: relative;
2024-09-27 16:22:34 +08:00
2024-07-31 10:42:04 +08:00
ul {
width: auto;
2024-07-22 10:35:01 +08:00
height: 40px;
display: flex;
2024-09-27 16:22:34 +08:00
2024-07-31 10:42:04 +08:00
li {
flex: none;
width: 100px;
2024-07-22 10:35:01 +08:00
line-height: 40px;
2024-07-31 10:42:04 +08:00
border: 1px solid #eee;
2024-07-22 10:35:01 +08:00
text-align: center;
2024-07-31 10:42:04 +08:00
list-style: none;
2024-07-22 10:35:01 +08:00
}
2024-07-31 10:42:04 +08:00
}
2024-09-27 16:22:34 +08:00
2024-07-31 10:42:04 +08:00
ul:nth-child(1) {
li {
font-weight: 800;
background: #f4f6f9;
2024-07-22 10:35:01 +08:00
}
}
}
2024-09-27 16:22:34 +08:00
// .table::-webkit-scrollbar {
// display: none;
// }
2024-10-14 15:09:58 +08:00
.realtrend_table {
width: 100%;
2024-10-14 20:39:01 +08:00
height: auto;
max-height: 150px;
2024-10-14 15:09:58 +08:00
display: flex;
2024-10-14 20:39:01 +08:00
border: 2px solid #eee;
cursor: pointer;
2024-10-14 15:09:58 +08:00
.thead_left {
2024-10-14 20:39:01 +08:00
width: 150px;
2024-10-14 15:09:58 +08:00
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
line-height: 50px;
2024-10-14 20:39:01 +08:00
font-weight: 800;
p {
width: 100%;
height: 100%;
text-align: center;
border: 1px solid #eee;
line-height: 50px;
margin: 0 !important;
}
2024-10-14 15:09:58 +08:00
}
.thead_right {
flex: 1;
align-items: center;
overflow-x: auto;
2024-10-14 20:39:01 +08:00
overflow-y: hidden;
2024-10-14 15:09:58 +08:00
display: flex;
.right_cell {
width: 100%;
display: flex;
flex-direction: column;
p {
flex: none;
2024-10-21 19:00:52 +08:00
width: 60px;
2024-10-14 15:09:58 +08:00
height: 100%;
2024-10-14 20:39:01 +08:00
text-align: center;
border: 1px solid #eee;
2024-10-21 19:00:52 +08:00
line-height: 40px;
2024-10-14 20:39:01 +08:00
margin: 0 !important;
}
p:nth-child(1) {
font-weight: 800;
2024-10-14 15:09:58 +08:00
}
}
}
}
2024-07-22 10:35:01 +08:00
}
}
2024-09-27 16:22:34 +08:00
2024-07-22 10:35:01 +08:00
.reverse-table .vxe-body--row .vxe-body--column:first-child {
background-color: #f8f8f9;
}
2024-09-27 16:22:34 +08:00
2024-07-22 10:35:01 +08:00
::v-deep .vxe-table--render-wrapper {
height: 90px !important;
max-height: 90px !important;
overflow-x: auto !important;
min-height: 0 !important;
}
2024-09-27 16:22:34 +08:00
2024-07-22 10:35:01 +08:00
::v-deep .body--wrapper {
height: 90px !important;
max-height: 90px !important;
min-height: 0 !important;
}
2024-09-27 16:22:34 +08:00
2024-07-22 10:35:01 +08:00
.tab_info {
width: 100%;
height: calc(100vh - 450px);
2024-09-27 16:22:34 +08:00
2024-07-22 10:35:01 +08:00
// overflow: auto;
// padding-bottom: 20px;
.charts {
width: 100%;
margin-top: 10px;
2024-09-27 16:22:34 +08:00
height: calc(100vh - 600px);
2024-07-22 10:35:01 +08:00
}
}
</style>