Merge remote-tracking branch 'origin/main'

This commit is contained in:
yu 2024-11-01 09:13:20 +08:00
commit 98b1348a4c
4 changed files with 89 additions and 85 deletions

View File

@ -61,7 +61,7 @@ const props = defineProps({
},
})
const selectedIndex = ref(null)
const selectedIndex: any = ref(null)
const tableColumn = [
{
type: 'selection',
@ -98,12 +98,12 @@ const tableColumn = [
]
const tableData = ref<any[]>([])
const emit = defineEmits(['handleRadioChange'])
const handleRadioChange = (row) => {
const handleRadioChange = (row: any) => {
selectedIndex.value = row.attributeCode
emit('handleRadioChange', row)
}
const getAttributeList = () => {
const requestData: GetModelAttributeType = {
const requestData: any = {
iotModelId: props.iotModelId,
pageNum: pageSetting.current,
pageSize: pageSetting.pageSize,

View File

@ -18,7 +18,7 @@ const activeIndex = ref(1)
const { t } = useI18n()
const headerList = [t('statAnalysis.PowerCurveAnalysis'), t('statAnalysis.trendAnalysis'), t('statAnalysis.trendComparison')]
const handleSelect = (index) => {
const handleSelect = (index: number) => {
activeIndex.value = index
}
</script>

View File

@ -24,12 +24,7 @@
</div>
<div class="selectPart">
<span>{{ t('statAnalysis.interval') }}</span>
<el-select
v-model="statAnalysisSelect.interval"
@change="selectstatAnalysis('interval')"
:placeholder="'请选择' + t('statAnalysis.interval')"
class="statAnalysisSelect"
>
<el-select v-model="statAnalysisSelect.interval" :placeholder="'请选择' + t('statAnalysis.interval')" class="statAnalysisSelect">
<el-option v-for="v in statAnalysisSelectOptions.interval" :key="v.value" :label="v.label" :value="v.value"></el-option>
</el-select>
</div>
@ -103,10 +98,10 @@
</div>
</template>
<script setup lang="ts">
import { onUnmounted, reactive, ref, watch, nextTick, onMounted, computed } from 'vue'
import { reactive, ref, onMounted } from 'vue'
import { useI18n } from 'vue-i18n'
import { queryWindTurbinesPages, historyReq } from '/@/api/backend/statAnalysis/request'
import { ElMessage, ElMenu } from 'element-plus'
import { ElMessage } from 'element-plus'
import { DArrowRight, Plus, Delete } from '@element-plus/icons-vue'
import MeasurementPage from './analysisAttributes.vue'
import * as echarts from 'echarts'
@ -118,23 +113,22 @@ const statAnalysisSelect = reactive({
interval: '',
time: '',
})
const times = reactive([{ time: '' }])
const addTime = (index) => {
const times: any = reactive([{ time: '' }])
const addTime = (index: any) => {
times.push({ time: '' })
customName.push(String(index + 2))
customName.push(statAnalysisSelect.attributes + String(index + 2))
}
const switchTime = (index) => {
const switchTime = (index: number) => {
times.splice(index, 1)
customName.splice(index, 1)
calculate.splice(index, 1)
xData.splice(index, 1)
}
const timechange = (value) => {
const timechange = (value: any) => {
const count = getTimeIntervals(times[0][0], times[0][1])
const count1 = getTimeIntervals(times[value][0], times[value][1])
if (count !== count1) {
times[value] = { time: '' }
value = ElMessage.warning('查询时间点错误,请重新输入')
ElMessage.warning('查询时间点错误,请重新输入')
}
}
const isExpand = ref(false)
@ -145,7 +139,7 @@ const handleClick = () => {
const iotModelId = ref('')
const irn = ref('')
const attributesChange = () => {
const row = statAnalysisSelectOptions.deviceId.filter((item) => {
const row: any = statAnalysisSelectOptions.deviceId.filter((item: any) => {
return item.value == statAnalysisSelect.deviceId
})
if (row.length) {
@ -163,11 +157,11 @@ const deviceIdChange = () => {
}
const showMeasure = ref(false)
const selectedAttrRow = ref({
const selectedAttrRow: any = ref({
attributeCode: '',
attributeName: '',
})
const handleRadioChange = (value) => {
const handleRadioChange = (value: any) => {
const { attributeCode, attributeName } = { ...value }
selectedAttrRow.attributeCode = attributeCode
selectedAttrRow.attributeName = attributeName
@ -176,11 +170,14 @@ const selectstatAnalysisAttributes = () => {
statAnalysisSelect.attributes = selectedAttrRow.attributeName
statAnalysisSelect.attributeCode = selectedAttrRow.attributeCode
showMeasure.value = false
customName.forEach((item: any, index: number, arr: any) => {
arr[index] = statAnalysisSelect.attributes + String(index + 1)
})
}
const chartContainer = ref<HTMLElement | null>(null)
const option = {
const option: any = {
tooltip: {},
legend: {
icon: 'circle',
@ -203,7 +200,7 @@ const option = {
},
}
const statAnalysisSelectOptions = reactive({
const statAnalysisSelectOptions: any = reactive({
interval: [
{ label: '五分钟', value: '5m' },
{ label: '十五分钟', value: '15m' },
@ -213,8 +210,8 @@ const statAnalysisSelectOptions = reactive({
],
deviceId: [],
})
const customName = reactive(['1'])
const chart = ref(null)
const customName = reactive([statAnalysisSelect.attributes + '1'])
const chart: any = ref(null)
onMounted(() => {
if (chartContainer.value) {
@ -226,7 +223,7 @@ onMounted(() => {
const queryWindTurbines = () => {
queryWindTurbinesPages().then((res) => {
if (res.code == 200) {
statAnalysisSelectOptions.deviceId = res.data.map((item) => {
statAnalysisSelectOptions.deviceId = res.data.map((item: any) => {
return {
value: item.irn,
label: item.name ?? '-',
@ -241,11 +238,6 @@ window.onresize = () => {
chart.value.resize()
}
const handleSelect = (index) => {
activeIndex.value = index
}
const selectstatAnalysis = () => {}
const shortcuts = [
{
text: '今天',
@ -284,7 +276,7 @@ const shortcuts = [
},
},
]
const getFormattedDate = (offset) => {
const getFormattedDate = (offset: number) => {
const date = new Date()
date.setDate(date.getDate() + offset)
@ -313,9 +305,9 @@ const getDateRange = (type: 'week' | 'month') => {
return [startOfMonth, endOfMonth]
}
}
const getTimeIntervals = (startTimestamp, endTimestamp) => {
const startDate = new Date(startTimestamp)
const endDate = new Date(endTimestamp)
const getTimeIntervals = (startTimestamp: number, endTimestamp: number) => {
const startDate: any = new Date(startTimestamp)
const endDate: any = new Date(endTimestamp)
let count = 0
switch (statAnalysisSelect.interval) {
@ -332,7 +324,7 @@ const getTimeIntervals = (startTimestamp, endTimestamp) => {
count = Math.floor((endDate - startDate) / (1 * 60 * 60 * 1000))
break
case '1d':
count = c((endDate - startDate) / (1 * 24 * 60 * 60 * 1000))
count = Math.floor((endDate - startDate) / (1 * 24 * 60 * 60 * 1000))
break
// default:
// throw new Error('Invalid interval')
@ -340,14 +332,14 @@ const getTimeIntervals = (startTimestamp, endTimestamp) => {
return count
}
const calculate = reactive([{ max: '', min: '', average: '' }])
var xDatas = []
const calculate: any = reactive([{ max: '', min: '', average: '' }])
var xDatas: any = []
const statAnalysisOperate = () => {
option.series = []
option.legend.data = []
xDatas = []
chart.value.setOption(option, { notMerge: true })
times.forEach((time, index) => {
times.forEach((time: any, index: number) => {
if (time[0] && time[1]) {
const requestData = {
devices: [
@ -365,7 +357,7 @@ const statAnalysisOperate = () => {
})
}
const historyDataReq = (data, index) => {
const historyDataReq = (data: any, index: number) => {
historyReq(data).then((res) => {
if (res.code == 200) {
const deviceId = statAnalysisSelect.deviceId
@ -374,19 +366,15 @@ const historyDataReq = (data, index) => {
if (resData) {
const xData = resData['times']
const yData = resData['values']
calculate[index] = {
max: Math.floor(Math.max(...yData)),
min: Math.floor(Math.min(...yData)),
average: Math.floor(yData.reduce((a, b) => a + b, 0) / yData.length),
}
calculate[index] = calculateStats(yData)
xDatas.push({
series: String(customName[index]),
data: xData,
})
option.tooltip = {
show: true,
formatter: function (params) {
const matchData = xDatas.filter((x) => x.series == params.seriesName)
formatter: function (params: any) {
const matchData = xDatas.filter((x: any) => x.series == params.seriesName)
const x = timestampToTime(matchData[0]['data'][params.dataIndex])
return `${params.marker} ${params.seriesName} <br/> ${x} <b>${params.data}</b>`
},
@ -413,7 +401,19 @@ const historyDataReq = (data, index) => {
const statAnalysisExport = () => {}
const statAnalysiImport = () => {}
const timestampToTime = (timestamp) => {
function calculateStats(numbers: any) {
const max = Math.max(...numbers)
const min = Math.min(...numbers)
const sum = numbers.reduce((acc: number, current: number) => acc + current, 0)
const average = sum / numbers.length
return {
max: max.toFixed(2),
min: min.toFixed(2),
average: average.toFixed(2),
}
}
const timestampToTime = (timestamp: any) => {
timestamp = timestamp ? timestamp : null
let date = new Date(timestamp)
let Y = date.getFullYear() + '-'
@ -482,7 +482,7 @@ const timestampToTime = (timestamp) => {
color: #0064aa;
}
.customName {
width: 80px;
width: fit-content;
margin-right: 10px;
}
}

View File

@ -116,8 +116,8 @@ const statAnalysisTime = ref('')
const statAnalysisInterval = ref('')
const statAnalysisDeviceId = reactive([''])
const statAnalysisAttributes = reactive([''])
const statAnalysisAttributeCode = reactive([])
const statAnalysisSelectOptions = reactive({
const statAnalysisAttributeCode: any = reactive([])
const statAnalysisSelectOptions: any = reactive({
interval: [
{ label: '五分钟', value: '5m' },
{ label: '十五分钟', value: '15m' },
@ -128,13 +128,12 @@ const statAnalysisSelectOptions = reactive({
deviceId: [],
})
const openModelIndex = ref(0)
const selectediotModelId = ref('')
const addDevice = (index) => {
const addDevice = (index: number) => {
statAnalysisDeviceId.push('')
statAnalysisAttributes.push('')
customName.push(String(index + 2))
}
const switchDevice = (index) => {
const switchDevice = (index: number) => {
statAnalysisDeviceId.splice(index, 1)
statAnalysisAttributes.splice(index, 1)
statAnalysisAttributeCode.splice(index, 1)
@ -148,8 +147,8 @@ const handleClick = () => {
}
const iotModelId = ref('')
const irn = ref('')
const selectAtteibutes = (index) => {
const row = statAnalysisSelectOptions.deviceId.filter((item) => {
const selectAtteibutes = (index: number) => {
const row = statAnalysisSelectOptions.deviceId.filter((item: any) => {
return item.value == statAnalysisDeviceId[index]
})
if (row.length) {
@ -162,7 +161,7 @@ const selectAtteibutes = (index) => {
}
}
const deviceIdChange = (index) => {
const deviceIdChange = (index: number) => {
statAnalysisAttributeCode[index] = ''
statAnalysisAttributes[index] = ''
}
@ -172,7 +171,7 @@ const selectedAttrRow = reactive({
attributeCode: '',
attributeName: '',
})
const handleRadioChange = (value) => {
const handleRadioChange = (value: any) => {
const { attributeCode, attributeName } = { ...value }
selectedAttrRow.attributeCode = attributeCode
selectedAttrRow.attributeName = attributeName
@ -181,11 +180,14 @@ const selectstatAnalysisAttributes = () => {
statAnalysisAttributes[openModelIndex.value] = selectedAttrRow.attributeName
statAnalysisAttributeCode[openModelIndex.value] = selectedAttrRow.attributeCode
showMeasure.value = false
customName.forEach((item: any, index: number, arr: any) => {
arr[openModelIndex.value] = statAnalysisAttributes[openModelIndex.value] + String(index + 1)
})
}
const chartContainer = ref<HTMLElement | null>(null)
const option = {
const option: any = {
tooltip: {},
legend: {
icon: 'circle',
@ -212,7 +214,7 @@ const option = {
}
const customName = reactive(['1'])
const chart = ref(null)
const chart: any = ref(null)
onMounted(() => {
if (chartContainer.value) {
chart.value = echarts.init(chartContainer.value)
@ -223,7 +225,7 @@ onMounted(() => {
const queryWindTurbines = () => {
queryWindTurbinesPages().then((res) => {
if (res.code == 200) {
statAnalysisSelectOptions.deviceId = res.data.map((item) => {
statAnalysisSelectOptions.deviceId = res.data.map((item: any) => {
return {
value: item.irn,
label: item.name ?? '-',
@ -238,11 +240,6 @@ window.onresize = () => {
chart.value.resize()
}
const handleSelect = (index) => {
activeIndex.value = index
}
const selectstatAnalysis = () => {}
const shortcuts = [
{
text: '今天',
@ -281,7 +278,7 @@ const shortcuts = [
},
},
]
const getFormattedDate = (offset) => {
const getFormattedDate = (offset: number) => {
const date = new Date()
date.setDate(date.getDate() + offset)
@ -315,8 +312,8 @@ const statAnalysisOperate = () => {
option.series = []
chart.value.setOption(option, { notMerge: true })
const attributes = statAnalysisAttributeCode
const devices = statAnalysisDeviceId.reduce((deviceId, curr, index) => {
const existing = deviceId.find((item) => item.deviceId === curr)
const devices = statAnalysisDeviceId.reduce((deviceId: any, curr, index) => {
const existing: any = deviceId.find((item: any) => item.deviceId === curr)
if (existing) {
existing.attributes.push(statAnalysisAttributeCode[index])
} else {
@ -330,10 +327,10 @@ const statAnalysisOperate = () => {
startTime: new Date(statAnalysisTime.value[0]).getTime(),
endTime: new Date(statAnalysisTime.value[1]).getTime(),
}
historyDataReq(requestData, devices)
historyDataReq(requestData)
}
const calculate = reactive([{ max: '', min: '', average: '' }])
const historyDataReq = (data, devices) => {
const calculate: any = reactive([{ max: '', min: '', average: '' }])
const historyDataReq = (data: any) => {
historyReq(data).then((res) => {
if (res.code == 200) {
const resData = res.data
@ -353,13 +350,9 @@ const historyDataReq = (data, devices) => {
type: 'line',
data: yData,
}
calculate[dataIndex] = {
max: Math.floor(Math.max(...yData)),
min: Math.floor(Math.min(...yData)),
average: Math.floor(yData.reduce((a, b) => a + b, 0) / yData.length),
}
calculate[dataIndex] = calculateStats(yData)
option.legend.data.push(customName[dataIndex])
option.xAxis.data = xData.map((item) => timestampToTime(item))
option.xAxis.data = xData.map((item: any) => timestampToTime(item))
option.series.push(seriesData)
chart.value.setOption(option)
})
@ -371,17 +364,28 @@ const historyDataReq = (data, devices) => {
})
}
const findAllOccurrences = (arr, target) => {
return arr.map((value, index) => (value === target ? index : -1)).filter((index) => index !== -1)
const findAllOccurrences = (arr: any, target: any) => {
return arr.map((value: any, index: number) => (value === target ? index : -1)).filter((index: number) => index !== -1)
}
const getCommonElements = (arr1, arr2) => {
return arr1.filter((item) => arr2.some((x) => x === item))
const getCommonElements = (arr1: any, arr2: any) => {
return arr1.filter((item: any) => arr2.some((x: any) => x === item))
}
const statAnalysisExport = () => {}
const statAnalysiImport = () => {}
function calculateStats(numbers: any) {
const max = Math.max(...numbers)
const min = Math.min(...numbers)
const sum = numbers.reduce((acc: number, current: number) => acc + current, 0)
const average = sum / numbers.length
const timestampToTime = (timestamp) => {
return {
max: max.toFixed(2),
min: min.toFixed(2),
average: average.toFixed(2),
}
}
const timestampToTime = (timestamp: any) => {
timestamp = timestamp ? timestamp : null
let date = new Date(timestamp)
let Y = date.getFullYear() + '-'
@ -417,7 +421,7 @@ const timestampToTime = (timestamp) => {
margin-right: 10px;
}
.customName {
width: 80px;
width: fit-content;
margin-right: 10px;
}
.statAnalysisSelect {