历史趋势添加缺失数据功能

This commit is contained in:
guanj
2025-10-31 13:41:48 +08:00
parent 13c0a28c95
commit dc44e16d4d
8 changed files with 2833 additions and 2530 deletions

View File

@@ -4,12 +4,12 @@ const dataProcessing = (arr: any[]) => {
.map(item => (typeof item === 'number' ? item : parseFloat(item)))
}
const calculateValue = (o:number,value: number, num: number, isMin: boolean) => {
const calculateValue = (o: number, value: number, num: number, isMin: boolean) => {
if (value === 0) {
return 0
}else if(value>0&& Math.abs(value)<1 && isMin==true){
} else if (value > 0 && Math.abs(value) < 1 && isMin == true) {
return 0
}else if(value>-1&& value<0 && isMin==false){
} else if (value > -1 && value < 0 && isMin == false) {
return 0
}
let base
@@ -55,9 +55,9 @@ export const yMethod = (arr: any) => {
let min = 0
maxValue = Math.max(...numList)
minValue = Math.min(...numList)
const o=maxValue-minValue
min = calculateValue( o,minValue, num, true)
max = calculateValue(o,maxValue, num, false)
const o = maxValue - minValue
min = calculateValue(o, minValue, num, true)
max = calculateValue(o, maxValue, num, false)
// if (-100 >= minValue) {
// min = Math.floor((minValue + num * minValue) / 100) * 100
// } else if (-10 >= minValue && minValue > -100) {
@@ -128,20 +128,18 @@ export const yMethod = (arr: any) => {
return [min, max]
}
/**
* title['A相','B相',]
* data[[1,2],[3,4]]
*/
// 导出csv文件
const convertToCSV = (title: object, data: any) => {
console.log('🚀 ~ convertToCSV ~ data:', data)
let csv = ''
// 添加列头
csv += ',' + title.join(',') + '\n'
// 遍历数据并添加到CSV字符串中
data?.map(item => {
csv += item.join(',') + '\n'
csv += '\u200B' + item.join(',') + '\n'
})
return csv
}
@@ -155,3 +153,144 @@ export const exportCSV = (title: object, data: any, filename: string) => {
// 释放URL对象
URL.revokeObjectURL(link.href)
}
/**
* 补全时间序列数据中缺失的条目
* @param rawData 原始数据,格式为 [["时间字符串", "数值", "单位", "类型"], ...]
* @returns 补全后的数据,缺失条目数值为 null
*/
export const completeTimeSeries = (rawData: string[][]): (string | null)[][] => {
// 步骤1校验原始数据并解析时间
if (rawData.length < 2) {
console.warn('数据量不足2条无法计算时间间隔直接返回原始数据')
return rawData.map(item => [...item])
}
// 解析所有时间为Date对象过滤无效时间并按时间排序
const validData = rawData
.map(item => {
// 确保至少有时间和数值字段
if (!item[0]) {
return { time: new Date(0), item, isValid: false }
}
const time = new Date(item[0])
return { time, item, isValid: !isNaN(time.getTime()) }
})
.filter(data => data.isValid)
.sort((a, b) => a.time.getTime() - b.time.getTime()) // 确保数据按时间排序
.map(data => data.item)
if (validData.length < 2) {
throw new Error('有效时间数据不足2条无法继续处理')
}
// 步骤2计算时间间隔分析前几条数据确定最可能的间隔
const intervals: number[] = []
// 分析前10条数据来确定间隔避免单一间隔出错
const analyzeCount = Math.min(10, validData.length - 1)
for (let i = 0; i < analyzeCount; i++) {
const currentTime = new Date(validData[i][0]!).getTime()
const nextTime = new Date(validData[i + 1][0]!).getTime()
const interval = nextTime - currentTime
if (interval > 0) {
intervals.push(interval)
}
}
// 取最常见的间隔作为标准间隔
const timeInterval = getMostFrequentValue(intervals)
if (timeInterval <= 0) {
throw new Error('无法确定有效的时间间隔')
}
// 步骤3生成完整的时间序列范围从第一条到最后一条
const startTime = new Date(validData[0][0]!).getTime()
const endTime = new Date(validData[validData.length - 1][0]!).getTime()
const completeTimes: Date[] = []
// 生成从 startTime 到 endTime 的所有间隔时间点
for (let time = startTime; time <= endTime; time += timeInterval) {
completeTimes.push(new Date(time))
}
// 步骤4将原始数据转为时间映射表使用精确的时间字符串匹配
const timeDataMap = new Map<string, (string | undefined)[]>()
validData.forEach(item => {
// 使用原始时间字符串作为键,避免格式转换导致的匹配问题
if (item[0]) {
timeDataMap.set(item[0], item)
}
})
// 提取模板数据(从第一条有效数据中提取单位和类型,处理可能的缺失)
const template = validData[0]
// 步骤5对比补全数据缺失条目数值为 null
const completedData = completeTimes.map(time => {
// 保持与原始数据相同的时间格式
const timeStr = formatTime(time)
const existingItem = timeDataMap.get(timeStr)
if (existingItem) {
// 存在该时间,返回原始数据
return [...existingItem]
} else {
// 缺失该时间,数值设为 null其他字段沿用第一个有效数据的格式
// 处理可能缺失的单位和类型字段
const result: (string | null | undefined)[] = [timeStr, '/']
// 仅在原始数据有单位字段时才添加
if (template.length > 2) {
result.push(template[2])
}
// 仅在原始数据有类型字段时才添加
if (template.length > 3) {
result.push(template[3])
}
return result
}
})
return completedData
}
/**
* 格式化时间为 "YYYY-MM-DD HH:mm:ss" 格式
* @param date 日期对象
* @returns 格式化后的时间字符串
*/
function formatTime(date: Date): string {
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')
const seconds = String(date.getSeconds()).padStart(2, '0')
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
}
/**
* 获取数组中出现频率最高的值
* @param arr 数字数组
* @returns 出现频率最高的值
*/
function getMostFrequentValue(arr: number[]): number {
if (arr.length === 0) return 0
const frequencyMap = new Map<number, number>()
arr.forEach(num => {
frequencyMap.set(num, (frequencyMap.get(num) || 0) + 1)
})
let maxFrequency = 0
let mostFrequent = arr[0]
frequencyMap.forEach((frequency, num) => {
if (frequency > maxFrequency) {
maxFrequency = frequency
mostFrequent = num
}
})
return mostFrequent
}

View File

@@ -94,7 +94,15 @@ const tableStore = new TableStore({
},
{ title: '设备名称', field: 'ndid', align: 'center' },
{ title: '异常时间', field: 'evtTime', align: 'center', sortable: true },
{ title: '告警代码', field: 'code', align: 'center', sortable: true }
{
title: '告警代码',
field: 'code',
align: 'center',
sortable: true,
formatter: (row: any) => {
return row.cellValue ? '\u200B' + row.cellValue : '/'
}
}
]
})

View File

@@ -86,7 +86,7 @@ const tableStore = new TableStore({
{ title: '设备名称', field: 'equipmentName', align: 'center' },
{ title: '工程名称', field: 'engineeringName', align: 'center' },
{ title: '项目名称', field: 'projectName', align: 'center' },
{ title: '发生时刻', field: 'startTime', align: 'center', minWidth: 110, sortable: true },
{ title: '发生时刻', field: 'startTime', align: 'center', width: 180, sortable: true },
{
title: '模块信息',
field: 'moduleNo',
@@ -99,20 +99,21 @@ const tableStore = new TableStore({
title: '告警代码',
field: 'code',
align: 'center',
width: 100,
formatter: (row: any) => {
return row.cellValue ? row.cellValue : '/'
return row.cellValue ? '\u200B' + row.cellValue : '/'
},
sortable: true
},
{
title: '事件描述',
minWidth: 220,
field: 'showName'
},
{
title: '级别',
field: 'level',
width: 100,
render: 'tag',
custom: {
1: 'danger',
@@ -133,7 +134,8 @@ const tableStore = new TableStore({
// }
// }
],
beforeSearchFun: () => {}
beforeSearchFun: () => {},
})
provide('tableStore', tableStore)

View File

@@ -51,7 +51,7 @@ const tableStore = new TableStore({
align: 'center',
formatter: (row: any) => {
return row.cellValue ? row.cellValue : '/'
return row.cellValue ? '\u200B' + row.cellValue : '/'
},
sortable: true
},

View File

@@ -52,6 +52,9 @@
</template>
<template v-slot:operation>
<el-button type="primary" @click="search" icon="el-icon-Search">查询</el-button>
<el-button :type="timeControl ? 'primary' : ''" icon="el-icon-Sort" @click="setTimeControl">
缺失数据
</el-button>
</template>
</TableHeader>
</div>
@@ -76,9 +79,9 @@ import { getDevCapacity } from '@/api/cs-device-boot/capacity'
import { queryCommonStatisticalByTime } from '@/api/cs-harmonic-boot/stable'
import DatePicker from '@/components/form/datePicker/index.vue'
import MyEchart from '@/components/echarts/MyEchart.vue'
import { yMethod } from '@/utils/echartMethod'
import { yMethod, completeTimeSeries } from '@/utils/echartMethod'
import TableHeader from '@/components/table/header/index.vue'
const timeControl = ref(false)
defineOptions({
name: 'govern/analyze/APF'
})
@@ -98,6 +101,7 @@ const formInline = reactive({
devId: '',
frequency: ''
})
const dataLists = ref<any[]>([])
const timeFlag = ref(true)
const frequencyShow = ref(false)
const devCapacity = ref(0)
@@ -180,6 +184,17 @@ const search = () => {
queryCommonStatisticalByTime(formInline)
.then(({ data }: { data: any[] }) => {
dataLists.value = data
setEchart()
loading.value = false
})
.catch(() => {
loading.value = false
})
}
const setEchart = () => {
loading.value = true
let data = JSON.parse(JSON.stringify(dataLists.value))
if (data.length) {
let list = processingOfData(data, 'unit')
@@ -232,26 +247,33 @@ const search = () => {
j == 'M' ? k : j == 'A' ? `A相_${k}` : j == 'B' ? `B相_${k}` : j == 'C' ? `C相_${k}` : j
)
series.push({
name:
j == 'M'
? k
: j == 'A'
? `A相_${k}`
: j == 'B'
? `B相_${k}`
: j == 'C'
? `C相_${k}`
: j,
name: j == 'M' ? k : j == 'A' ? `A相_${k}` : j == 'B' ? `B相_${k}` : j == 'C' ? `C相_${k}` : j,
symbol: 'none',
smooth: true,
type: 'line',
data: phaseList[j].map(item => [
// data: phaseList[j].map(item => [
// item.time,
// Math.floor(item.statisticalData * 100) / 100,
// unit,
// lineName.type
// ]),
data: timeControl.value
? completeTimeSeries(
phaseList[j].map(item => [
item.time,
Math.floor(item.statisticalData * 100) / 100,
unit,
lineName.type
])
)
: phaseList[j].map(item => [
item.time,
Math.floor(item.statisticalData * 100) / 100,
unit,
lineName.type
]),
lineStyle: lineName,
yAxisIndex: unit.indexOf(units)
})
@@ -293,9 +315,7 @@ const search = () => {
}
str += `${marker}${el.seriesName.split('(')[0]}${
el.value[1] != null
? el.value[1] + ' ' + (el.value[2] == 'null' ? '' : el.value[2])
: '-'
el.value[1] != null ? el.value[1] + ' ' + (el.value[2] == 'null' ? '' : el.value[2]) : '-'
}<br>`
})
return str
@@ -394,11 +414,12 @@ const search = () => {
echartsData.value = null
}
loading.value = false
})
.catch(() => {
loading.value = false
})
}
const setTimeControl = () => {
timeControl.value = !timeControl.value
setEchart()
}
const processingOfData = (data: any, type: string) => {
let groupedData: any = {}

View File

@@ -8,21 +8,39 @@
<DatePicker ref="datePickerRef"></DatePicker>
</el-form-item>
<el-form-item label="统计指标" label-width="80px">
<el-select multiple :multiple-limit="3" collapse-tags collapse-tags-tooltip
v-model="searchForm.index" placeholder="请选择统计指标" @change="onIndexChange($event)">
<el-option v-for="item in indexOptions" :key="item.id" :label="item.name"
:value="item.id"></el-option>
<el-select
multiple
:multiple-limit="3"
collapse-tags
collapse-tags-tooltip
v-model="searchForm.index"
placeholder="请选择统计指标"
@change="onIndexChange($event)"
>
<el-option
v-for="item in indexOptions"
:key="item.id"
:label="item.name"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
<el-form-item>
<el-radio-group v-model="searchForm.dataLevel" :disabled="props?.TrendList?.lineType != 1" @change="init()">
<el-radio-group
v-model="searchForm.dataLevel"
:disabled="props?.TrendList?.lineType != 1"
@change="init()"
>
<el-radio-button label="一次值" value="Primary" />
<el-radio-button label="二次值" value="Secondary" />
</el-radio-group>
</el-form-item>
<el-form-item label="统计类型">
<el-select style="min-width: 120px !important" placeholder="请选择" v-model="searchForm.valueType">
<el-select
style="min-width: 120px !important"
placeholder="请选择"
v-model="searchForm.valueType"
>
<el-option value="max" label="最大值"></el-option>
<el-option value="min" label="最小值"></el-option>
<el-option value="avg" label="平均值"></el-option>
@@ -30,19 +48,37 @@
</el-select>
</el-form-item>
<el-form-item>
<div class="history_count" v-for="(item, index) in countData" :key="index"
v-show="item.countOptions.length != 0">
<span class="mr12">{{item.name.includes('次数') ? item.name : item.name + '谐波次数'}}</span>
<el-select v-model="item.count" @change="onCountChange($event, index)" placeholder="请选择谐波次数"
style="width: 100px" class="mr20">
<el-option v-for="vv in item.countOptions" :key="vv" :label="vv"
:value="vv"></el-option>
<div
class="history_count"
v-for="(item, index) in countData"
:key="index"
v-show="item.countOptions.length != 0"
>
<span class="mr12">
{{ item.name.includes('次数') ? item.name : item.name + '谐波次数' }}
</span>
<el-select
v-model="item.count"
@change="onCountChange($event, index)"
placeholder="请选择谐波次数"
style="width: 100px"
class="mr20"
>
<el-option
v-for="vv in item.countOptions"
:key="vv"
:label="vv"
:value="vv"
></el-option>
</el-select>
</div>
</el-form-item>
</template>
<template #operation>
<el-button type="primary" icon="el-icon-Search" @click="init()">查询</el-button>
<el-button :type="timeControl ? 'primary' : ''" icon="el-icon-Sort" @click="setTimeControl">
缺失数据
</el-button>
</template>
</TableHeader>
</div>
@@ -59,7 +95,7 @@ import { ref, onMounted, watch } from 'vue'
import MyEchart from '@/components/echarts/MyEchart.vue'
import { useDictData } from '@/stores/dictData'
import { queryStatistical } from '@/api/system-boot/csstatisticalset'
import { yMethod, exportCSV } from '@/utils/echartMethod'
import { yMethod, exportCSV, completeTimeSeries } from '@/utils/echartMethod'
import TableHeader from '@/components/table/header/index.vue'
import { getTabsDataByType } from '@/api/cs-device-boot/EquipmentDelivery'
import DatePicker from '@/components/form/datePicker/index.vue'
@@ -71,7 +107,7 @@ defineOptions({
})
const props = defineProps({
TrendList: {
type: Array,
type: Array
}
})
// console.log("🚀 ~ props:", props.TrendList)
@@ -81,7 +117,7 @@ const voltageLevelList = dictData.getBasicData('Dev_Voltage_Stand')
//接线方式
const volConTypeList = dictData.getBasicData('Dev_Connect')
const num = ref(0)
const timeControl = ref(false)
//值类型
const pageHeight = ref(mainHeight(290))
const loading = ref(true)
@@ -168,8 +204,8 @@ queryByCode(props?.TrendList?.lineType == 0 ? 'apf-harmonic' : 'portable-harmoni
})
init()
})
})
const chartsList = ref<any>([])
const activeName: any = ref()
const deviceData: any = ref([])
//历史趋势devId
@@ -191,7 +227,7 @@ const getTrendRequest = (val: any) => {
//初始化趋势图
const headerRef = ref()
const datePickerRef = ref()
const lineStyle = [{ type: 'solid', }, { type: 'dashed', }, { type: 'dotted', }]
const lineStyle = [{ type: 'solid' }, { type: 'dashed' }, { type: 'dotted' }]
const init = async () => {
loading.value = true
// 选择指标的时候切换legend内容和data数据
@@ -258,15 +294,28 @@ const init = async () => {
return
}
historyDataList.value = res.data
let chartsList = JSON.parse(JSON.stringify(res.data))
chartsList.value = JSON.parse(JSON.stringify(res.data))
loading.value = false
setEchart()
}
})
.catch(error => {
loading.value = false
})
} catch (error) {
loading.value = false
}
}
}
const setEchart = () => {
loading.value = true
echartsData.value = {}
//icon图标替换legend图例
// y轴单位数组
let unitList: any = []
let groupedData = chartsList.reduce((acc: any, item: any) => {
let groupedData = chartsList.value.reduce((acc: any, item: any) => {
let key = ''
if (item.phase == null) {
key = item.unit
@@ -283,7 +332,7 @@ const init = async () => {
let result = Object.values(groupedData)
// console.log("🚀 ~ .then ~ result:", result)
// console.log("🚀 ~ .then ~ result:", result)
if (chartsList.length > 0) {
if (chartsList.value.length > 0) {
unitList = result.map((item: any) => {
return item[0].unit
})
@@ -293,17 +342,16 @@ const init = async () => {
legend: {
itemWidth: 20,
itemHeight: 20,
itemStyle: { opacity: 0 },//去圆点
itemStyle: { opacity: 0 }, //去圆点
type: 'scroll', // 开启滚动分页
// orient: 'vertical', // 垂直排列
top: 5,
right: 70,
right: 70
// width: 550,
// height: 50
},
grid: {
top: '80px',
top: '80px'
},
tooltip: {
axisPointer: {
@@ -388,10 +436,10 @@ const init = async () => {
}
// console.log("🚀 ~ unitList.forEach ~ unitList:", unitList)
if (chartsList.length > 0) {
if (chartsList.value.length > 0) {
let yData: any = []
echartsData.value.yAxis = []
let setList = [...new Set(unitList)];
let setList = [...new Set(unitList)]
setList.forEach((item: any, index: any) => {
if (index > 2) {
@@ -416,19 +464,29 @@ const init = async () => {
})
// console.log("🚀 ~ result.forEach ~ result:", result)
// '电压负序分量', '电压正序分量', '电压零序分量'
let ABCName = [...new Set(chartsList.map((item: any) => { return item.anotherName == '电压负序分量' ? '电压不平衡' : item.anotherName == '电压正序分量' ? '电压不平衡' : item.anotherName == '电压零序分量' ? '电压不平衡' : item.anotherName }))];
let ABCName = [
...new Set(
chartsList.value.map((item: any) => {
return item.anotherName == '电压负序分量'
? '电压不平衡'
: item.anotherName == '电压正序分量'
? '电压不平衡'
: item.anotherName == '电压零序分量'
? '电压不平衡'
: item.anotherName
})
)
]
// console.log("🚀 ~ .then ~ ABCName:", ABCName)
result.forEach((item: any, index: any) => {
let yMethodList: any = []
let ABCList = Object.values(
item.reduce((acc, item) => {
let key = ''
if (item.phase == null) {
key = item.anotherName
} else {
key = item.phase
}
@@ -443,7 +501,17 @@ const init = async () => {
ABCList.forEach((kk: any) => {
let colorName = kk[0].phase?.charAt(0).toUpperCase()
let lineS = ABCName.findIndex(item => item === (kk[0].anotherName == '电压负序分量' ? '电压不平衡' : kk[0].anotherName == '电压正序分量' ? '电压不平衡' : kk[0].anotherName == '电压零序分量' ? '电压不平衡' : kk[0].anotherName));
let lineS = ABCName.findIndex(
item =>
item ===
(kk[0].anotherName == '电压负序分量'
? '电压不平衡'
: kk[0].anotherName == '电压正序分量'
? '电压不平衡'
: kk[0].anotherName == '电压零序分量'
? '电压不平衡'
: kk[0].anotherName)
)
let seriesList: any = []
kk.forEach((cc: any) => {
@@ -456,14 +524,14 @@ const init = async () => {
// console.log(kk);
echartsData.value.options.series.push({
name: kk[0].phase
? kk[0].phase + '相' + kk[0].anotherName
: kk[0].anotherName,
name: kk[0].phase ? kk[0].phase + '相' + kk[0].anotherName : kk[0].anotherName,
type: 'line',
smooth: true,
color: colorName == 'A' ? '#DAA520' : colorName == 'B' ? '#2E8B57' : colorName == 'C' ? '#A52a2a' : '',
color:
colorName == 'A' ? '#DAA520' : colorName == 'B' ? '#2E8B57' : colorName == 'C' ? '#A52a2a' : '',
symbol: 'none',
data: seriesList,
// data: seriesList,
data: timeControl.value ? completeTimeSeries(seriesList) : seriesList,
lineStyle: lineStyle[lineS],
yAxisIndex: setList.indexOf(kk[0].unit)
})
@@ -480,16 +548,12 @@ const init = async () => {
// console.log("🚀 ~ result.forEach ~ echartsData.value:", echartsData.value)
}
loading.value = false
}
})
.catch(error => {
loading.value = false
})
} catch (error) {
loading.value = false
}
}
}
const setTimeControl = () => {
timeControl.value = !timeControl.value
setEchart()
}
const selectChange = (flag: boolean) => {
if (flag) {
pageHeight.value = mainHeight(332)
@@ -600,7 +664,7 @@ const handleExport = async () => {
: (strs += list[index].data[indexs] + ',')
})
if (count == 0 && xAxis[indexs]) {
csv += `${xAxis[indexs]},` + strs + '\n'
csv += '\u200B' + `${xAxis[indexs]},` + strs + '\n'
}
})
return csv
@@ -639,7 +703,6 @@ const formatCountOptions = () => {
countData.value.push(vv)
}
})
})
// list.map((item: any, index: any) => {
// if (!countData.value[index]) {
@@ -702,9 +765,9 @@ const onIndexChange = (val: any) => {
num.value += 1
let pp: any = []
indexOptions.value.forEach((item: any) => {
const filteredResult = val.filter(vv => item.id == vv);
const filteredResult = val.filter(vv => item.id == vv)
if (filteredResult.length > 0) {
pp.push(filteredResult[0]);
pp.push(filteredResult[0])
}
})
searchForm.value.index = pp

View File

@@ -1,9 +1,14 @@
<template>
<div class="default-main device-manage" :style="{ height: pageHeight.height }">
<!-- @node-change="nodeClick" -->
<schemeTree @node-change="nodeClick" @node-click="nodeClick" @init="nodeClick" @onAdd="onAdd" @bind="bind"
ref="schemeTreeRef"></schemeTree>
<schemeTree
@node-change="nodeClick"
@node-click="nodeClick"
@init="nodeClick"
@onAdd="onAdd"
@bind="bind"
ref="schemeTreeRef"
></schemeTree>
<div class="device-manage-right" v-if="deviceData">
<el-descriptions title="方案信息" :column="2" border>
<!-- <template #extra>
@@ -23,8 +28,12 @@
<p>测试项信息</p>
</div> -->
<el-tabs v-model.trim="activeName" type="border-card" @tab-change="handleClickTabs">
<el-tab-pane v-for="(item, index) in deviceData?.records" :label="item.itemName"
:name="item.id" :key="index">
<el-tab-pane
v-for="(item, index) in deviceData?.records"
:label="item.itemName"
:name="item.id"
:key="index"
>
<template #label>
<span class="custom-tabs-label">
<el-icon>
@@ -110,11 +119,22 @@
<TableHeader :showSearch="false" ref="tableHeaderRef" @selectChange="selectChange">
<template v-slot:select :key="num">
<el-form-item for="-" label="统计指标">
<el-select style="min-width: 200px" collapse-tags collapse-tags-tooltip
v-model.trim="searchForm.index" placeholder="请选择统计指标"
@change="onIndexChange($event)" multiple :multiple-limit="3">
<el-option v-for="item in indexOptions" :key="item.id"
:label="item.name" :value="item.id"></el-option>
<el-select
style="min-width: 200px"
collapse-tags
collapse-tags-tooltip
v-model.trim="searchForm.index"
placeholder="请选择统计指标"
@change="onIndexChange($event)"
multiple
:multiple-limit="3"
>
<el-option
v-for="item in indexOptions"
:key="item.id"
:label="item.name"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
<el-form-item>
@@ -125,26 +145,53 @@
<el-radio-group v-model.trim="searchForm.dataLevel" @change="init(true)">
<el-radio-button label="一次值" value="Primary" />
<el-radio-button label="二次值" value="Secondary" />
</el-radio-group>
</el-form-item>
<el-form-item for="-" label="统计类型" label-width="80px">
<el-select style="width: 120px" v-model.trim="searchForm.type"
placeholder="请选择值类型">
<el-option v-for="item in typeOptions" :key="item.id" :label="item.name"
:value="item.id"></el-option>
<el-select
style="width: 120px"
v-model.trim="searchForm.type"
placeholder="请选择值类型"
>
<el-option
v-for="item in typeOptions"
:key="item.id"
:label="item.name"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
<el-form-item>
<div for="-" v-for="(item, index) in countData" :key="index"
v-show="item.countOptions.length != 0">
<span class="mr12">{{item.name.includes('次数') ? item.name : item.name.includes('幅值') ? item.name.slice(0, -2) + '次数' : item.name + '谐波次数'}}</span>
<el-select v-model.trim="item.count" class="mr20" collapse-tags collapse-tags-tooltip
placeholder="请选择谐波次数" style="width: 120px">
<el-option v-for="vv in item.countOptions" :key="vv" :label="vv"
:value="vv"></el-option>
<div
for="-"
v-for="(item, index) in countData"
:key="index"
v-show="item.countOptions.length != 0"
>
<span class="mr12">
{{
item.name.includes('次数')
? item.name
: item.name.includes('幅值')
? item.name.slice(0, -2) + '次数'
: item.name + '谐波次数'
}}
</span>
<el-select
v-model.trim="item.count"
class="mr20"
collapse-tags
collapse-tags-tooltip
placeholder="请选择谐波次数"
style="width: 120px"
>
<el-option
v-for="vv in item.countOptions"
:key="vv"
:label="vv"
:value="vv"
></el-option>
</el-select>
</div>
</el-form-item>
@@ -153,28 +200,43 @@
<!-- <el-button type="primary" icon="el-icon-Download" @click="handleExport">
数据导出
</el-button> -->
<el-button type="primary" icon="el-icon-Search"
@click="init(true)">查询</el-button>
<el-button type="primary" icon="el-icon-Search" @click="init(true)">
查询
</el-button>
<!-- <el-button
:type="timeControl ? 'primary' : ''"
icon="el-icon-Sort"
@click="setTimeControl"
>
缺失数据
</el-button> -->
</template>
</TableHeader>
</div>
<!-- <div class="history_title">
<p>{{ chartTitle }}</p>
</div> -->
<div class="history_chart mt5" v-loading="loading" :style="EcharHeight"
:key="EcharHeight.height" ref="chartRef">
<MyEchart ref="historyChart" v-if="echartsData" :isExport="true"
:options="echartsData" />
<div
class="history_chart mt5"
v-loading="loading"
:style="EcharHeight"
:key="EcharHeight.height"
ref="chartRef"
>
<MyEchart
ref="historyChart"
v-if="echartsData"
:isExport="true"
:options="echartsData"
/>
</div>
</div>
<el-empty :style="EcharHeight" v-else description="未绑定数据" />
</el-tab-pane>
<el-tab-pane label="暂态数据" name="1">
<transient :activeName='activeName' ref="transientRef" :activeColName="activeColName" />
<transient :activeName="activeName" ref="transientRef" :activeColName="activeColName" />
</el-tab-pane>
</el-tabs>
</div>
</div>
<el-empty v-else description="请选择设备" class="device-manage-right" />
@@ -193,8 +255,8 @@ import MyEchart from '@/components/echarts/MyEchart.vue'
import { getTestRecordInfo, getHistoryTrend } from '@/api/cs-device-boot/planData'
import { useDictData } from '@/stores/dictData'
import { queryStatistical } from '@/api/system-boot/csstatisticalset'
import { TrendCharts, Plus, Platform, } from '@element-plus/icons-vue'
import { yMethod } from '@/utils/echartMethod'
import { TrendCharts, Plus, Platform } from '@element-plus/icons-vue'
import { yMethod, completeTimeSeries } from '@/utils/echartMethod'
import { color, gradeColor3 } from '@/components/echarts/color'
import TableHeader from '@/components/table/header/index.vue'
import { useConfig } from '@/stores/config'
@@ -208,6 +270,8 @@ const childTab = ref('0')
const num = ref(0)
const config = useConfig()
const transientRef = ref()
const timeControl = ref(false)
const chartsList = ref([])
color[0] = config.layout.elementUiPrimary[0]
//电压等级
const voltageLevelList = dictData.getBasicData('Dev_Voltage_Stand')
@@ -330,16 +394,16 @@ const nodeClick = async (e: anyObj) => {
if (res.data.records.length == 1) {
activeName.value = res.data.records[0].id
} else {
for (const item of res.data.records) {
if (item.id == e.id) {
activeName.value = item.id;
break; // 找到匹配项后停止遍历
activeName.value = item.id
break // 找到匹配项后停止遍历
}
}
// 如果没有找到匹配项默认设置为第一个元素的id
if (activeName.value !== e.id) { // 假设e.id是一个用于比较的初始值表示未找到匹配项
activeName.value = res.data.records[0].id;
if (activeName.value !== e.id) {
// 假设e.id是一个用于比较的初始值表示未找到匹配项
activeName.value = res.data.records[0].id
}
}
@@ -369,9 +433,9 @@ const onIndexChange = (val: any) => {
num.value += 1
let pp: any = []
indexOptions.value.forEach((item: any) => {
const filteredResult = val.filter(vv => item.id == vv);
const filteredResult = val.filter(vv => item.id == vv)
if (filteredResult.length > 0) {
pp.push(filteredResult[0]);
pp.push(filteredResult[0])
}
})
searchForm.value.index = pp
@@ -432,7 +496,7 @@ const range = (start: any, end: any, step: any) => {
return Array.from({ length: (end - start) / step + 1 }, (_, i) => start + i * step)
}
const colors = ['#DAA520', '#2E8B57', '#A52a2a']
const lineStyle = [{ type: 'solid', }, { type: 'dashed', }, { type: 'dotted', }]
const lineStyle = [{ type: 'solid' }, { type: 'dashed' }, { type: 'dotted' }]
const titleList: any = ref('')
const init = (flag: boolean) => {
@@ -451,7 +515,6 @@ const init = (flag: boolean) => {
})
})
//选择的指标使用方法处理
formatCountOptions()
//查询历史趋势
@@ -471,7 +534,7 @@ const init = (flag: boolean) => {
middleTitle = ''
}
let indexList = searchForm.value.index
chartTitle.value = ''//deviceData.value.itemName + '_' + middleTitle + '_'
chartTitle.value = '' //deviceData.value.itemName + '_' + middleTitle + '_'
indexList.map((item: any, indexs: any) => {
indexOptions.value.map((vv: any) => {
if (vv.id == item) {
@@ -494,9 +557,6 @@ const init = (flag: boolean) => {
}
})
let obj = {
devId: historyDevId.value,
list: lists,
@@ -508,7 +568,6 @@ const init = (flag: boolean) => {
return
}
if (flag) {
getDeviceList({
id: historyDevId.value,
isTrueFlag: 1
@@ -524,14 +583,31 @@ const init = (flag: boolean) => {
.then((res: any) => {
if (res.code === 'A0000') {
historyDataList.value = res.data
let chartsList = JSON.parse(JSON.stringify(res.data))
chartsList.value = JSON.parse(JSON.stringify(res.data))
loading.value = false
setEchart()
}
})
.catch(error => {
loading.value = false
})
} else {
loading.value = false
}
}
}
const setEchart = () => {
loading.value = true
echartsData.value = {}
//icon图标替换legend图例
// y轴单位数组
let unitList: any = []
let groupedData = chartsList.reduce((acc: any, item: any) => {
let groupedData = chartsList.value.reduce((acc: any, item: any) => {
let key = ''
if (item.phase == null) {
key = item.unit
@@ -546,14 +622,13 @@ const init = (flag: boolean) => {
}, {})
let result = Object.values(groupedData)
if (chartsList.length > 0) {
if (chartsList.value.length > 0) {
unitList = result.map((item: any) => {
return item[0].unit
})
}
echartsData.value = {
// title: {
// text: chartTitle.value,
// left: '0',
@@ -572,7 +647,6 @@ const init = (flag: boolean) => {
icon: 'path://M588.8 551.253333V512H352v39.253333h236.373333z m0 78.933334v-39.253334H352v39.253334h236.373333z m136.533333 78.933333V334.933333l-157.866666-157.866666H273.066667A59.306667 59.306667 0 0 0 213.333333 236.373333v551.253334a59.306667 59.306667 0 0 0 59.306667 59.306666h274.773333v42.666667H853.333333v-180.48zM568.746667 234.666667l100.266666 100.693333h-81.066666a20.053333 20.053333 0 0 1-19.626667-20.053333z m-20.48 573.013333H273.066667a19.2 19.2 0 0 1-17.493334-19.626667V236.373333a19.2 19.2 0 0 1 19.626667-19.626666h256v98.133333a58.88 58.88 0 0 0 58.88 59.306667h96.426667v334.933333h-98.133334v-39.68H352v39.68h196.266667z m100.266666 23.04a37.973333 37.973333 0 0 1-32 15.786667 38.826667 38.826667 0 0 1-32.426666-15.786667 53.76 53.76 0 0 1-10.24-32.853333 42.666667 42.666667 0 0 1 42.666666-47.786667 35.84 35.84 0 0 1 37.546667 29.866667h-12.8a23.893333 23.893333 0 0 0-24.746667-19.2c-17.066667 0-29.013333 14.08-29.013333 35.84s11.52 37.546667 28.586667 37.546666a26.453333 26.453333 0 0 0 26.453333-25.6h12.8a39.253333 39.253333 0 0 1-7.253333 22.186667z m59.733334 15.786667a35.84 35.84 0 0 1-40.106667-34.56H682.666667a23.893333 23.893333 0 0 0 26.88 23.04c12.8 0 22.613333-6.4 22.613333-15.786667s-4.266667-11.52-14.506667-13.653333l-21.333333-5.12c-17.066667-4.266667-24.32-11.52-24.32-23.893334s12.8-26.453333 34.133333-26.453333a31.573333 31.573333 0 0 1 35.413334 30.293333h-13.653334a19.626667 19.626667 0 0 0-22.613333-18.773333c-12.8 0-20.48 5.12-20.48 12.8s5.12 11.093333 17.066667 13.653333l14.933333 2.986667a42.666667 42.666667 0 0 1 20.906667 8.96 23.893333 23.893333 0 0 1 7.68 17.92c-0.426667 17.066667-14.506667 28.16-37.12 28.16z m88.746666 0h-14.506666l-32.426667-92.16h14.08l19.626667 59.733333 6.4 20.053333c0-9.386667 3.413333-12.8 5.546666-20.053333l19.2-59.733333h14.08z',
onclick: e => {
handleExport()
}
}
}
@@ -580,16 +654,15 @@ const init = (flag: boolean) => {
legend: {
itemWidth: 20,
itemHeight: 20,
itemStyle: { opacity: 0 },//去圆点
itemStyle: { opacity: 0 }, //去圆点
type: 'scroll', // 开启滚动分页
right: 70,
right: 70
// width: 550,
// height: 50
},
grid: {
top: '80px',
top: '80px'
},
tooltip: {
axisPointer: {
@@ -620,9 +693,9 @@ const init = (flag: boolean) => {
} else {
marker = `<span style="display:inline-block;border: 2px ${el.color} ${el.value[3]};margin-right:5px;width:40px;height:0px;background-color:#ffffff00;"></span>`
}
str += `${marker}${el.seriesName.split('(')[0]}${el.value[1] ? el.value[1] + ' ' + (el.value[2] || '') : '-'
str += `${marker}${el.seriesName.split('(')[0]}${
el.value[1] ? el.value[1] + ' ' + (el.value[2] || '') : '-'
}<br>`
})
return str
}
@@ -641,14 +714,13 @@ const init = (flag: boolean) => {
yAxis: [{}],
options: {
series: []
}
}
if (chartsList.length > 0) {
if (chartsList.value.length > 0) {
let yData: any = []
echartsData.value.yAxis = []
let setList = [...new Set(unitList)];
let setList = [...new Set(unitList)]
setList.forEach((item: any, index: any) => {
if (index > 2) {
@@ -671,8 +743,19 @@ const init = (flag: boolean) => {
})
})
// console.log("🚀 ~ result.forEach ~ result:", result)
let ABCName = [...new Set(chartsList.map((item: any) => { return item.anotherName == '电压负序分量' ? '电压不平衡' : item.anotherName == '电压正序分量' ? '电压不平衡' : item.anotherName == '电压零序分量' ? '电压不平衡' : item.anotherName }))];
let ABCName = [
...new Set(
chartsList.value.map((item: any) => {
return item.anotherName == '电压负序分量'
? '电压不平衡'
: item.anotherName == '电压正序分量'
? '电压不平衡'
: item.anotherName == '电压零序分量'
? '电压不平衡'
: item.anotherName
})
)
]
result.forEach((item: any, index: any) => {
let yMethodList: any = []
@@ -686,7 +769,6 @@ const init = (flag: boolean) => {
key = item.phase
}
if (!acc[key]) {
acc[key] = []
}
@@ -695,13 +777,19 @@ const init = (flag: boolean) => {
}, {})
)
ABCList.forEach((kk: any) => {
let colorName = kk[0].phase?.charAt(0).toUpperCase()
let lineS = ABCName.findIndex(item => item === (kk[0].anotherName == '电压负序分量' ? '电压不平衡' : kk[0].anotherName == '电压正序分量' ? '电压不平衡' : kk[0].anotherName == '电压零序分量' ? '电压不平衡' : kk[0].anotherName));
let lineS = ABCName.findIndex(
item =>
item ===
(kk[0].anotherName == '电压负序分量'
? '电压不平衡'
: kk[0].anotherName == '电压正序分量'
? '电压不平衡'
: kk[0].anotherName == '电压零序分量'
? '电压不平衡'
: kk[0].anotherName)
)
let seriesList: any = []
kk.forEach((cc: any) => {
if (cc.statisticalData !== null) {
@@ -710,15 +798,15 @@ const init = (flag: boolean) => {
seriesList.push([cc.time, cc.statisticalData?.toFixed(2), cc.unit, lineStyle[lineS].type])
})
echartsData.value.options.series.push({
name: kk[0].phase
? kk[0].phase + '相' + kk[0].anotherName
: kk[0].anotherName,
name: kk[0].phase ? kk[0].phase + '相' + kk[0].anotherName : kk[0].anotherName,
type: 'line',
color: colorName == 'A' ? '#DAA520' : colorName == 'B' ? '#2E8B57' : colorName == 'C' ? '#A52a2a' : '',
color:
colorName == 'A' ? '#DAA520' : colorName == 'B' ? '#2E8B57' : colorName == 'C' ? '#A52a2a' : '',
smooth: true,
symbol: 'none',
lineStyle: lineStyle[lineS],
data: seriesList,
// data: seriesList,
data: timeControl.value ? completeTimeSeries(seriesList) : seriesList,
yAxisIndex: setList.indexOf(kk[0].unit)
})
})
@@ -733,22 +821,12 @@ const init = (flag: boolean) => {
echartsData.value.yAxis[index].min = min
echartsData.value.yAxis[index].max = max
})
}
loading.value = false
}
})
.catch(error => {
loading.value = false
})
} else {
loading.value = false
}
}
}
const setTimeControl = () => {
timeControl.value = !timeControl.value
setEchart()
}
//导出
const historyChart = ref()
@@ -828,6 +906,7 @@ const handleExport = async () => {
let csv = ''
csv = title
// 遍历数据并添加到CSV字符串中
list[0]?.data.map((vv: any, indexs: any) => {
let strs = '',
count = null
@@ -843,11 +922,11 @@ const handleExport = async () => {
index == list.length - 1 ? (strs += '/') : (strs += '/,')
}
})
if (count == 0 && xAxis[indexs]) {
csv += `${xAxis[indexs]},` + strs + '\n'
} else {
strs += '/,'
}
// if (count == 0 && xAxis[indexs]) {
csv += '\u200B' + `${vv[0]},` + strs + '\n'
// } else {
// strs += '/,'
// }
})
return csv
}
@@ -878,7 +957,6 @@ const tableHeaderRef = ref()
//根据选择的指标处理谐波次数
const formatCountOptions = () => {
countData.value = []
// console.log(123, indexOptions.value);
@@ -889,7 +967,6 @@ const formatCountOptions = () => {
countData.value.push(vv)
}
})
})
// indexOptions.value.map((item: any, index: any) => {
// if (!countDataCopy.value[index]) {
@@ -944,7 +1021,6 @@ const formatCountOptions = () => {
}
setTimeout(() => {
tableHeaderRef.value && tableHeaderRef.value?.computedSearchRow()
}, 100)
}
@@ -969,7 +1045,6 @@ const selectChange = (e: boolean) => {
}
const handleChange = () => {
if (activeColName.value == '0') {
if (flag.value) {
EcharHeight.value = mainHeight(480)
@@ -985,15 +1060,13 @@ const handleChange = () => {
}
setTimeout(() => {
transientRef.value && transientRef.value.setHeight()
}, 100);
}, 100)
}
watch(
() => searchForm.value.index,
(val: any, oldval: any) => {
// if (val) {
// let list = val
// setTimeout(() => {
// formatCountOptions(list)
@@ -1007,7 +1080,6 @@ watch(
// countData.value.splice(key, 1)
// }
// })
// init(false)
// }
},
@@ -1017,7 +1089,6 @@ watch(
}
)
onMounted(() => {
setTimeout(() => {
init(true)
}, 1500)

View File

@@ -14,7 +14,6 @@
<script lang="ts" setup>
import { ref, onMounted, provide, nextTick, defineEmits, watch } from 'vue'
import { getTabsDataByType } from '@/api/cs-device-boot/EquipmentDelivery'
import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue'
import TableHeader from '@/components/table/header/index.vue'