2025-06-24 19:52:11 +08:00
|
|
|
|
|
|
|
|
<template>
|
2025-09-22 17:57:30 +08:00
|
|
|
<el-card shadow="always" class="common-card-container time-range-card" style="margin-top:20px">
|
|
|
|
|
<div slot="header" class="time-range-header">
|
|
|
|
|
<span class="card-title">
|
|
|
|
|
<el-button-group class="ems-btns-group">
|
|
|
|
|
<el-button v-for="(item,index) in btnList" :key="index+'flqxcBtns'" size="mini" :class="{'activeBtn' : activeBtn === item.id}" @click="changeDataType(item.id)">{{item.name}}</el-button>
|
2025-06-24 19:52:11 +08:00
|
|
|
</el-button-group>
|
2025-09-22 17:57:30 +08:00
|
|
|
</span>
|
|
|
|
|
<date-range-select ref="dateRangeSelect" @updateDate="updateDate"/>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="card-main" v-loading="loading">
|
|
|
|
|
<div id="pcsEchart" style="height: 310px;"></div>
|
2025-06-24 19:52:11 +08:00
|
|
|
</div>
|
2025-09-22 17:57:30 +08:00
|
|
|
</el-card>
|
2025-06-24 19:52:11 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import * as echarts from 'echarts'
|
|
|
|
|
import resize from "@/mixins/ems/resize";
|
2025-07-09 00:03:52 +08:00
|
|
|
import getQuerySiteId from "@/mixins/ems/getQuerySiteId";
|
|
|
|
|
import { getPCSData, getPcsNameList} from '@/api/ems/dzjk'
|
|
|
|
|
import {formatDate} from "@/filters/ems";
|
2025-09-22 17:57:30 +08:00
|
|
|
import DateRangeSelect from "@/components/Ems/DateRangeSelect/index.vue";
|
2025-06-24 19:52:11 +08:00
|
|
|
export default {
|
|
|
|
|
name:'DzjkTjbbPcsqx',
|
2025-09-22 17:57:30 +08:00
|
|
|
components: {DateRangeSelect},
|
2025-07-09 00:03:52 +08:00
|
|
|
mixins: [resize,getQuerySiteId],
|
2025-06-24 19:52:11 +08:00
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
pickerOptions:{
|
|
|
|
|
disabledDate(time) {
|
|
|
|
|
return time.getTime() > Date.now();
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
dateRange:[],
|
|
|
|
|
loading:false,
|
2025-07-09 00:03:52 +08:00
|
|
|
activeBtn:'1',
|
2025-06-24 19:52:11 +08:00
|
|
|
btnList:[
|
2025-09-14 23:33:53 +08:00
|
|
|
{name:'有功功率',id:'1',attr:['activePower'],source:['有功功率']},
|
|
|
|
|
{name:'无功功率',id:'2',attr:['reactivePower'],source:['无功功率']},
|
|
|
|
|
{name:'三相电流',id:'3',attr:['uCurrent','vCurrent','wCurrent'],source:['u电流','v电流','w电流'],type:'bar'},
|
2025-06-24 19:52:11 +08:00
|
|
|
],
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
changeDataType(id){
|
|
|
|
|
if(id !== this.activeBtn){
|
|
|
|
|
console.log('点击了不同的菜单,更新数据')
|
|
|
|
|
this.activeBtn=id;
|
2025-07-09 00:03:52 +08:00
|
|
|
this.getData()
|
2025-06-24 19:52:11 +08:00
|
|
|
}
|
|
|
|
|
},
|
2025-09-22 17:57:30 +08:00
|
|
|
// 更新时间范围 重置图表
|
|
|
|
|
updateDate(data){
|
|
|
|
|
this.dateRange=data || []
|
2025-06-24 19:52:11 +08:00
|
|
|
this.getData()
|
|
|
|
|
},
|
|
|
|
|
getData(){
|
2025-09-14 23:33:53 +08:00
|
|
|
const {siteId,activeBtn}=this;
|
2025-07-09 00:03:52 +08:00
|
|
|
const [start='',end='']=(this.dateRange || [])
|
2025-07-09 23:52:19 +08:00
|
|
|
this.loading=true;
|
2025-06-24 19:52:11 +08:00
|
|
|
//接口调用完成之后 设置图表、结束loading
|
2025-09-14 23:33:53 +08:00
|
|
|
getPCSData({siteId,startTime:formatDate(start),endTime:formatDate(end),dataType:activeBtn}).then(response => {
|
2025-07-09 00:03:52 +08:00
|
|
|
this.setOption(response?.data || [])
|
|
|
|
|
}).finally(()=>{this.loading=false;})
|
2025-06-24 19:52:11 +08:00
|
|
|
},
|
2025-09-16 18:20:48 +08:00
|
|
|
compareDate(date1,date2){
|
|
|
|
|
console.log('比较时间',date1,date2)
|
|
|
|
|
// 年2025-09/天2025-09-15/时2025-09-15/10:00
|
|
|
|
|
if(date1.indexOf(':') > -1 && date2.indexOf(':') > -1){
|
|
|
|
|
return parseInt(date1) - parseInt(date2)
|
|
|
|
|
}
|
|
|
|
|
const [date1_Y='',date1_M='',date1_D=''] = date1.split('-')//根据空格区分[年月日,小时]
|
|
|
|
|
const [date2_Y='',date2_M='',date2_D=''] = date2.split('-')//根据空格区分[年月日,小时]
|
|
|
|
|
return (date1_Y === date2_Y && date1_M === date2_M && date1_D - date2_D) || (date1_Y === date2_Y && date1_M - date2_M) || date1_Y - date2_Y
|
|
|
|
|
},
|
2025-07-09 00:03:52 +08:00
|
|
|
setOption(data) {
|
|
|
|
|
const ele = this.btnList.find((item)=>{return item.id === this.activeBtn})
|
2025-09-14 23:33:53 +08:00
|
|
|
const sourceBase = JSON.parse(JSON.stringify(ele.source))
|
2025-09-16 18:20:48 +08:00
|
|
|
// sourceBase={name:'堆平均维度',id:'1',attr:['temp'],source:['有功功率']},
|
2025-09-14 23:33:53 +08:00
|
|
|
const source=[]
|
|
|
|
|
const sourceTop = ['日期']
|
2025-09-16 18:20:48 +08:00
|
|
|
let map={},mapArr=[]
|
|
|
|
|
// 生成所有{日期:[],日期:[]}格式的对象和所有包含所有日期的[日期1,日期2...]
|
|
|
|
|
data.forEach((item)=>{
|
|
|
|
|
item.dataList.forEach((inner)=>{
|
|
|
|
|
// 日期格式
|
|
|
|
|
// 年2025-09/天2025-09-15/时2025-09-15/10:00
|
|
|
|
|
// 所有数据的日期格式一致
|
|
|
|
|
if(!map[inner.statisDate]) {
|
|
|
|
|
map[inner.statisDate] = []
|
|
|
|
|
mapArr.push(inner.statisDate)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
data.forEach((item,itemIndex)=>{
|
|
|
|
|
const dataTimeList = item.dataList.map(i =>i.statisDate)
|
|
|
|
|
const noDataTime = mapArr.filter(i=>!dataTimeList.includes(i))
|
|
|
|
|
sourceBase.forEach((outer,outerIndex)=>{
|
2025-09-14 23:33:53 +08:00
|
|
|
sourceTop.push(`${item.deviceId}-${outer}`)
|
2025-09-16 18:20:48 +08:00
|
|
|
noDataTime.forEach(i=>map[i].push(''))
|
2025-09-14 23:33:53 +08:00
|
|
|
item.dataList.forEach((inner,innerIndex)=>{
|
2025-09-16 18:20:48 +08:00
|
|
|
map[inner.statisDate].push(inner[ele.attr[outerIndex]])
|
2025-09-14 23:33:53 +08:00
|
|
|
})
|
2025-07-09 00:03:52 +08:00
|
|
|
})
|
|
|
|
|
})
|
2025-09-16 18:20:48 +08:00
|
|
|
mapArr = mapArr.sort((a,b)=>this.compareDate(a,b))
|
|
|
|
|
mapArr.forEach(item=>{
|
|
|
|
|
source.push([item,...map[item]])
|
|
|
|
|
})
|
2025-09-14 23:33:53 +08:00
|
|
|
source.unshift(sourceTop)
|
2025-09-16 18:20:48 +08:00
|
|
|
console.log('map=',map)
|
|
|
|
|
console.log('mapArr=',mapArr)
|
2025-09-14 23:33:53 +08:00
|
|
|
console.log('========',source)
|
2025-06-24 19:52:11 +08:00
|
|
|
this.chart.setOption({
|
2025-08-13 14:51:26 +08:00
|
|
|
grid: {
|
|
|
|
|
containLabel: true
|
|
|
|
|
},
|
2025-06-24 19:52:11 +08:00
|
|
|
legend: {
|
|
|
|
|
left: 'center',
|
2025-08-13 14:51:26 +08:00
|
|
|
bottom: '15',
|
2025-06-24 19:52:11 +08:00
|
|
|
},
|
|
|
|
|
tooltip: {
|
|
|
|
|
trigger: 'axis',
|
|
|
|
|
axisPointer: { // 坐标轴指示器,坐标轴触发有效
|
|
|
|
|
type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
textStyle:{
|
|
|
|
|
color:"#333333",
|
|
|
|
|
},
|
|
|
|
|
xAxis: {
|
2025-07-09 00:03:52 +08:00
|
|
|
type: 'category',
|
2025-06-24 19:52:11 +08:00
|
|
|
},
|
|
|
|
|
yAxis: {
|
|
|
|
|
type: 'value',
|
|
|
|
|
},
|
2025-07-09 00:03:52 +08:00
|
|
|
dataset: {source},
|
2025-09-14 23:33:53 +08:00
|
|
|
series:source[0].slice(1).map(item=>{
|
|
|
|
|
return {
|
|
|
|
|
type:ele.type || 'scatter'
|
|
|
|
|
}
|
|
|
|
|
})
|
2025-07-09 00:03:52 +08:00
|
|
|
|
|
|
|
|
},true)
|
2025-06-24 19:52:11 +08:00
|
|
|
},
|
|
|
|
|
initChart() {
|
|
|
|
|
this.chart = echarts.init(document.querySelector('#pcsEchart'));
|
2025-07-09 00:03:52 +08:00
|
|
|
},
|
|
|
|
|
init(){
|
2025-09-22 17:57:30 +08:00
|
|
|
this.$nextTick(()=>{
|
|
|
|
|
this.initChart()
|
|
|
|
|
this.$refs.dateRangeSelect.init()
|
|
|
|
|
})
|
2025-06-24 19:52:11 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
beforeDestroy() {
|
|
|
|
|
if (!this.chart) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
this.chart.dispose()
|
|
|
|
|
this.chart = null
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
</script>
|