Browse Source

管理端 设备在线监测

develop
王兴琳 1 week ago
parent
commit
6961ba6439
  1. 2
      ruoyi-ui/src/api/deviceManage/deviceOnline.js
  2. 58
      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
}) })

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

@ -222,6 +222,7 @@ 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;
@ -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) { if (Object.keys(data).length !== 0) {
xData =Object.keys(data[Object.keys(data)[0]]); // xData
Object.keys(data[Object.keys(data)[0]]).forEach(date => {
Object.keys(data[Object.keys(data)[0]][date]).forEach(time => {
const formattedTime = this.formatDate(time)
console.log("***************************")
console.log(formattedTime)
if (!xData.includes(formattedTime )) {
xData.push(formattedTime );
}
});
});
//
for (const type in data) { for (const type in data) {
let yItem = {} let yItem = {
yItem.name = this.findType(type).label; name: this.findType(type).label,
yItem.unit = '%'; unit: '%',
yItem.data = []; data: []
let lineObj = data[type]; };
for(const time in lineObj){
yItem.data.push(lineObj[time].replace('%','')); //
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.xData = xData;
this.chartData.yData = yData; this.chartData.yData = yData;
}
}) })
} }

Loading…
Cancel
Save