screenFront/src/views/TrendChart/index.vue

150 lines
3.7 KiB
Vue
Raw Normal View History

<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>
</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">
</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
let timer = null
type calcType = {
name: string,
2023-06-08 07:58:40 +00:00
math: {
key: string,
value: {
max: number,
min: number,
avg: number,
data: any[]
}
}[],
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)) {
tempData[item.id].data.push({
name: item.type,
type: 'line',
showSymbol: false,
data: item.date.map((key, value) => [key, item.value[value]]),
smooth: true,
})
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-08 07:58:40 +00:00
})
data = Object.values(tempData)
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;
} else {
2023-06-08 07:58:40 +00:00
width.value = width.value / 4 - 3 * 20;
height.value = 950 / 3 - 60;
}
2023-06-08 07:58:40 +00:00
}
}
onMounted(() => {
ajax()
2023-06-08 07:58:40 +00:00
timer = setInterval(() => {
ajax()
}, 1000 * 60 * 10)
})
onUnmounted(() => {
clearInterval(timer)
})
</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>