xiaoyi
5 天以前 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
 
export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    { field: 'id', title: 'ID', width: 60 },
    { field: 'name', title: '规则名称', width: 150 },
    {
      field: 'severity', title: '严重级别', width: 90,
      slots: { default: 'severitySlot' },
    },
    { field: 'comparisonOperator', title: '运算符', width: 70 },
    { field: 'thresholdValue', title: '阈值', width: 100 },
    {
      field: 'enabled', title: '启用', width: 70,
      slots: { default: 'enabledSlot' },
    },
    {
      title: '操作', width: 160,
      slots: { default: 'actionSlot' },
      fixed: 'right',
    },
  ];
}
 
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'enabled',
      label: '状态',
      component: 'Select',
      componentProps: {
        options: [
          { label: '全部', value: '' },
          { label: '启用', value: 1 },
          { label: '禁用', value: 0 },
        ],
        allowClear: true,
      },
    },
  ];
}
 
export function useFormSchema(kpiOptions: { label: string; value: number }[]): VbenFormSchema[] {
  return [
    {
      fieldName: 'kpiId',
      label: '关联KPI',
      component: 'Select',
      componentProps: { options: kpiOptions },
      rules: 'required',
    },
    {
      fieldName: 'name',
      label: '规则名称',
      component: 'Input',
      componentProps: { placeholder: '请输入规则名称' },
      rules: 'required',
    },
    {
      fieldName: 'severity',
      label: '严重级别',
      component: 'Select',
      componentProps: {
        options: [
          { label: '警告', value: 1 },
          { label: '严重', value: 2 },
          { label: '紧急', value: 3 },
        ],
      },
      rules: 'required',
    },
    {
      fieldName: 'comparisonOperator',
      label: '比较运算符',
      component: 'Select',
      componentProps: {
        options: [
          { label: '大于 >', value: '>' },
          { label: '小于 <', value: '<' },
          { label: '大于等于 >=', value: '>=' },
          { label: '小于等于 <=', value: '<=' },
        ],
      },
      rules: 'required',
    },
    {
      fieldName: 'thresholdValue', label: '阈值', component: 'InputNumber',
      componentProps: { placeholder: '阈值', style: 'width:100%' },
      rules: 'required',
    },
    {
      fieldName: 'enabled',
      label: '启用',
      component: 'Switch',
      componentProps: { checkedValue: 1, unCheckedValue: 0 },
    },
    {
      fieldName: 'notificationType', label: '通知方式', component: 'Input',
      componentProps: { placeholder: 'system/message/email' },
    },
    {
      fieldName: 'remark', label: '备注', component: 'InputTextArea',
      componentProps: { placeholder: '备注', rows: 2 },
    },
  ];
}
 
export function severityColor(severity: number): string {
  if (severity === 3) return 'red';
  if (severity === 2) return 'orange';
  return 'blue';
}
 
export function severityText(severity: number): string {
  if (severity === 3) return '紧急';
  if (severity === 2) return '严重';
  return '警告';
}