diff --git a/src/views/ems/dzjk/tjbb/dcdqx/index.vue b/src/views/ems/dzjk/tjbb/dcdqx/index.vue index 1e9f208..dae643c 100644 --- a/src/views/ems/dzjk/tjbb/dcdqx/index.vue +++ b/src/views/ems/dzjk/tjbb/dcdqx/index.vue @@ -106,47 +106,53 @@ export default { this.setOption(response?.data || []) }).finally(()=>{this.loading=false;}) }, + 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 + }, setOption(data) { - - // [{ - // "deviceId": "PCS04", - // "dataList": [ - // { - // "statisDate": "2025-09-05", - // "activePower": null, - // "reactivePower": null, - // "uCurrent": 1.30, - // "vCurrent": 0.90, - // "wCurrent": 1.00, - // "deviceId": "PCS04" - // }, - // { - // "statisDate": "2025-09-04", - // "activePower": null, - // "reactivePower": null, - // "uCurrent": 71.40, - // "vCurrent": 71.30, - // "wCurrent": 71.80, - // "deviceId": "PCS04" - // } - // ] - // }] const ele = this.btnList.find((item)=>{return item.id === this.activeBtn}) const sourceBase = JSON.parse(JSON.stringify(ele.source)) + // sourceBase={name:'堆平均维度',id:'1',attr:['temp'],source:['有功功率']}, const source=[] const sourceTop = ['日期'] - sourceBase.forEach((outer,outerIndex)=>{ - data.forEach((item,itemIndex)=>{ + 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)=>{ sourceTop.push(`${item.deviceId}-${outer}`) + noDataTime.forEach(i=>map[i].push('')) item.dataList.forEach((inner,innerIndex)=>{ - if(itemIndex === 0 || innerIndex+1>source.length) { - source.push([inner.statisDate]) - } - source[innerIndex].push(inner[ele.attr[outerIndex]]) + map[inner.statisDate].push(inner[ele.attr[outerIndex]]) }) }) }) + mapArr = mapArr.sort((a,b)=>this.compareDate(a,b)) + mapArr.forEach(item=>{ + source.push([item,...map[item]]) + }) source.unshift(sourceTop) + console.log('map=',map) + console.log('mapArr=',mapArr) console.log('========',source) this.chart.setOption({ grid: { diff --git a/src/views/ems/dzjk/tjbb/pcsqx/index.vue b/src/views/ems/dzjk/tjbb/pcsqx/index.vue index 62b5436..b6c7131 100644 --- a/src/views/ems/dzjk/tjbb/pcsqx/index.vue +++ b/src/views/ems/dzjk/tjbb/pcsqx/index.vue @@ -110,23 +110,53 @@ export default { }).finally(()=>{this.loading=false;}) }, + 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 + }, setOption(data) { const ele = this.btnList.find((item)=>{return item.id === this.activeBtn}) const sourceBase = JSON.parse(JSON.stringify(ele.source)) + // sourceBase={name:'堆平均维度',id:'1',attr:['temp'],source:['有功功率']}, const source=[] const sourceTop = ['日期'] - sourceBase.forEach((outer,outerIndex)=>{ - data.forEach((item,itemIndex)=>{ + 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)=>{ sourceTop.push(`${item.deviceId}-${outer}`) + noDataTime.forEach(i=>map[i].push('')) item.dataList.forEach((inner,innerIndex)=>{ - if(itemIndex === 0 || innerIndex+1>source.length) { - source.push([inner.statisDate]) - } - source[innerIndex].push(inner[ele.attr[outerIndex]]) + map[inner.statisDate].push(inner[ele.attr[outerIndex]]) }) }) }) + mapArr = mapArr.sort((a,b)=>this.compareDate(a,b)) + mapArr.forEach(item=>{ + source.push([item,...map[item]]) + }) source.unshift(sourceTop) + console.log('map=',map) + console.log('mapArr=',mapArr) console.log('========',source) this.chart.setOption({ grid: {