2023-06-06 10:07:59 +00:00
|
|
|
<template>
|
|
|
|
<div :class="$style['container']">
|
|
|
|
<div class="header">
|
|
|
|
<div class="title">
|
2023-06-08 07:58:40 +00:00
|
|
|
<header2 ref="headerref" :width="'100%'" :height="'100px'" :title="t('messages.传感器监测走势图')" :titleTip="[]"
|
|
|
|
:typeFun="['comback', 'time']" :alarmType="[]"></header2>
|
2023-06-06 10:07:59 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="content">
|
2023-06-08 07:58:40 +00:00
|
|
|
<lineChart v-for="(calc, index) in calcArr"
|
|
|
|
:style="{ width: width + 'px', height: height + 'px', 'min-width': 'calc(25% - 20px)' }" :calc="calc">
|
2023-06-06 10:07:59 +00:00
|
|
|
</lineChart>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang='ts'>
|
|
|
|
import { ref, reactive, onMounted, onUnmounted } from "vue"
|
|
|
|
import Header2 from "@/components/headerBox/header2.vue"
|
|
|
|
import lineChart from "./lineChart.vue";
|
2023-06-08 07:58:40 +00:00
|
|
|
import { getCurrent24Trend } from '@/http/Trend/index'
|
|
|
|
import { useRoute } from "vue-router";
|
|
|
|
import { useI18n } from 'vue-i18n'
|
|
|
|
let { t } = useI18n();
|
|
|
|
let route = useRoute()
|
|
|
|
let ids = route.query.ids as string
|
|
|
|
let unit = route.query.unit as string
|
2023-07-21 09:30:42 +00:00
|
|
|
let limit = route.query.limit as string
|
2023-06-08 07:58:40 +00:00
|
|
|
let timer = null
|
2023-06-08 10:07:29 +00:00
|
|
|
document.title = t('messages.传感器监测走势图')
|
2023-06-06 10:07:59 +00:00
|
|
|
type calcType = {
|
|
|
|
name: string,
|
2023-06-08 07:58:40 +00:00
|
|
|
math: {
|
|
|
|
key: string,
|
|
|
|
value: {
|
|
|
|
max: number,
|
|
|
|
min: number,
|
|
|
|
avg: number,
|
|
|
|
data: any[]
|
|
|
|
}
|
|
|
|
}[],
|
2023-06-06 10:07:59 +00:00
|
|
|
data: any[]
|
|
|
|
}
|
|
|
|
let calcArr = ref<calcType[]>()
|
|
|
|
let width = ref(1500)
|
|
|
|
let height = ref(700)
|
2023-06-08 07:58:40 +00:00
|
|
|
async function ajax() {
|
|
|
|
const res: any = await getCurrent24Trend(ids);
|
|
|
|
let data = []
|
|
|
|
if (res.code == 200) {
|
|
|
|
// data = res.data.map((item: any) => {
|
|
|
|
// if (unit) {
|
|
|
|
// item.name = item.name + '(' + unit + ')'
|
|
|
|
// }
|
|
|
|
// return {
|
|
|
|
// name: item.name,
|
|
|
|
// type: item.type,
|
|
|
|
// max: item.max,
|
|
|
|
// min: item.min,
|
|
|
|
// avg: item.avg,
|
|
|
|
// data: item.date.map((key, value) => [key, item.value[value]])
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
|
|
|
|
let tempData = {}
|
|
|
|
res.data.forEach((item: any) => {
|
2023-06-08 08:12:49 +00:00
|
|
|
if (unit) {
|
|
|
|
item.name = item.name + '(' + unit + ')'
|
|
|
|
}
|
2023-06-08 07:58:40 +00:00
|
|
|
if (tempData.hasOwnProperty(item.id)) {
|
2023-07-21 09:30:42 +00:00
|
|
|
let seriesData:any = {
|
2023-06-08 07:58:40 +00:00
|
|
|
name: item.type,
|
|
|
|
type: 'line',
|
|
|
|
showSymbol: false,
|
|
|
|
data: item.date.map((key, value) => [key, item.value[value]]),
|
|
|
|
smooth: true,
|
2023-07-21 09:30:42 +00:00
|
|
|
}
|
|
|
|
if (limit&&limit!=='{}') {
|
|
|
|
let arrLimit:object = JSON.parse(limit)
|
|
|
|
let markLineData = []
|
|
|
|
for(let i in arrLimit) {
|
|
|
|
markLineData.push({
|
|
|
|
name: i,
|
|
|
|
yAxis: arrLimit[i],
|
|
|
|
label: {
|
|
|
|
formatter: `${i}上限值:` + arrLimit[i] + unit,
|
|
|
|
position: "middle",
|
|
|
|
},
|
|
|
|
lineStyle: {
|
|
|
|
color: "red", // 这儿设置安全基线颜色
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
seriesData.markLine = {
|
|
|
|
// 设置最大值和最小值
|
|
|
|
silent: true, //基线显示 隐藏
|
|
|
|
symbol: "none", // 不显示箭头和圆点
|
|
|
|
data: markLineData
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tempData[item.id].data.push(seriesData)
|
2023-06-08 07:58:40 +00:00
|
|
|
tempData[item.id].math.push({
|
|
|
|
key: item.type,
|
|
|
|
value: {
|
|
|
|
max: item.max,
|
|
|
|
min: item.min,
|
|
|
|
avg: item.avg
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
tempData[item.id] = {
|
|
|
|
name: item.name,
|
|
|
|
data: [{
|
|
|
|
name: item.type,
|
|
|
|
type: 'line',
|
|
|
|
showSymbol: false,
|
|
|
|
data: item.date.map((key, value) => [key, item.value[value]]),
|
|
|
|
smooth: true,
|
|
|
|
}],
|
|
|
|
math: [{
|
|
|
|
key: item.type,
|
|
|
|
value: {
|
|
|
|
max: item.max,
|
|
|
|
min: item.min,
|
|
|
|
avg: item.avg
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
}
|
2023-06-06 10:07:59 +00:00
|
|
|
}
|
2023-06-08 07:58:40 +00:00
|
|
|
})
|
|
|
|
data = Object.values(tempData)
|
2023-06-06 10:07:59 +00:00
|
|
|
calcArr.value = data
|
2023-06-08 07:58:40 +00:00
|
|
|
if (data.length <= 4) {
|
|
|
|
width.value = 1900 / data.length - (data.length - 1) * 20;
|
|
|
|
} else if (data.length > 4 && data.length <= 8) {
|
|
|
|
width.value = width.value / 4 - 3 * 20;
|
|
|
|
height.value = 950 / 2 - 40;
|
2023-06-06 10:07:59 +00:00
|
|
|
} else {
|
2023-06-08 07:58:40 +00:00
|
|
|
width.value = width.value / 4 - 3 * 20;
|
|
|
|
height.value = 950 / 3 - 60;
|
2023-06-06 10:07:59 +00:00
|
|
|
}
|
2023-06-08 07:58:40 +00:00
|
|
|
}
|
2023-06-06 10:07:59 +00:00
|
|
|
}
|
|
|
|
onMounted(() => {
|
|
|
|
ajax()
|
2023-06-08 07:58:40 +00:00
|
|
|
timer = setInterval(() => {
|
|
|
|
ajax()
|
|
|
|
}, 1000 * 60 * 10)
|
|
|
|
})
|
|
|
|
onUnmounted(() => {
|
|
|
|
clearInterval(timer)
|
2023-06-06 10:07:59 +00:00
|
|
|
})
|
|
|
|
</script>
|
|
|
|
<style module>
|
|
|
|
.container {
|
|
|
|
height: 1080px;
|
|
|
|
width: 1920px;
|
|
|
|
color: #20aec5;
|
|
|
|
background-color: #100c2a;
|
|
|
|
box-sizing: border-box;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<style scoped>
|
|
|
|
.content {
|
|
|
|
height: 980px;
|
|
|
|
width: 1920px;
|
|
|
|
display: flex;
|
|
|
|
justify-content: space-around;
|
|
|
|
align-items: center;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
box-sizing: border-box;
|
|
|
|
padding: 5px;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|