This commit is contained in:
geting 2024-11-25 14:56:10 +08:00
parent fecad2745e
commit 3f6451a556
4 changed files with 135 additions and 93 deletions

View File

@ -17,12 +17,17 @@
/>
<div style="width: 20px"></div>
<div style="width: fit-content; min-width: 60px">{{ t('airBlower.airBlowerNumber') }}</div>
<el-select v-model="airBlowerNumberValue" :placeholder="t('alarm.select') + t('airBlower.airBlowerNumber')" class="alarmSelect">
<el-select
v-model="airBlowerNumberValue"
:placeholder="t('alarm.select') + t('airBlower.airBlowerNumber')"
class="alarmSelect"
clearable
>
<el-option v-for="v in airBlowerList" :key="v.value" :label="v.label" :value="v.value"></el-option>
</el-select>
<div style="width: 20px"></div>
<div style="width: fit-content; min-width: 30px">{{ t('alarm.type') }}</div>
<el-select v-model="alarmTypeValue" :placeholder="t('alarm.select') + t('alarm.type')" class="alarmSelect">
<el-select v-model="alarmTypeValue" :placeholder="t('alarm.select') + t('alarm.type')" class="alarmSelect" clearable>
<el-option v-for="v in alarmTypes" :key="v.value" :label="v.label" :value="v.value"></el-option>
</el-select>
<div style="width: 20px"></div>
@ -153,7 +158,7 @@ const searchalarms = (): GetAlarmsTableParam => {
const start = timeRange.value[0]
const end = timeRange.value[1]
const deviceCode: any = []
if (airBlowerNumberValue.value.length) {
if (airBlowerNumberValue.value && airBlowerNumberValue.value.length) {
deviceCode.push(airBlowerNumberValue.value)
} else {
airBlowerList.value.forEach((item: any) => {

View File

@ -95,6 +95,7 @@ const option: any = {
itemGap: 20,
itemWidth: 8,
itemHeight: 8,
selectedMode: true,
data: [],
},
xAxis: {
@ -255,6 +256,7 @@ const isLoading = ref(false)
const statAnalysisOperate = () => {
isLoading.value = true
option.series = []
option.legend.data = []
chart.value.setOption(option, { notMerge: true })
const requestData = {
devices: [
@ -271,24 +273,32 @@ const statAnalysisOperate = () => {
const promise1 = new Promise((resolve, reject) => {
const madeinfactory = params.split(':')[0]
const model = params.split(':')[1]
powerCurveQuery(madeinfactory, model).then((res) => {
if (res.code == 200) {
resolve(res.data)
} else {
isLoading.value = false
ElMessage.warning('查询失败')
}
})
powerCurveQuery(madeinfactory, model)
.then((res) => {
if (res.code == 200) {
resolve(res.data)
} else {
isLoading.value = false
ElMessage.warning('查询失败')
}
})
.catch((error) => {
resolve(error)
})
})
const promise2 = new Promise((resolve, reject) => {
historyReq(requestData).then((res) => {
if (res.code == 200) {
resolve(res.data)
} else {
isLoading.value = false
ElMessage.warning('查询失败')
}
})
historyReq(requestData)
.then((res) => {
if (res.code == 200) {
resolve(res.data)
} else {
isLoading.value = false
ElMessage.warning('查询失败')
}
})
.catch((error) => {
resolve(error)
})
})
Promise.all([promise1, promise2])
@ -299,20 +309,25 @@ const statAnalysisOperate = () => {
if (resData0) {
const iGenPower = resData0['iGenPower']['values']
const iWindSpeed = resData0['iWindSpeed']['values']
const seriesData = iGenPower.map((item: any, index: number) => {
return [iWindSpeed[index], item]
})
seriesData.sort((a: any, b: any) => {
return a[0] - b[0]
})
const series = {
type: 'line',
data: seriesData,
name: '实际值',
smooth: true,
if (!iWindSpeed.length) {
ElMessage.info(`实时值数据为空`)
} else {
const seriesData = iGenPower.map((item: any, index: number) => {
return [iWindSpeed[index], item]
})
seriesData.sort((a: any, b: any) => {
return a[0] - b[0]
})
const series = {
type: 'line',
data: seriesData,
name: '实际值',
smooth: true,
animation: false,
}
option.series.push(series)
option.legend.data.push('实际值')
}
option.series.push(series)
option.legend.data.push('实际值')
}
if (resData1.length) {
const seriesData = resData1.map((item: any) => {
@ -323,6 +338,7 @@ const statAnalysisOperate = () => {
data: seriesData,
name: '理论值',
smooth: true,
animation: false,
}
option.series.push(series)
option.legend.data.push('理论值')
@ -331,7 +347,6 @@ const statAnalysisOperate = () => {
})
.catch((error) => {
isLoading.value = false
console.error(error)
ElMessage.warning(error)
})
}

View File

@ -105,8 +105,6 @@ import { ElMessage } from 'element-plus'
import { DArrowRight, Plus, Delete } from '@element-plus/icons-vue'
import MeasurementPage from './analysisAttributes.vue'
import * as echarts from 'echarts'
import { promises } from 'dns'
import { index } from '/@/api/backend'
const { t } = useI18n()
const statAnalysisSelect = reactive({
deviceId: '',
@ -123,7 +121,7 @@ const addTime = (index: any) => {
const switchTime = (index: number) => {
times.splice(index, 1)
customName.splice(index, 1)
calculate.splice(index, 1)
calculate.value.splice(index, 1)
}
const timechange = (value: any) => {
const count = getTimeIntervals(times[0][0], times[0][1])
@ -326,7 +324,6 @@ const getTimeIntervals = (startTimestamp: number, endTimestamp: number) => {
const startDate: any = new Date(startTimestamp)
const endDate: any = new Date(endTimestamp)
let count = 0
switch (statAnalysisSelect.interval) {
case 'NONE':
count = Math.floor((endDate - startDate) / 1000)
@ -343,13 +340,13 @@ const getTimeIntervals = (startTimestamp: number, endTimestamp: number) => {
case '1d':
count = Math.floor((endDate - startDate) / (1 * 24 * 60 * 60 * 1000))
break
// default:
// throw new Error('Invalid interval')
default:
count = Math.floor((endDate - startDate) / (5 * 60 * 1000))
}
return count
}
const calculate: any = reactive([{ max: '', min: '', average: '' }])
const calculate: any = ref([{ max: '', min: '', average: '' }])
var xDatas: any = []
const isLoading = ref(false)
const statAnalysisOperate = () => {
@ -357,6 +354,7 @@ const statAnalysisOperate = () => {
option.series = []
option.legend.data = []
xDatas = []
calculate.value = []
chart.value.setOption(option, { notMerge: true })
const promises: any = []
times.forEach((time: any, index: number) => {
@ -373,13 +371,17 @@ const statAnalysisOperate = () => {
endTime: new Date(time[1]).getTime(),
}
const promise = new Promise((resolve, reject) => {
historyReq(requestData).then((res) => {
if (res.code == 200) {
resolve(res.data)
} else {
ElMessage.warning('查询失败')
}
})
historyReq(requestData)
.then((res) => {
if (res.code == 200) {
resolve(res.data)
} else {
ElMessage.warning('查询失败')
}
})
.catch((error) => {
reject(error)
})
})
promises.push(promise)
}
@ -397,7 +399,11 @@ const historyDataReq = (promises: any) => {
const resData = (res && deviceId in res && res[deviceId][attributeCode]) || undefined
const xData = resData['times']
const yData = resData['values']
calculate[index] = calculateStats(yData)
if (!yData.length) {
ElMessage.info(`${customName[index]}数据为空`)
return
}
calculate.value[index] = calculateStats(yData)
xDatas.push({
series: String(customName[index]),
data: xData,
@ -421,6 +427,7 @@ const historyDataReq = (promises: any) => {
type: 'line',
data: yData,
showSymbol: true,
animation: false,
}
option.legend.data.push(customName[index])
option.series.push(seriesData)

View File

@ -138,7 +138,7 @@ const switchDevice = (index: number) => {
statAnalysisAttributes.splice(index, 1)
statAnalysisAttributeCode.splice(index, 1)
customName.splice(index, 1)
calculate.splice(index, 1)
calculate.value.splice(index, 1)
}
const isExpand = ref(false)
@ -327,54 +327,69 @@ const isLoading = ref(false)
const statAnalysisOperate = () => {
isLoading.value = true
option.series = []
option.legend.data = []
calculate.value = []
chart.value.setOption(option, { notMerge: true })
historyDataReq(getRequestData())
}
const calculate: any = reactive([{ max: '', min: '', average: '' }])
const calculate: any = ref([{ max: '', min: '', average: '' }])
const historyDataReq = (data: any) => {
historyReq(data).then((res) => {
isLoading.value = false
if (res.code == 200) {
const resData = res.data
const deviceIdKeys = Object.keys(resData)
const attributeKeys = []
if (deviceIdKeys.length) {
deviceIdKeys.forEach((item) => {
const indexList1 = findAllOccurrences(statAnalysisDeviceId, item)
Object.keys(resData[item]).forEach((value) => {
const indexList2 = findAllOccurrences(statAnalysisAttributeCode, value)
const dataIndex = getCommonElements(indexList1, indexList2)[0]
const historyData = resData[item][value]
const xData = historyData['times']
const yData = historyData['values']
const seriesData = {
name: customName[dataIndex],
type: 'line',
data: yData,
}
calculate[dataIndex] = calculateStats(yData)
option.tooltip = {
show: true,
trigger: 'axis',
formatter: function (params: any) {
return params
.map((item: any) => {
return `${item.marker} ${item.seriesName} (${timestampToTime(xData[item.dataIndex])}): ${item.data}`
})
.join('<br/>')
},
}
option.legend.data.push(customName[dataIndex])
option.xAxis.data = xData.map((item: any) => timestampToTime(item))
option.series.push(seriesData)
chart.value.setOption(option)
})
})
}
} else {
historyReq(data)
.then((res) => {
isLoading.value = false
ElMessage.warning('查询失败')
}
})
if (res.code == 200) {
const resData = res.data
const deviceIdKeys = Object.keys(resData)
const attributeKeys = []
if (deviceIdKeys.length) {
deviceIdKeys.forEach((item) => {
const indexList1 = findAllOccurrences(statAnalysisDeviceId, item)
Object.keys(resData[item]).forEach((value) => {
const indexList2 = findAllOccurrences(statAnalysisAttributeCode, value)
const dataIndex = getCommonElements(indexList1, indexList2)[0]
const historyData = resData[item][value]
const xData = historyData['times']
const yData = historyData['values']
if (!yData.length) {
ElMessage.info(`${customName[dataIndex]}数据为空`)
return
}
const seriesData = {
name: customName[dataIndex],
type: 'line',
data: yData,
animation: false,
}
calculate.value[dataIndex] = calculateStats(yData)
option.tooltip = {
show: true,
trigger: 'axis',
formatter: function (params: any) {
return params
.map((item: any) => {
return `${item.marker} ${item.seriesName} (${timestampToTime(xData[item.dataIndex])}): ${item.data}`
})
.join('<br/>')
},
}
option.legend.data.push(customName[dataIndex])
option.xAxis.data = xData.map((item: any) => timestampToTime(item))
option.series.push(seriesData)
chart.value.setOption(option)
})
})
}
} else {
isLoading.value = false
ElMessage.warning('查询失败')
}
})
.catch((error) => {
isLoading.value = false
console.error(error)
ElMessage.warning(error)
})
}
const findAllOccurrences = (arr: any, target: any) => {