Browse Source

管理端 设备在线监测

develop
王兴琳 1 week ago
parent
commit
6961ba6439
  1. 2
      ruoyi-ui/src/api/deviceManage/deviceOnline.js
  2. 66
      ruoyi-ui/src/views/deviceManage/deviceOnline/index.vue

2
ruoyi-ui/src/api/deviceManage/deviceOnline.js

@ -2,7 +2,7 @@ import request from '@/utils/request'
export function deviceOnlineChart(query) { export function deviceOnlineChart(query) {
return request({ return request({
url: '/system/status/list', url: '/system/status/listHourSystem',
method: 'get', method: 'get',
params: query params: query
}) })

66
ruoyi-ui/src/views/deviceManage/deviceOnline/index.vue

@ -222,7 +222,8 @@ export default {
logTotal:0 logTotal:0
} }
}, },
created() {
created() {
let rangeDate = getDaysRange(-30); let rangeDate = getDaysRange(-30);
this.dateRange[0] = rangeDate.start; this.dateRange[0] = rangeDate.start;
this.dateRange[1] = rangeDate.end; this.dateRange[1] = rangeDate.end;
@ -244,29 +245,66 @@ export default {
this.total = response.total; this.total = response.total;
}) })
}, },
formatDate(isoString) {
const date = new Date(isoString);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
return `${year}-${month}-${day} ${hours}:${minutes}`;
},
deviceOnlineChart(){ deviceOnlineChart(){
if(this.dateRange.length > 0){ if(this.dateRange.length > 0){
this.queryParams.startTime = this.dateRange[0]; this.queryParams.startTime = this.dateRange[0];
this.queryParams.time = this.dateRange[1]; this.queryParams.time = this.dateRange[1];
deviceOnlineChart(this.queryParams).then(response => { deviceOnlineChart(this.queryParams).then(response => {
console.log("*******************************")
let data = response.data; let data = response.data;
let xData ,yData = []; let xData = [], yData = [];
if(Object.keys(data).length !== 0){
xData =Object.keys(data[Object.keys(data)[0]]); if (Object.keys(data).length !== 0) {
for(const type in data){ // xData
let yItem = {} Object.keys(data[Object.keys(data)[0]]).forEach(date => {
yItem.name = this.findType(type).label; Object.keys(data[Object.keys(data)[0]][date]).forEach(time => {
yItem.unit = '%'; const formattedTime = this.formatDate(time)
yItem.data = []; console.log("***************************")
let lineObj = data[type]; console.log(formattedTime)
for(const time in lineObj){ if (!xData.includes(formattedTime )) {
yItem.data.push(lineObj[time].replace('%',''));
xData.push(formattedTime );
}
});
});
//
for (const type in data) {
let yItem = {
name: this.findType(type).label,
unit: '%',
data: []
};
//
for (const date in data[type]) {
//
for (const time in data[type][date]) {
yItem.data.push(parseFloat(data[type][date][time].replace('%', '')));
}
} }
yData.push(yItem); yData.push(yItem);
} }
// xData
/*
xData.sort((a, b) => moment(a).diff(moment(b)));
*/
this.chartData.xData = xData;
this.chartData.yData = yData;
} }
this.chartData.xData = xData;
this.chartData.yData = yData;
}) })
} }

Loading…
Cancel
Save