<!-- Description: 报警统计-报警趋势分析 Author: 李亚光 Date: 2023-07-09 --> <script lang="ts" setup name="TrendAnalysis"> import layout from './layout.vue' import { getAlarmTrend } from '@/api/home/alarm/count' import { shortcuts } from '@/utils/common' const listQuery = ref({ timeType: '2', ledgerType: '', endTime: '', begTime: '', deptid: '', }) // 开始结束时间 const datetimerange = ref() watch(() => datetimerange.value, (newVal) => { listQuery.value.begTime = '' listQuery.value.endTime = '' if (Array.isArray(newVal)) { if (newVal.length) { listQuery.value.begTime = `${newVal[0]}` listQuery.value.endTime = `${newVal[1]}` } } }) const selectTimeType = (type: string) => { listQuery.value.timeType = type } const columns = ref<any[]>([ { text: '闸井浓度超限', value: 'well', }, { text: '场站浓度超限', value: 'station', }, { text: '管线浓度超限', value: 'pipeline', }, ]) // 类别 const ledgerTypeList = ref<{ id: string; name: string; value: string }[]>([ { name: '闸井', id: '1', value: '1', }, { name: '场站', id: '2', value: '2', }, { name: '管线', id: '3', value: '3', }, ]) const xAxisData = ref<string[]>([]) const data = ref<any[]>([]) const list = ref([]) const loading = ref(true) // setTimeout(() => { // xAxisData.value = [ // '2024-07-01 12:11:12', // '2024-07-02 12:11:12', // '2024-07-03 12:11:12', // '2024-07-04 12:11:12', // '2024-07-05 12:11:12', // '2024-07-06 12:11:12', // '2024-07-07 12:11:12', // ] // data.value = [ // { // name: '闸井浓度超限', // data: [1, 3, 5, 1, 4, 2, 7], // symbol: 'emptyCircle', // }, // { // name: '场站浓度超限', // data: [2, 1, 4, 1, 5, 2, 9], // symbol: 'emptyCircle', // }, // { // name: '闸井浓度超限', // data: [4, 3, 2, 4, 7, 9, 1], // symbol: 'emptyCircle', // }, // ] // list.value = xAxisData.value.map((item, index) => ({ // alarmTime: item, // wellOver: data.value[0].data[index], // senceOver: data.value[1].data[index], // thirdParty: data.value[2].data[index], // })) // }, 1000) const resizePage = () => { setTimeout(() => { const resize = new Event('resize') window.dispatchEvent(resize) }, 500) } const fetchData = () => { loading.value = true const columnsDict = { 闸井浓度超限: 'well', 场站浓度超限: 'station', 管线浓度超限: 'pipeline', } as { [key: string]: string } getAlarmTrend(listQuery.value).then((res) => { console.log(res.data, '报警趋势分析') xAxisData.value = res.data.map((item: any) => item.date) if (!listQuery.value.ledgerType) { data.value = [ { name: '闸井浓度超限', data: res.data.map((item: any) => item['闸井浓度超限']), }, { name: '场站浓度超限', data: res.data.map((item: any) => item['场站浓度超限']), }, { name: '管线浓度超限', data: res.data.map((item: any) => item['管线浓度超限']), }, ] } else if (listQuery.value.ledgerType === '1') { data.value = [ { name: '闸井浓度超限', data: res.data.map((item: any) => item['闸井浓度超限']), }, ] } else if (listQuery.value.ledgerType === '2') { data.value = [ { name: '场站浓度超限', data: res.data.map((item: any) => item['场站浓度超限']), }, ] } else if (listQuery.value.ledgerType === '3') { data.value = [ { name: '管线浓度超限', data: res.data.map((item: any) => item['管线浓度超限']), }, ] } list.value = res.data.map((item: any) => ({ date: item.date, well: item['闸井浓度超限'], station: item['场站浓度超限'], pipeline: item['管线浓度超限'], })) columns.value = data.value.map((item: any) => ({ text: item.name, value: columnsDict[item.name], })) resizePage() loading.value = false }).catch(() => { loading.value = false }) } onMounted(() => { fetchData() }) </script> <template> <layout title="报警趋势分析"> <!-- 查询条件 --> <template #search> <div class="search"> <el-button :class="listQuery.timeType === '2' ? 'active' : ''" round size="small" style="margin: 0 5px;" @click="selectTimeType('2')" > 本周 </el-button> <el-button :class="listQuery.timeType === '3' ? 'active' : ''" round size="small" style="margin: 0 5px;" @click="selectTimeType('3')" > 本月 </el-button> <el-select v-model="listQuery.ledgerType" placeholder="全部类别" clearable style="width: 180px;margin: 0 5px;"> <el-option v-for="item in ledgerTypeList" :key="item.id" :label="item.name" :value="item.id" /> </el-select> <dept-select v-model="listQuery.deptid" placeholder="管理单位" :clearable="true" style="width: 220px;margin: 0 5px;" /> <el-date-picker v-model="datetimerange" type="datetimerange" format="YYYY-MM-DD HH:mm:ss" style="width: 380px;margin: 0 5px;" value-format="YYYY-MM-DD HH:mm:ss" range-separator="至" start-placeholder="报警开始时间" end-placeholder="报警结束时间" clearable :shortcuts="shortcuts" /> <el-button type="primary" style="margin: 0 5px;" @click="fetchData"> 搜索 </el-button> </div> </template> <template #content> <div class="alarm-count"> <div class="bar"> <line-chart :x-axis-data="xAxisData" :data="data" :gradient="false" :legend="{ itemWidth: 8, itemHeight: 8, type: 'scroll', orient: 'horizontal', icon: 'roundRect', right: '0', top: '10' }" :grid="{ top: 50, left: 30, right: 30, bottom: 20, containLabel: true, // 是否包含坐标轴的刻度标签 }" /> </div> <div class="table"> <el-table border :data="list" stripe style="width: 100%;" :height="440"> <el-table-column label="日期" prop="date" align="center" width="190" /> <el-table-column v-for="item in columns" :key="item.text" :label="item.text" :prop="item.value" align="center" /> </el-table> </div> </div> </template> </layout> </template> <style lang="scss" scoped> .active { color: #3d7eff; border-color: #c5d8ff; outline: none; background-color: #ecf2ff; } .search { display: flex; align-items: center; } .alarm-count { display: flex; .bar { width: 60%; height: 450px; } .table { width: 38%; padding: 10px; margin-left: 20px; } } </style>