2026-08-05 bd36da9f3daa0c326b9c954f920c97b4a61d5fce
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
 
/** 状态选项:BI 模块 1=启用 0=禁用(与 common_status 字典值相反) */
const STATUS_OPTIONS = [
  { label: '启用', value: 1 },
  { label: '禁用', value: 0 },
];
 
/** 图表类型选项 */
const CHART_TYPE_OPTIONS = [
  { label: '柱状图 (bar)', value: 'bar' },
  { label: '折线图 (line)', value: 'line' },
  { label: '饼图 (pie)', value: 'pie' },
  { label: '散点图 (scatter)', value: 'scatter' },
  { label: '仪表盘 (gauge)', value: 'gauge' },
  { label: '表格 (table)', value: 'table' },
  { label: '数字卡 (number)', value: 'number' },
];
 
/** 新增/修改表单 */
export function useFormSchema(
  dashboardOptions: { label: string; value: number }[],
): VbenFormSchema[] {
  return [
    {
      component: 'Input',
      fieldName: 'id',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'dashboardId',
      label: '所属仪表盘',
      component: 'Select',
      componentProps: {
        options: dashboardOptions,
        placeholder: '请选择仪表盘',
      },
      rules: 'required',
    },
    {
      fieldName: 'name',
      label: '图表名称',
      component: 'Input',
      componentProps: {
        placeholder: '请输入图表名称',
      },
      rules: 'required',
    },
    {
      fieldName: 'chartType',
      label: '图表类型',
      component: 'Select',
      componentProps: {
        options: CHART_TYPE_OPTIONS,
        placeholder: '请选择图表类型',
      },
      defaultValue: 'bar',
      rules: 'required',
    },
    {
      fieldName: 'dataSourceId',
      label: '数据源ID',
      component: 'InputNumber',
      componentProps: {
        placeholder: '数据源配置ID',
      },
    },
    {
      fieldName: 'querySql',
      label: '查询SQL',
      component: 'Textarea',
      componentProps: {
        placeholder: 'SELECT ...',
        rows: 3,
      },
    },
    {
      fieldName: 'position',
      label: '布局位置',
      component: 'Input',
      componentProps: {
        placeholder: '{"x":0,"y":0,"w":12,"h":6}',
      },
    },
    {
      fieldName: 'chartOptions',
      label: '图表配置',
      component: 'Textarea',
      componentProps: {
        placeholder: 'JSON 配置(可选)',
        rows: 3,
      },
    },
    {
      fieldName: 'refreshInterval',
      label: '刷新间隔(秒)',
      component: 'InputNumber',
      componentProps: {
        placeholder: '0 表示不自动刷新',
        min: 0,
      },
      defaultValue: 0,
    },
    {
      fieldName: 'sort',
      label: '排序',
      component: 'InputNumber',
      componentProps: {
        min: 0,
      },
      defaultValue: 0,
    },
    {
      fieldName: 'status',
      label: '状态',
      component: 'RadioGroup',
      componentProps: {
        options: STATUS_OPTIONS,
        buttonStyle: 'solid',
        optionType: 'button',
      },
      defaultValue: 1,
      rules: 'required',
    },
  ];
}
 
/** 列表搜索表单 */
export function useGridFormSchema(
  dashboardOptions: { label: string; value: number }[],
): VbenFormSchema[] {
  return [
    {
      fieldName: 'dashboardId',
      label: '所属仪表盘',
      component: 'Select',
      componentProps: {
        options: dashboardOptions,
        placeholder: '请选择仪表盘',
        allowClear: true,
      },
    },
    {
      fieldName: 'name',
      label: '图表名称',
      component: 'Input',
      componentProps: {
        placeholder: '请输入图表名称',
        allowClear: true,
      },
    },
  ];
}
 
/** 列表字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    { type: 'checkbox', width: 40 },
    {
      field: 'id',
      title: '编号',
      width: 80,
    },
    {
      field: 'name',
      title: '图表名称',
      minWidth: 150,
    },
    {
      field: 'chartType',
      title: '图表类型',
      width: 120,
      cellRender: {
        name: 'CellSelect',
        props: {
          options: CHART_TYPE_OPTIONS,
        },
      },
    },
    {
      field: 'refreshInterval',
      title: '刷新间隔(s)',
      width: 100,
    },
    {
      field: 'sort',
      title: '排序',
      width: 70,
    },
    {
      field: 'status',
      title: '状态',
      width: 80,
      slots: { default: 'status' },
    },
    {
      field: 'createTime',
      title: '创建时间',
      width: 170,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 160,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}