<!-- Description: 报警统计-各类报警统计 Author: 李亚光 Date: 2023-07-08 --> <script lang="ts" setup name="AlarmCount"> import layout from './layout.vue' import { getAlarmType, getAlarmTypeList } from '@/api/home/alarm/count' import { shortcuts } from '@/utils/common' const listQuery = ref({ timeType: '1', ledgerType: '', deptid: '', begTime: '', endTime: '', }) const selectTimeType = (type: string) => { listQuery.value.timeType = type } // 类别 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) // 开始结束时间 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]}` } } }) // setTimeout(() => { // xAxisData.value = [ // '闸井浓度超限', '场站浓度超限', '场站火焰报警', '疑似第三方破坏', '场站烟雾报警', // ] // data.value = [ // { // name: '报警数量', // data: [1, 3, 5, 1, 4], // }, // ] // list.value = xAxisData.value.map((item, index) => ({ // alarmType: item, // value: data.value[0].data[index], // })) // }, 1000) const resizePage = () => { setTimeout(() => { const resize = new Event('resize') window.dispatchEvent(resize) }, 500) } const fetchData = () => { loading.value = true getAlarmType(listQuery.value).then((res) => { // console.log(res.data, '各类报警统计') xAxisData.value = res.data.map((item: any) => item.name) data.value = [ { name: '报警数量', data: res.data.map((item: any) => item.value), }, ] list.value = res.data resizePage loading.value = false }).catch(() => { loading.value = false }) } onMounted(() => { fetchData() }) </script> <template> <layout title="各类报警统计"> <!-- 查询条件 --> <template #search> <div class="search"> <el-button :class="listQuery.timeType === '1' ? 'active' : ''" round size="small" style="margin: 0 5px;" @click="selectTimeType('1')" > 今日 </el-button> <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" :shortcuts="shortcuts" style="width: 380px;margin: 0 5px;" value-format="YYYY-MM-DD HH:mm:ss" range-separator="至" start-placeholder="报警开始时间" end-placeholder="报警结束时间" clearable /> <el-button type="primary" style="margin: 0 5px;" @click="fetchData"> 搜索 </el-button> </div> </template> <template #content> <div v-loading="loading" class="alarm-count"> <div class="bar"> <bar-chart-vertical v-show="xAxisData.length" :x-axis-data="xAxisData" :bar-coner="0" :data="data" :show-label="false" :colors="[]" :bar-width="15" :legend="{ itemWidth: 8, itemHeight: 8, type: 'scroll', orient: 'horizontal', icon: 'roundRect', right: '40', top: '10' }" :grid="{ top: 50, left: 40, right: 40, bottom: 20, containLabel: true, // 是否包含坐标轴的刻度标签 }" /> <el-empty v-show="!xAxisData.length" description="暂无数据" /> </div> <div class="table"> <el-table border :data="list" stripe style="width: 100%;" :height="440"> <el-table-column label="报警类型" prop="name" align="center" /> <el-table-column label="报警数量" prop="value" align="center" /> </el-table> </div> </div> </template> </layout> </template> <style lang="scss" scoped> .active { color: #0d76d4; 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>