xiaoyi
6 天以前 27c8277d717b34b55f3ea967027b53b067f77df3
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
 
export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    { field: 'code', title: 'KPI编码', width: 140 },
    { field: 'name', title: 'KPI名称', width: 150 },
    {
      field: 'category', title: '分类', width: 100,
      slots: { default: 'categorySlot' },
    },
    { field: 'unit', title: '单位', width: 70 },
    { field: 'chartType', title: '图表类型', width: 90 },
    {
      field: 'status', title: '状态', width: 70,
      slots: { default: 'statusSlot' },
    },
    { field: 'sort', title: '排序', width: 60 },
    {
      title: '操作', width: 160,
      slots: { default: 'actionSlot' },
      fixed: 'right',
    },
  ];
}
 
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'name',
      label: 'KPI名称',
      component: 'Input',
      componentProps: { placeholder: '请输入KPI名称' },
    },
    {
      fieldName: 'category',
      label: '分类',
      component: 'Select',
      componentProps: {
        options: [
          { label: '全部', value: '' },
          { label: '供电量', value: 'power_supply' },
          { label: '设备运行', value: 'device_operation' },
          { label: '生产', value: 'production' },
          { label: '质量', value: 'quality' },
          { label: '采购', value: 'procurement' },
          { label: '安全', value: 'safety' },
        ],
        allowClear: true,
      },
    },
    {
      fieldName: 'status',
      label: '状态',
      component: 'Select',
      componentProps: {
        options: [
          { label: '全部', value: '' },
          { label: '启用', value: 1 },
          { label: '禁用', value: 0 },
        ],
        allowClear: true,
      },
    },
  ];
}
 
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'code',
      label: 'KPI编码',
      component: 'Input',
      componentProps: { placeholder: '请输入KPI编码(唯一)' },
      rules: 'required',
    },
    {
      fieldName: 'name',
      label: 'KPI名称',
      component: 'Input',
      componentProps: { placeholder: '请输入KPI名称' },
      rules: 'required',
    },
    {
      fieldName: 'category',
      label: '分类',
      component: 'Select',
      componentProps: {
        options: [
          { label: '供电量', value: 'power_supply' },
          { label: '设备运行', value: 'device_operation' },
          { label: '生产', value: 'production' },
          { label: '质量', value: 'quality' },
          { label: '采购', value: 'procurement' },
          { label: '安全', value: 'safety' },
        ],
      },
      rules: 'required',
    },
    { fieldName: 'unit', label: '单位', component: 'Input', componentProps: { placeholder: '单位' } },
    {
      fieldName: 'chartType',
      label: '图表类型',
      component: 'Select',
      componentProps: {
        options: [
          { label: '数字卡片', value: 'number' },
          { label: '柱状图', value: 'bar' },
          { label: '折线图', value: 'line' },
          { label: '饼图', value: 'pie' },
        ],
      },
    },
    {
      fieldName: 'comparisonOperator',
      label: '比较运算符',
      component: 'Select',
      componentProps: {
        options: [
          { label: '大于 >', value: '>' },
          { label: '小于 <', value: '<' },
          { label: '大于等于 >=', value: '>=' },
          { label: '小于等于 <=', value: '<=' },
        ],
      },
    },
    { fieldName: 'thresholdWarn', label: '警告阈值', component: 'InputNumber', componentProps: { placeholder: '警告阈值', style: 'width:100%' } },
    { fieldName: 'thresholdCritical', label: '严重阈值', component: 'InputNumber', componentProps: { placeholder: '严重阈值', style: 'width:100%' } },
    { fieldName: 'refreshInterval', label: '刷新间隔(秒)', component: 'InputNumber', componentProps: { placeholder: '默认300', style: 'width:100%' } },
    { fieldName: 'sort', label: '排序', component: 'InputNumber', componentProps: { placeholder: '排序号', style: 'width:100%' } },
    {
      fieldName: 'status',
      label: '状态',
      component: 'Select',
      componentProps: {
        options: [
          { label: '启用', value: 1 },
          { label: '禁用', value: 0 },
        ],
      },
    },
    { fieldName: 'querySql', label: '查询SQL', component: 'InputTextArea', componentProps: { placeholder: 'SELECT SUM(...) FROM ...', rows: 3 } },
    { fieldName: 'remark', label: '备注', component: 'InputTextArea', componentProps: { placeholder: '备注', rows: 2 } },
  ];
}
 
export const CATEGORY_MAP: Record<string, string> = {
  power_supply: '供电量',
  device_operation: '设备运行',
  production: '生产',
  quality: '质量',
  procurement: '采购',
  safety: '安全',
};