<!-- Description: 报警管理-历史报警 Author: 李亚光 Date: 2023-06-28 --> <script lang="ts" setup name="HistoryAlarm"> import { ElLoading, ElMessage } from 'element-plus' import dayjs from 'dayjs' import { getDictByCode } from '@/api/system/dict' import { exportHistoryAlarm, getHistoryAlarmListPage } from '@/api/home/alarm/history' import { getAlarmLevelListPage, getAlarmTypeListPage } from '@/api/home/rule/alarm' import { getDeviceTypeListPage } from '@/api/home/device/type' import { uniqueMultiArray } from '@/utils/Array' import { shortcuts } from '@/utils/common' import { exportFile } from '@/utils/exportUtils' const alarmCategoryList = ref<{ id: string; name: string; value: string }[]>([]) // 报警类别 const alarmTypeList = ref<{ id: string; name: string; value: string }[]>([]) // 报警类型 const alarmLevelList = ref<{ id: string; name: string; value: string }[]>([]) // 报警等级 const deviceTypeList = ref<{ id: string; name: string; value: string }[]>([]) // 设备类型 const realAlarmList = ref<{ id: string; name: string; value: string }[]>([ { name: '是', id: '0', value: '0', }, { name: '否', id: '1', value: '1', }, ]) // 报警状态 // 表格数据 const list = ref<any[]>([]) const total = ref(0) // 初始展示列 const columns = ref<any>([ { text: '报警类别', value: 'alarmCategory', align: 'center', width: '110' }, { text: '报警类型', value: 'alarmType', align: 'center', width: '140' }, { text: '报警原因', value: 'alarmMsg', align: 'center' }, { text: '报警等级', value: 'alarmLevelName', align: 'center', width: '90' }, { text: '位置', value: 'position', align: 'center' }, { text: '设备编号', value: 'devcode', align: 'center', width: '130' }, { text: '管理单位', value: 'deptName', align: 'center' }, { text: '是否误报', value: 'realAlarmName', align: 'center', width: '90' }, { text: '报警时间', value: 'alarmTime', align: 'center' }, { text: '解除时间', value: 'cancelTime', align: 'center' }, { text: '解除时长', value: 'cancelDuration', align: 'center' }, ]) // 最终展示列 const columnsConfig = ref([]) // 修改列 const editColumns = (data: any) => { columnsConfig.value = data } const loadingTable = ref(true) // 查询条件 const listQuery = ref({ limit: 20, offset: 1, alarmCategory: '', alarmLevel: '', alarmTypeId: '', begTime: '', deptId: '', devCode: '', devTypeId: '', endTime: '', ledgerNumber: '', manufactureId: '', position: '', processStatus: '', realAlarm: '', }) // 开始结束时间 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]} 00:00:00` listQuery.value.endTime = `${newVal[1]} 23:59:59` } } }) // 查询数据 const fetchData = () => { loadingTable.value = true getHistoryAlarmListPage(listQuery.value).then((res) => { console.log(res.data.rows, '查询数据') list.value = res.data.rows total.value = res.data.total loadingTable.value = false }).catch(() => { loadingTable.value = false }) } // 重置查询条件f const reset = () => { datetimerange.value = [] listQuery.value = { limit: 20, offset: 1, alarmCategory: '', alarmLevel: '', alarmTypeId: '', begTime: '', deptId: '', devCode: '', devTypeId: '', endTime: '', ledgerNumber: '', manufactureId: '', position: '', processStatus: '', realAlarm: '', } fetchData() } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 const changePage = (val: { size: number; page: number }) => { if (val && val.size) { listQuery.value.limit = val.size } if (val && val.page) { listQuery.value.offset = val.page } fetchData() } // 详情 const $router = useRouter() const moreData = (row: any) => { $router.push({ name: 'AlarmHistoryDetail', query: { id: row.id, row: JSON.stringify(row), type: 'history', }, }) } // 导出列表 const exportList = () => { if (!list.value.length) { ElMessage.warning('暂无导出数据') return } const loading = ElLoading.service({ lock: true, background: 'rgba(255, 255, 255, 0.8)', }) exportHistoryAlarm(listQuery.value).then((res) => { exportFile(res.data, '历史报警列表(数据).xlsx') loading.close() }).catch(() => { loading.close() }) } onMounted(() => { datetimerange.value = [dayjs().subtract(7, 'day').format('YYYY-MM-DD HH:mm:ss'), dayjs().format('YYYY-MM-DD HH:mm:ss')] setTimeout(() => { fetchData() }) }) // 字典 const fetchDict = () => { // 报警类别 getDictByCode('alarmCategory').then((res) => { alarmCategoryList.value = res.data }) // 报警类型 getAlarmTypeListPage({ offset: 1, limit: 99999 }).then((res) => { alarmTypeList.value = uniqueMultiArray(res.data.rows.map((item: any) => ({ name: item.alarmType, value: item.id, id: item.id, })), 'name') }) // 报警等级 getAlarmLevelListPage({ offset: 1, limit: 99999 }).then((res) => { alarmLevelList.value = res.data.rows.map((item: any) => ({ name: item.alarmLevel, value: item.id, id: item.id, })) }) // 设备类型 getDeviceTypeListPage({ offset: 1, limit: 99999 }).then((res) => { deviceTypeList.value = res.data.rows.map((item: any) => ({ name: item.typeName, value: item.id, id: item.id, })) }) } fetchDict() const { proxy } = getCurrentInstance() as any </script> <template> <!-- 布局 --> <app-container> <!-- 筛选条件 --> <search-area :need-clear="true" @search="fetchData" @clear="reset"> <search-item> <el-select v-model="listQuery.alarmCategory" placeholder="报警类别" clearable class="select" style="width: 192px;"> <el-option v-for="item in alarmCategoryList" :key="item.id" :value="item.value" :label="item.name" /> </el-select> </search-item> <search-item> <el-select v-model="listQuery.alarmTypeId" placeholder="报警类型" clearable class="select" style="width: 192px;"> <el-option v-for="item in alarmTypeList" :key="item.id" :value="item.value" :label="item.name" /> </el-select> </search-item> <search-item> <el-select v-model="listQuery.alarmLevel" placeholder="报警等级" clearable class="select" style="width: 192px;"> <el-option v-for="item in alarmLevelList" :key="item.id" :value="item.value" :label="item.name" /> </el-select> </search-item> <search-item> <el-select v-model="listQuery.devTypeId" placeholder="设备类型" clearable class="select" style="width: 192px;"> <el-option v-for="item in deviceTypeList" :key="item.id" :value="item.value" :label="item.name" /> </el-select> </search-item> <search-item> <el-select v-model="listQuery.realAlarm" placeholder="是否误报" clearable class="select" style="width: 192px;"> <el-option v-for="item in realAlarmList" :key="item.id" :value="item.value" :label="item.name" /> </el-select> </search-item> <search-item> <el-input v-model.trim="listQuery.position" placeholder="位置" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.devCode" placeholder="设备编号" clearable /> </search-item> <search-item> <dept-select v-model="listQuery.deptId" placeholder="管理单位" :clearable="true" class="select" style="width: 192px;" /> </search-item> <search-item> <el-date-picker v-model="datetimerange" type="datetimerange" format="YYYY-MM-DD HH:mm:ss" :shortcuts="shortcuts" value-format="YYYY-MM-DD HH:mm:ss" range-separator="至" start-placeholder="报警开始时间" end-placeholder="报警结束时间" clearable /> </search-item> </search-area> <!-- 表头标题 --> <table-container :is-config="true" config-title="history-alarm" :columns="columns" :config-columns="columnsConfig" :edit="editColumns" > <template #btns-right> <!-- 操作 --> <div> <el-button v-if="proxy.hasPerm('/alarm/history/export')" type="primary" @click="exportList"> 导出 </el-button> </div> </template> <!-- 查询结果Table显示 --> <normal-table :data="list" :total="total" :columns="columnsConfig" :query="listQuery" :list-loading="loadingTable" @change="changePage" > <template #preColumns> <!-- <el-table-column label="选择" width="55" align="center"> <template #default="scope"> <el-radio v-model="select" :label="scope.$index + 1" class="radio" /> </template> </el-table-column> --> <el-table-column label="序号" width="55" align="center"> <template #default="scope"> {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }} </template> </el-table-column> </template> <template #columns> <el-table-column v-if="proxy.hasPerm('/alarm/history/detail')" label="操作" align="center" width="80"> <template #default="scope"> <el-button type="primary" link size="small" @click="moreData(scope.row)"> 查看 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> </app-container> </template>