feat(iot):优化 alert 的代码实现(继续)
parent
fbc03a9713
commit
e9e534018f
|
|
@ -1,7 +1,7 @@
|
||||||
import type { VbenFormSchema } from '#/adapter/form';
|
import type { VbenFormSchema } from '#/adapter/form';
|
||||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
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 { getDictOptions } from '@vben/hooks';
|
||||||
|
|
||||||
import { getSimpleRuleSceneList } from '#/api/iot/rule/scene';
|
import { getSimpleRuleSceneList } from '#/api/iot/rule/scene';
|
||||||
|
|
@ -9,7 +9,6 @@ import { getSimpleUserList } from '#/api/system/user';
|
||||||
import { getRangePickerDefaultProps } from '#/utils';
|
import { getRangePickerDefaultProps } from '#/utils';
|
||||||
|
|
||||||
/** 新增/修改告警配置的表单 */
|
/** 新增/修改告警配置的表单 */
|
||||||
// TODO @AI:两行=》1 行;
|
|
||||||
export function useFormSchema(): VbenFormSchema[] {
|
export function useFormSchema(): VbenFormSchema[] {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
|
@ -29,7 +28,6 @@ export function useFormSchema(): VbenFormSchema[] {
|
||||||
},
|
},
|
||||||
rules: 'required',
|
rules: 'required',
|
||||||
},
|
},
|
||||||
// TODO @AI:vue + ep 貌似也要改成 teatarea!
|
|
||||||
{
|
{
|
||||||
fieldName: 'description',
|
fieldName: 'description',
|
||||||
label: '配置描述',
|
label: '配置描述',
|
||||||
|
|
@ -58,11 +56,9 @@ export function useFormSchema(): VbenFormSchema[] {
|
||||||
buttonStyle: 'solid',
|
buttonStyle: 'solid',
|
||||||
optionType: 'button',
|
optionType: 'button',
|
||||||
},
|
},
|
||||||
// TODO @AI:defaultValue 这种要枚举值哇?
|
defaultValue: CommonStatusEnum.ENABLE,
|
||||||
defaultValue: 0,
|
|
||||||
rules: 'required',
|
rules: 'required',
|
||||||
},
|
},
|
||||||
// TODO @AI:可能 label 比较宽,需要拉长点。
|
|
||||||
{
|
{
|
||||||
fieldName: 'sceneRuleIds',
|
fieldName: 'sceneRuleIds',
|
||||||
label: '关联场景联动规则',
|
label: '关联场景联动规则',
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
import { deleteAlertConfig, getAlertConfigPage } from '#/api/iot/alert/config';
|
import { deleteAlertConfig, getAlertConfigPage } from '#/api/iot/alert/config';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
import AlertConfigForm from '../modules/form.vue';
|
import AlertConfigForm from './modules/form.vue';
|
||||||
import { useGridColumns, useGridFormSchema } from './data';
|
import { useGridColumns, useGridFormSchema } from './data';
|
||||||
|
|
||||||
defineOptions({ name: 'IoTAlertConfig' });
|
defineOptions({ name: 'IoTAlertConfig' });
|
||||||
|
|
@ -102,8 +102,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
]"
|
]"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<!-- TODO DONE @AI:告警级别已改用 CellDict 在 data.ts 渲染 -->
|
|
||||||
<!-- TODO DONE @AI:关联场景联动规则计数已改用 formatter 在 data.ts 渲染 -->
|
|
||||||
<!-- TODO DONE @AI:接收类型是 number[] 多 Tag,CellDict 只能渲染单值,保留 slot -->
|
<!-- TODO DONE @AI:接收类型是 number[] 多 Tag,CellDict 只能渲染单值,保留 slot -->
|
||||||
<template #receiveTypes="{ row }">
|
<template #receiveTypes="{ row }">
|
||||||
<Tag
|
<Tag
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
// TODO @AI:是不是应该拿到【config/modules】里?
|
|
||||||
import type { AlertConfigApi } from '#/api/iot/alert/config';
|
import type { AlertConfigApi } from '#/api/iot/alert/config';
|
||||||
|
|
||||||
import { computed, ref } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
|
|
@ -16,7 +15,7 @@ import {
|
||||||
} from '#/api/iot/alert/config';
|
} from '#/api/iot/alert/config';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
import { useFormSchema } from '../config/data';
|
import { useFormSchema } from '../data';
|
||||||
|
|
||||||
defineOptions({ name: 'IoTAlertConfigForm' });
|
defineOptions({ name: 'IoTAlertConfigForm' });
|
||||||
|
|
||||||
|
|
@ -33,6 +32,7 @@ const [Form, formApi] = useVbenForm({
|
||||||
componentProps: {
|
componentProps: {
|
||||||
class: 'w-full',
|
class: 'w-full',
|
||||||
},
|
},
|
||||||
|
labelWidth: 140,
|
||||||
},
|
},
|
||||||
wrapperClass: 'grid-cols-2',
|
wrapperClass: 'grid-cols-2',
|
||||||
layout: 'horizontal',
|
layout: 'horizontal',
|
||||||
|
|
@ -5,8 +5,6 @@ import type { AlertRecordApi } from '#/api/iot/alert/record';
|
||||||
import { h, ref } from 'vue';
|
import { h, ref } from 'vue';
|
||||||
|
|
||||||
import { Page } from '@vben/common-ui';
|
import { Page } from '@vben/common-ui';
|
||||||
import { DICT_TYPE } from '@vben/constants';
|
|
||||||
import { getDictLabel } from '@vben/hooks';
|
|
||||||
import { IconifyIcon } from '@vben/icons';
|
import { IconifyIcon } from '@vben/icons';
|
||||||
|
|
||||||
import { Button, Input, message, Modal, Popover } from 'ant-design-vue';
|
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({
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
formOptions: {
|
formOptions: {
|
||||||
schema: useGridFormSchema(),
|
schema: useGridFormSchema(),
|
||||||
|
|
@ -149,8 +100,6 @@ function stringifyDeviceMessage(deviceMessage: any) {
|
||||||
<template>
|
<template>
|
||||||
<Page auto-content-height>
|
<Page auto-content-height>
|
||||||
<Grid table-title="告警记录列表">
|
<Grid table-title="告警记录列表">
|
||||||
<!-- TODO DONE @AI:告警级别已改用 CellDict 在 data.ts 渲染 -->
|
|
||||||
<!-- TODO DONE @AI:设备消息是 Popover hover 看 JSON 详情,CellDict 只渲染单值文本,保留 slot -->
|
|
||||||
<template #deviceMessage="{ row }">
|
<template #deviceMessage="{ row }">
|
||||||
<Popover
|
<Popover
|
||||||
v-if="row.deviceMessage"
|
v-if="row.deviceMessage"
|
||||||
|
|
@ -180,14 +129,6 @@ function stringifyDeviceMessage(deviceMessage: any) {
|
||||||
onClick: handleProcess.bind(null, row),
|
onClick: handleProcess.bind(null, row),
|
||||||
ifShow: !row.processStatus,
|
ifShow: !row.processStatus,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
label: '查看',
|
|
||||||
type: 'link',
|
|
||||||
icon: ACTION_ICON.VIEW,
|
|
||||||
auth: ['iot:alert-record:query'],
|
|
||||||
onClick: handleView.bind(null, row),
|
|
||||||
ifShow: row.processStatus,
|
|
||||||
},
|
|
||||||
]"
|
]"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue