xiaoyi
6 天以前 a4025834e2304dc57f6e98d58feeb9416bd90609
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { DecisionAlertApi } from '#/api/bi/decision/alert';
 
import { Page, useVbenModal } from '@vben/common-ui';
 
import { message, Tag } from 'ant-design-vue';
 
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { deleteAlertRule, getAlertRulePage } from '#/api/bi/decision/alert';
 
import { severityColor, severityText, useGridColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue';
 
defineOptions({ name: 'DecisionAlertRule' });
 
const [FormModal, formModalApi] = useVbenModal({
  connectedComponent: Form,
  destroyOnClose: true,
});
 
const [Grid, gridApi] = useVbenVxeGrid({
  formOptions: {
    schema: useGridFormSchema(),
  },
  gridOptions: {
    columns: useGridColumns(),
    height: 'auto',
    proxyConfig: {
      ajax: {
        query: async ({ page, form }: any) => {
          const res = await getAlertRulePage({ ...page, ...form });
          return res;
        },
      },
    },
  } as VxeTableGridOptions<DecisionAlertApi.AlertRule>,
});
 
function handleRefresh() {
  gridApi.query();
}
 
function handleCreate() {
  formModalApi.setData(null).open();
}
 
function handleEdit(row: DecisionAlertApi.AlertRule) {
  formModalApi.setData(row).open();
}
 
async function handleDelete(row: DecisionAlertApi.AlertRule) {
  const hide = message.loading(`正在删除「${row.name}」...`, 0);
  try {
    await deleteAlertRule(row.id!);
    message.success('删除成功');
    handleRefresh();
  } finally {
    hide();
  }
}
</script>
 
<template>
  <Page :auto-content-height="true">
    <div class="mb-3 flex items-center justify-between">
      <span class="text-lg font-bold">预警规则配置</span>
      <a-button type="primary" @click="handleCreate">新增</a-button>
    </div>
    <Grid>
      <template #severitySlot="{ row }">
        <Tag :color="severityColor(row.severity)">{{ severityText(row.severity) }}</Tag>
      </template>
      <template #enabledSlot="{ row }">
        <Tag :color="row.enabled === 1 ? 'green' : 'default'">{{ row.enabled === 1 ? '启用' : '禁用' }}</Tag>
      </template>
      <template #actionSlot="{ row }">
        <TableAction
          :actions="[
            { label: '编辑', type: 'link', icon: ACTION_ICON.EDIT, onClick: handleEdit.bind(null, row) },
            { label: '删除', type: 'link', danger: true, icon: ACTION_ICON.DELETE, onClick: handleDelete.bind(null, row) },
          ]"
        />
      </template>
    </Grid>
    <FormModal />
  </Page>
</template>