This commit is contained in:
xingyu4j
2025-10-10 21:44:08 +08:00
parent 00a25ed1d3
commit 691f9aa764
24 changed files with 689 additions and 732 deletions

View File

@@ -4,7 +4,7 @@ import type { AlertConfigApi } from '#/api/iot/alert/config';
import { Page, useVbenModal } from '@vben/common-ui';
import { message } from 'ant-design-vue';
import { message, Tag } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { deleteAlertConfig, getAlertConfigPage } from '#/api/iot/alert/config';
@@ -26,7 +26,7 @@ function onRefresh() {
}
// 获取告警级别文本
const getLevelText = (level?: number) => {
function getLevelText(level?: number) {
const levelMap: Record<number, string> = {
1: '提示',
2: '一般',
@@ -35,10 +35,10 @@ const getLevelText = (level?: number) => {
5: '紧急',
};
return level ? levelMap[level] || `级别${level}` : '-';
};
}
// 获取告警级别颜色
const getLevelColor = (level?: number) => {
function getLevelColor(level?: number) {
const colorMap: Record<number, string> = {
1: 'blue',
2: 'green',
@@ -47,10 +47,10 @@ const getLevelColor = (level?: number) => {
5: 'purple',
};
return level ? colorMap[level] || 'default' : 'default';
};
}
// 获取接收类型文本
const getReceiveTypeText = (type?: number) => {
function getReceiveTypeText(type?: number) {
const typeMap: Record<number, string> = {
1: '站内信',
2: '邮箱',
@@ -59,7 +59,7 @@ const getReceiveTypeText = (type?: number) => {
5: '钉钉',
};
return type ? typeMap[type] || `类型${type}` : '-';
};
}
/** 创建告警配置 */
function handleCreate() {
@@ -138,9 +138,9 @@ const [Grid, gridApi] = useVbenVxeGrid({
<!-- 告警级别列 -->
<template #level="{ row }">
<a-tag :color="getLevelColor(row.level)">
<Tag :color="getLevelColor(row.level)">
{{ getLevelText(row.level) }}
</a-tag>
</Tag>
</template>
<!-- 关联场景联动规则列 -->
@@ -150,13 +150,13 @@ const [Grid, gridApi] = useVbenVxeGrid({
<!-- 接收类型列 -->
<template #receiveTypes="{ row }">
<a-tag
<Tag
v-for="(type, index) in row.receiveTypes"
:key="index"
class="mr-1"
>
{{ getReceiveTypeText(type) }}
</a-tag>
</Tag>
</template>
<!-- 操作列 -->

View File

@@ -5,8 +5,9 @@ import type { AlertRecord } from '#/api/iot/alert/record';
import { h, onMounted, ref } from 'vue';
import { Page } from '@vben/common-ui';
import { IconifyIcon } from '@vben/icons';
import { message, Modal } from 'ant-design-vue';
import { Button, message, Modal, Popover, Tag } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { getAlertRecordPage, processAlertRecord } from '#/api/iot/alert/record';
@@ -26,13 +27,13 @@ function onRefresh() {
}
// 加载产品和设备列表
const loadData = async () => {
async function loadData() {
productList.value = await getSimpleProductList();
deviceList.value = await getSimpleDeviceList();
};
}
// 获取告警级别文本
const getLevelText = (level?: number) => {
function getLevelText(level?: number) {
const levelMap: Record<number, string> = {
1: '提示',
2: '一般',
@@ -41,10 +42,10 @@ const getLevelText = (level?: number) => {
5: '紧急',
};
return level ? levelMap[level] || `级别${level}` : '-';
};
}
// 获取告警级别颜色
const getLevelColor = (level?: number) => {
function getLevelColor(level?: number) {
const colorMap: Record<number, string> = {
1: 'blue',
2: 'green',
@@ -53,24 +54,24 @@ const getLevelColor = (level?: number) => {
5: 'purple',
};
return level ? colorMap[level] || 'default' : 'default';
};
}
// 获取产品名称
const getProductName = (productId?: number) => {
function getProductName(productId?: number) {
if (!productId) return '-';
const product = productList.value.find((p: any) => p.id === productId);
return product?.name || '加载中...';
};
}
// 获取设备名称
const getDeviceName = (deviceId?: number) => {
function getDeviceName(deviceId?: number) {
if (!deviceId) return '-';
const device = deviceList.value.find((d: any) => d.id === deviceId);
return device?.deviceName || '加载中...';
};
}
// 处理告警记录
const handleProcess = async (row: AlertRecord) => {
async function handleProcess(row: AlertRecord) {
Modal.confirm({
title: '处理告警记录',
content: h('div', [
@@ -90,7 +91,7 @@ const handleProcess = async (row: AlertRecord) => {
if (!processRemark) {
message.warning('请输入处理原因');
throw undefined;
throw new Error('请输入处理原因');
}
const hideLoading = message.loading({
@@ -103,16 +104,16 @@ const handleProcess = async (row: AlertRecord) => {
onRefresh();
} catch (error) {
console.error('处理失败:', error);
return Promise.reject();
throw error;
} finally {
hideLoading();
}
},
});
};
}
// 查看告警记录详情
const handleView = (row: AlertRecord) => {
function handleView(row: AlertRecord) {
Modal.info({
title: '告警记录详情',
width: 600,
@@ -148,7 +149,7 @@ const handleView = (row: AlertRecord) => {
]),
]),
});
};
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
@@ -190,9 +191,9 @@ onMounted(() => {
<Grid table-title="告警记录列表">
<!-- 告警级别列 -->
<template #configLevel="{ row }">
<a-tag :color="getLevelColor(row.configLevel)">
<Tag :color="getLevelColor(row.configLevel)">
{{ getLevelText(row.configLevel) }}
</a-tag>
</Tag>
</template>
<!-- 产品名称列 -->
@@ -207,7 +208,7 @@ onMounted(() => {
<!-- 设备消息列 -->
<template #deviceMessage="{ row }">
<a-popover
<Popover
v-if="row.deviceMessage"
placement="topLeft"
trigger="hover"
@@ -216,11 +217,11 @@ onMounted(() => {
<template #content>
<pre class="text-xs">{{ row.deviceMessage }}</pre>
</template>
<VbenButton size="small" type="link">
<Icon icon="ant-design:eye-outlined" class="mr-1" />
<Button size="small" type="link">
<IconifyIcon icon="ant-design:eye-outlined" class="mr-1" />
查看消息
</VbenButton>
</a-popover>
</Button>
</Popover>
<span v-else class="text-gray-400">-</span>
</template>