diff --git a/ruoyi-ui/src/components/modelComponents/pie/pie.vue b/ruoyi-ui/src/components/modelComponents/pie/pie.vue index e97d8ac..8968ab7 100644 --- a/ruoyi-ui/src/components/modelComponents/pie/pie.vue +++ b/ruoyi-ui/src/components/modelComponents/pie/pie.vue @@ -170,8 +170,13 @@ export default { }, dataChange() { this.pieData = this.networkData[this.defaultData.configForm.data] + + let keys = [] + this.pieData.forEach(ee=>{ + keys = [...new Set(keys.concat(Object.keys(ee)))] + }) console.log('this.pieData', this.pieData) - this.option = Object.keys(this.pieData?.[0]).map(e => { + this.option = keys.map(e => { return { value: e, label: e diff --git a/ruoyi-ui/src/components/modelComponents/srcollTable/srcollTable.vue b/ruoyi-ui/src/components/modelComponents/srcollTable/srcollTable.vue index 9b03878..d5e1988 100644 --- a/ruoyi-ui/src/components/modelComponents/srcollTable/srcollTable.vue +++ b/ruoyi-ui/src/components/modelComponents/srcollTable/srcollTable.vue @@ -127,7 +127,11 @@ export default { }, dataChange() { this.tableData = this.networkData[this.defaultData.tableDataKey] - let keys = Object.keys(this.tableData?.[0] || {}) + + let keys = [] + this.tableData.forEach(ee=>{ + keys = [...new Set(keys.concat(Object.keys(ee)))] + }) this.tdkeys = keys } }, diff --git a/ruoyi-ui/src/components/networkRequest/NetworkRequest.vue b/ruoyi-ui/src/components/networkRequest/NetworkRequest.vue index ed1309d..8aaa479 100644 --- a/ruoyi-ui/src/components/networkRequest/NetworkRequest.vue +++ b/ruoyi-ui/src/components/networkRequest/NetworkRequest.vue @@ -486,16 +486,18 @@ export default { }, testDeviceConnection(i, k) { this.$set(this.requests[k], 'connectionStatus', 0) - getHistoryData({ + this.$getDeviceData({ deviceModeId: i.deviceModeId, functionIdentifier: i.functionIdentifier, interval: i.interval, + isRealTime:i.isRealTime, "sceneId": 144, "deviceId": i.deviceId, startTime: i.startTime, endTime: i.endTime, intervalType: 1 || i.intervalType, }).then(e => { + console.log('eee',e) // this.$set(this.requests[k], 'connectionStatus', e.status ? 1 : 2) this.$set(this.requests[k], 'connectionStatus', e.code === 200 ? 1 : 2) this.$set(this.requests[k], 'request', e.data) @@ -602,8 +604,9 @@ export default { }, async setDeviceMapping(i, k) { if (!this.requests?.[k]?.request) { - await getHistoryData({ + await this.$getDeviceData({ deviceModeId: i.deviceModeId, + isRealTime:i.isRealTime, functionIdentifier: i.functionIdentifier, interval: i.interval, "sceneId": 144, @@ -637,11 +640,18 @@ export default { children: fun(v[e]) } } else { + let keys = [] + if(Array.isArray(v[e])){ + v[e].forEach(ee=>{ + keys = [...new Set(keys.concat(Object.keys(ee)))] + }) + } + console.log('keys',keys) return { value: e, label: e, type: Array.isArray(v[e]) ? 'Array' : 'String', - enum: Array.isArray(v[e]) ? Object.keys(v[e]?.[0] || {}) : [], + enum: Array.isArray(v[e]) ? keys : [], } } }) @@ -649,6 +659,7 @@ export default { let option = fun(data) this.options = option + console.log('option',option) if (this.mappingForm.isArray) { this.mappingChange() } diff --git a/ruoyi-ui/src/main.js b/ruoyi-ui/src/main.js index b81cf19..aacf379 100644 --- a/ruoyi-ui/src/main.js +++ b/ruoyi-ui/src/main.js @@ -50,7 +50,8 @@ import { clearArrNull, clearNull, getFinalData, - testColor + testColor, + getDeviceData } from '@/utils/scrin' import request from '@/utils/request' @@ -75,6 +76,7 @@ Vue.prototype.$request = request Vue.prototype.$detectingNullValues = detectingNullValues Vue.prototype.$getFinalData = getFinalData Vue.prototype.$testColor = testColor +Vue.prototype.$getDeviceData = getDeviceData // 全局组件挂载 Vue.component('DictTag', DictTag) diff --git a/ruoyi-ui/src/utils/scrin.js b/ruoyi-ui/src/utils/scrin.js index 45facb8..8916ddf 100644 --- a/ruoyi-ui/src/utils/scrin.js +++ b/ruoyi-ui/src/utils/scrin.js @@ -2,6 +2,148 @@ import {interfaceRequest} from "@/components/networkRequest/requestSend"; import {getHistoryData} from "@/api/configuration/equipment"; import Vue from 'vue' +const getDeviceData = async (data) => { + + let getTime = (e) => { + if (e === '1') { + return [(new Date().getTime() - (1000 * 60 * 60 * 24)), (new Date().getTime())] + } + if (e === '2') { + return [(new Date().getTime() - (1000 * 60 * 60 * 24)), (new Date().getTime())] + } + if (e === '3') { + return [(new Date().getTime() - (1000 * 60 * 60 * 24 * 7)), (new Date().getTime())] + } + if (e === '4') { + return [(new Date().getTime() - (1000 * 60 * 60 * 24 * 30)), (new Date().getTime())] + } + if (e === '5') { + return [(new Date().getTime() - (1000 * 60 * 60 * 24 * 365)), (new Date().getTime())] + } + } + const getTimeList = (e, isRealTime, startTimeArg, endTimeArg) => { + let startTime, endTime + if (!isRealTime) { + startTime = startTimeArg + endTime = endTimeArg + } else { + startTime = getTime(e)[0] + endTime = getTime(e)[1] + } + if (e === '1') { + let scope = Math.ceil((endTime - startTime) / (1000 * 60 * 60)) || 0 + let arr = Array(scope).fill(1).map((v, k) => { + return parseTime(endTime - (1000 * 60 * 60) * k, '{y}-{m}-{d} {h}:{i}') + }) + return arr.reverse() + } + if (e === '2') { + let scope = Math.ceil((endTime - startTime) / (1000 * 60 * 60)) || 0 + let arr = Array(scope).fill(1).map((v, k) => { + return parseTime(endTime - (1000 * 60 * 60) * k, '{y}-{m}-{d} {h}') + }) + return arr.reverse() + } + if (e === '3') { + let scope = Math.ceil((endTime - startTime) / (1000 * 60 * 60 * 24)) || 0 + let arr = Array(scope).fill(1).map((v, k) => { + return parseTime(endTime - (1000 * 60 * 60 * 24) * k, '{y}-{m}-{d}') + }) + return arr.reverse() + } + if (e === '4') { + let scope = Math.ceil((endTime - startTime) / (1000 * 60 * 60 * 24)) || 0 + let arr = Array(scope).fill(1).map((v, k) => { + return parseTime(endTime - (1000 * 60 * 60 * 24) * k, '{y}-{m}-{d}') + }) + return arr.reverse() + } + if (e === '5') { + let scope = Math.ceil((endTime - startTime) / (1000 * 60 * 60 * 24 * 30)) || 0 + let arr = Array(scope).fill(1).map((v, k) => { + return parseTime(endTime - (1000 * 60 * 60 * 24 * 30) * k, '{y}-{m}') + }) + return arr.reverse() + } + } + const res2 = await getHistoryData({ + deviceModeId: data.deviceModeId, + functionIdentifier: data.functionIdentifier, + interval: data.interval, + "sceneId": 144, + "deviceId": data.deviceId, + startTime: data.isRealTime ? getTime(data.interval)?.[0] : data.startTime, + endTime: data.isRealTime ? getTime(data.interval)?.[1] : data.endTime, + intervalType: 1 || data.intervalType, + }) + if (data.isRealTime) { + if (data.interval === '1') { + let arr = getTimeList(data.interval, data.isRealTime) + + res2.data.groupDeviceData.dataList = arr.map(v => { + let data = res2.data.groupDeviceData.dataList.find(vv => parseTime(vv.time, '{y}-{m}-{d} {h}:{i}') === v) + return {...data, time: v} + }) + } + if (data.interval === '2') { + let arr = getTimeList(data.interval, data.isRealTime) + + res2.data.groupDeviceData.dataList = arr.map(v => { + let data = res2.data.groupDeviceData.dataList.find(vv => parseTime(vv.time, '{y}-{m}-{d} {h}') === v) + return {...data, time: v} + }) + } + if (data.interval === '3') { + let arr = getTimeList(data.interval, data.isRealTime) + console.log('arr', arr) + + res2.data.groupDeviceData.dataList = arr.map(v => { + let data = res2.data.groupDeviceData.dataList.find(vv => parseTime(vv.time, '{y}-{m}-{d}') === v) + return {...data, time: v} + }) + + } + if (data.interval === '4') { + let arr = getTimeList(data.interval, data.isRealTime) + console.log('arr', arr) + + res2.data.groupDeviceData.dataList = arr.map(v => { + let data = res2.data.groupDeviceData.dataList.find(vv => parseTime(vv.time, '{y}-{m}-{d}') === v) + return {...data, time: v} + }) + + } + if (data.interval === '5') { + let arr = getTimeList(data.interval, data.isRealTime) + console.log('arr', arr) + + res2.data.groupDeviceData.dataList = arr.map(v => { + let data = res2.data.groupDeviceData.dataList.find(vv => parseTime(vv.time, '{y}-{m}') === v) + return {...data, time: v} + }) + + } + } else { + if (data.interval === '5') { + res2.data.groupDeviceData.dataList = res2.data.groupDeviceData.dataList.map(e => { + return {...e, time: parseTime(e.time, '{y}-{m}')} + }) + } else if (data.interval === '4' || data.interval === '3') { + res2.data.groupDeviceData.dataList = res2.data.groupDeviceData.dataList.map(e => { + return {...e, time: parseTime(e.time, '{y}-{m}-{d}')} + }) + } else { + res2.data.groupDeviceData.dataList = res2.data.groupDeviceData.dataList.map(e => { + return {...e, time: parseTime(e.time, '{y}-{m}-{d} {h}:{i}:{s}')} + }) + } + } + debugger + console.log('res2222222', res2) + debugger + return res2 +} + const mappingFunction = async (data, method) => { if (data.type === 1) { let res2 = await interfaceRequest(data) @@ -28,145 +170,12 @@ const mappingFunction = async (data, method) => { } if (data.type === 2) { - let getTime = (e) => { - if (e === '1') { - return [(new Date().getTime() - (1000 * 60 * 60 * 24)), (new Date().getTime())] - } - if (e === '2') { - return [(new Date().getTime() - (1000 * 60 * 60 * 24)), (new Date().getTime())] - } - if (e === '3') { - return [(new Date().getTime() - (1000 * 60 * 60 * 24 * 7)), (new Date().getTime())] - } - if (e === '4') { - return [(new Date().getTime() - (1000 * 60 * 60 * 24 * 30)), (new Date().getTime())] - } - if (e === '5') { - return [(new Date().getTime() - (1000 * 60 * 60 * 24 * 365)), (new Date().getTime())] - } - } - const getTimeList = (e, isRealTime, startTimeArg, endTimeArg) => { - let startTime, endTime - if (!isRealTime) { - startTime = startTimeArg - endTime = endTimeArg - } else { - startTime = getTime(e)[0] - endTime = getTime(e)[1] - } - if (e === '1') { - let scope = Math.ceil((endTime - startTime) / (1000 * 60 * 60)) || 0 - let arr = Array(scope).fill(1).map((v, k) => { - return parseTime(endTime - (1000 * 60 * 60) * k, '{y}-{m}-{d} {h}:{i}') - }) - return arr - } - if (e === '2') { - let scope = Math.ceil((endTime - startTime) / (1000 * 60 * 60)) || 0 - let arr = Array(scope).fill(1).map((v, k) => { - return parseTime(endTime - (1000 * 60 * 60) * k, '{y}-{m}-{d} {h}') - }) - return arr - } - if (e === '3') { - let scope = Math.ceil((endTime - startTime) / (1000 * 60 * 60 * 24)) || 0 - let arr = Array(scope).fill(1).map((v, k) => { - return parseTime(endTime - (1000 * 60 * 60 * 24) * k, '{y}-{m}-{d}') - }) - return arr - } - if (e === '4') { - let scope = Math.ceil((endTime - startTime) / (1000 * 60 * 60 * 24)) || 0 - let arr = Array(scope).fill(1).map((v, k) => { - return parseTime(endTime - (1000 * 60 * 60 * 24) * k, '{y}-{m}-{d}') - }) - return arr - } - if (e === '5') { - let scope = Math.ceil((endTime - startTime) / (1000 * 60 * 60 * 24 * 30)) || 0 - let arr = Array(scope).fill(1).map((v, k) => { - return parseTime(endTime - (1000 * 60 * 60 * 24 * 30) * k, '{y}-{m}') - }) - return arr - } - } - let res2 = await getHistoryData({ - deviceModeId: data.deviceModeId, - functionIdentifier: data.functionIdentifier, - interval: data.interval, - "sceneId": 144, - "deviceId": data.deviceId, - startTime: data.isRealTime ? getTime(data.interval)?.[0] : data.startTime, - endTime: data.isRealTime ? getTime(data.interval)?.[1] : data.endTime, - intervalType: 1 || data.intervalType, - }) - console.log('datadata', data) - if (data.isRealTime) { - if (data.interval === '1') { - let arr = getTimeList(data.interval, data.isRealTime) - - res2.data.groupDeviceData.dataList = arr.map(v => { - let data = res2.data.groupDeviceData.dataList.find(vv => parseTime(vv.time, '{y}-{m}-{d} {h}:{i}') === v) - return {...data, time: v} - }) - } - if (data.interval === '2') { - let arr = getTimeList(data.interval, data.isRealTime) - - res2.data.groupDeviceData.dataList = arr.map(v => { - let data = res2.data.groupDeviceData.dataList.find(vv => parseTime(vv.time, '{y}-{m}-{d} {h}') === v) - return {...data, time: v} - }) - } - if (data.interval === '3') { - let arr = getTimeList(data.interval, data.isRealTime) - console.log('arr', arr) - - res2.data.groupDeviceData.dataList = arr.map(v => { - let data = res2.data.groupDeviceData.dataList.find(vv => parseTime(vv.time, '{y}-{m}-{d}') === v) - return {...data, time: v} - }) - - } - if (data.interval === '4') { - let arr = getTimeList(data.interval, data.isRealTime) - console.log('arr', arr) - - res2.data.groupDeviceData.dataList = arr.map(v => { - let data = res2.data.groupDeviceData.dataList.find(vv => parseTime(vv.time, '{y}-{m}-{d}') === v) - return {...data, time: v} - }) - - } - if (data.interval === '5') { - let arr = getTimeList(data.interval, data.isRealTime) - console.log('arr', arr) - - res2.data.groupDeviceData.dataList = arr.map(v => { - let data = res2.data.groupDeviceData.dataList.find(vv => parseTime(vv.time, '{y}-{m}') === v) - return {...data, time: v} - }) - - } - } else { - if (data.interval === '5') { - res2.data.groupDeviceData.dataList = res2.data.groupDeviceData.dataList.map(e => { - return {...e, time: parseTime(e.time, '{y}-{m}')} - }) - } else if (data.interval === '4' || data.interval === '3') { - res2.data.groupDeviceData.dataList = res2.data.groupDeviceData.dataList.map(e => { - return {...e, time: parseTime(e.time, '{y}-{m}-{d}')} - }) - } else { - res2.data.groupDeviceData.dataList = res2.data.groupDeviceData.dataList.map(e => { - return {...e, time: parseTime(e.time, '{y}-{m}-{d} {h}:{i}:{s}')} - }) - } - } - console.log(res2) + let res2 = await getDeviceData(data) + console.log('res2666', res2) let returnRes = {} method?.mappingArr?.forEach(v => { let res = res2.data + console.log(res) for (let i of (v?.region || [])) { if (res[i]) { res = res[i] @@ -176,9 +185,10 @@ const mappingFunction = async (data, method) => { } } if (v?.isArray && v?.mapData && Array.isArray(res)) { - console.log(res) - res = res.map(e => e[v.mapData]) + console.log('res10101010101',res) + res = res.map(e => e[v.mapData]||null) } + console.log('res10101010101--1',res) returnRes = { ...returnRes, [v?.name]: res @@ -288,8 +298,9 @@ const clearObjNull = (e, data1) => { return Object.keys(obj).length === 0 ? null : obj } const clearArrNull = (e, data1) => { + return e if (!Array.isArray(e)) { - return null + return e } let arr = [] e.forEach(v => { @@ -401,5 +412,6 @@ export { detectingNullValues, getFinalData, parseTime, - testColor + testColor, + getDeviceData }