feat(iot):优化 alert 的代码实现(继续)

pull/345/head
YunaiV 2026-05-18 20:35:07 +08:00
parent fbc03a9713
commit e9e534018f
4 changed files with 5 additions and 70 deletions

View File

@ -1,7 +1,7 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { DICT_TYPE } from '@vben/constants';
import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { getSimpleRuleSceneList } from '#/api/iot/rule/scene';
@ -9,7 +9,6 @@ import { getSimpleUserList } from '#/api/system/user';
import { getRangePickerDefaultProps } from '#/utils';
/** 新增/修改告警配置的表单 */
// TODO @AI两行=》1 行;
export function useFormSchema(): VbenFormSchema[] {
return [
{
@ -29,7 +28,6 @@ export function useFormSchema(): VbenFormSchema[] {
},
rules: 'required',
},
// TODO @AIvue + ep 貌似也要改成 teatarea
{
fieldName: 'description',
label: '配置描述',
@ -58,11 +56,9 @@ export function useFormSchema(): VbenFormSchema[] {
buttonStyle: 'solid',
optionType: 'button',
},
// TODO @AIdefaultValue 这种要枚举值哇?
defaultValue: 0,
defaultValue: CommonStatusEnum.ENABLE,
rules: 'required',
},
// TODO @AI可能 label 比较宽,需要拉长点。
{
fieldName: 'sceneRuleIds',
label: '关联场景联动规则',

View File

@ -12,7 +12,7 @@ import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { deleteAlertConfig, getAlertConfigPage } from '#/api/iot/alert/config';
import { $t } from '#/locales';
import AlertConfigForm from '../modules/form.vue';
import AlertConfigForm from './modules/form.vue';
import { useGridColumns, useGridFormSchema } from './data';
defineOptions({ name: 'IoTAlertConfig' });
@ -102,8 +102,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
]"
/>
</template>
<!-- TODO DONE @AI告警级别已改用 CellDict data.ts 渲染 -->
<!-- TODO DONE @AI关联场景联动规则计数已改用 formatter data.ts 渲染 -->
<!-- TODO DONE @AI接收类型是 number[] TagCellDict 只能渲染单值保留 slot -->
<template #receiveTypes="{ row }">
<Tag

View File

@ -1,5 +1,4 @@
<script setup lang="ts">
// TODO @AIconfig/modules
import type { AlertConfigApi } from '#/api/iot/alert/config';
import { computed, ref } from 'vue';
@ -16,7 +15,7 @@ import {
} from '#/api/iot/alert/config';
import { $t } from '#/locales';
import { useFormSchema } from '../config/data';
import { useFormSchema } from '../data';
defineOptions({ name: 'IoTAlertConfigForm' });
@ -33,6 +32,7 @@ const [Form, formApi] = useVbenForm({
componentProps: {
class: 'w-full',
},
labelWidth: 140,
},
wrapperClass: 'grid-cols-2',
layout: 'horizontal',

View File

@ -5,8 +5,6 @@ import type { AlertRecordApi } from '#/api/iot/alert/record';
import { h, ref } from 'vue';
import { Page } from '@vben/common-ui';
import { DICT_TYPE } from '@vben/constants';
import { getDictLabel } from '@vben/hooks';
import { IconifyIcon } from '@vben/icons';
import { Button, Input, message, Modal, Popover } from 'ant-design-vue';
@ -58,53 +56,6 @@ function handleProcess(row: AlertRecordApi.AlertRecord) {
});
}
/** 查看告警记录详情 */
// TODO @AI view vue3 + ep
function handleView(row: AlertRecordApi.AlertRecord) {
const deviceMessageText =
row.deviceMessage && typeof row.deviceMessage === 'object'
? JSON.stringify(row.deviceMessage, null, 2)
: row.deviceMessage || '-';
Modal.info({
title: '告警记录详情',
width: 600,
content: h('div', { class: 'space-y-2' }, [
h('div', [
h('span', { class: 'font-semibold' }, '告警名称:'),
h('span', row.configName || '-'),
]),
h('div', [
h('span', { class: 'font-semibold' }, '告警级别:'),
h(
'span',
getDictLabel(DICT_TYPE.IOT_ALERT_LEVEL, row.configLevel) || '-',
),
]),
h('div', [
h('span', { class: 'font-semibold' }, '设备消息:'),
h(
'pre',
{ class: 'mt-1 text-xs bg-gray-50 p-2 rounded' },
deviceMessageText,
),
]),
h('div', [
h('span', { class: 'font-semibold' }, '处理结果:'),
h('span', row.processRemark || '-'),
]),
h('div', [
h('span', { class: 'font-semibold' }, '处理时间:'),
h(
'span',
row.processTime
? new Date(row.processTime).toLocaleString('zh-CN')
: '-',
),
]),
]),
});
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
@ -149,8 +100,6 @@ function stringifyDeviceMessage(deviceMessage: any) {
<template>
<Page auto-content-height>
<Grid table-title="">
<!-- TODO DONE @AI告警级别已改用 CellDict data.ts 渲染 -->
<!-- TODO DONE @AI设备消息是 Popover hover JSON 详情CellDict 只渲染单值文本保留 slot -->
<template #deviceMessage="{ row }">
<Popover
v-if="row.deviceMessage"
@ -180,14 +129,6 @@ function stringifyDeviceMessage(deviceMessage: any) {
onClick: handleProcess.bind(null, row),
ifShow: !row.processStatus,
},
{
label: '查看',
type: 'link',
icon: ACTION_ICON.VIEW,
auth: ['iot:alert-record:query'],
onClick: handleView.bind(null, row),
ifShow: row.processStatus,
},
]"
/>
</template>