gen-data.tsx
7.18 KB
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
import type { Recordable } from '@vben/types';
import type { VxeGridProps } from '#/adapter/vxe-table';
import { getPopupContainer } from '@vben/utils';
import { Checkbox, Input, Select } from 'ant-design-vue';
const JavaTypes: string[] = [
'Long',
'String',
'Integer',
'Double',
'BigDecimal',
'Date',
'Boolean',
'LocalDate',
'LocalDateTime',
];
const queryTypeOptions = [
{ label: '=', value: 'EQ' },
{ label: '!=', value: 'NE' },
{ label: '>', value: 'GT' },
{ label: '>=', value: 'GE' },
{ label: '<', value: 'LT' },
{ label: '<=', value: 'LE' },
{ label: 'LIKE', value: 'LIKE' },
{ label: 'BETWEEN', value: 'BETWEEN' },
];
const componentsOptions = [
{ label: '文本框', value: 'input' },
{ label: '文本域', value: 'textarea' },
{ label: '下拉框', value: 'select' },
{ label: '单选框', value: 'radio' },
{ label: '复选框', value: 'checkbox' },
{ label: '日期控件', value: 'datetime' },
{ label: '图片上传', value: 'imageUpload' },
{ label: '文件上传', value: 'fileUpload' },
{ label: '富文本', value: 'editor' },
];
function renderBooleanTag(row: Recordable<any>, field: string) {
const value = row[field] ? '是' : '否';
const className = row[field] ? 'text-green-500' : 'text-red-500';
return <span class={className}>{value}</span>;
}
function renderBooleanCheckbox(row: Recordable<any>, field: string) {
return <Checkbox v-model:checked={row[field]}></Checkbox>;
}
export const validRules: VxeGridProps['editRules'] = {
columnComment: [{ required: true, message: '请输入' }],
javaField: [{ required: true, message: '请输入' }],
};
// 内部依赖的字典从外部通过函数传入
export const vxeTableColumns: (
dictOptions: { label: string; value: string }[],
) => VxeGridProps['columns'] = (dictOptions) => [
{
title: '序号',
type: 'seq',
fixed: 'left',
width: '50',
align: 'center',
},
{
title: '字段列名',
field: 'columnName',
showOverflow: 'tooltip',
fixed: 'left',
minWidth: 150,
},
{
title: '字段描述',
field: 'columnComment',
minWidth: 150,
slots: {
edit: ({ row }) => {
return <Input v-model:value={row.columnComment}></Input>;
},
},
editRender: {},
},
{
title: 'db类型',
field: 'columnType',
minWidth: 120,
showOverflow: 'tooltip',
},
{
title: 'Java类型',
field: 'javaType',
minWidth: 150,
slots: {
edit: ({ row }) => {
const javaTypeOptions = JavaTypes.map((type) => ({
label: type,
value: type,
}));
return (
<Select
class="w-full"
getPopupContainer={getPopupContainer}
options={javaTypeOptions}
v-model:value={row.javaType}
></Select>
);
},
},
editRender: {},
},
{
title: 'Java属性名',
field: 'javaField',
minWidth: 150,
showOverflow: 'tooltip',
slots: {
edit: ({ row }) => {
return <Input v-model:value={row.javaField}></Input>;
},
},
editRender: {},
},
{
title: '插入',
field: 'insert',
minWidth: 80,
showOverflow: 'tooltip',
align: 'center',
slots: {
default: ({ row }) => {
return renderBooleanTag(row, 'insert');
},
edit: ({ row }) => {
return renderBooleanCheckbox(row, 'insert');
},
},
editRender: {},
},
{
title: '编辑',
field: 'edit',
showOverflow: 'tooltip',
align: 'center',
minWidth: 80,
slots: {
default: ({ row }) => {
return renderBooleanTag(row, 'edit');
},
edit: ({ row }) => {
return renderBooleanCheckbox(row, 'edit');
},
},
editRender: {},
},
{
title: '列表',
field: 'list',
showOverflow: 'tooltip',
align: 'center',
minWidth: 80,
slots: {
default: ({ row }) => {
return renderBooleanTag(row, 'list');
},
edit: ({ row }) => {
return renderBooleanCheckbox(row, 'list');
},
},
editRender: {},
},
{
title: '查询',
field: 'query',
showOverflow: 'tooltip',
align: 'center',
minWidth: 80,
slots: {
default: ({ row }) => {
return renderBooleanTag(row, 'query');
},
edit: ({ row }) => {
return renderBooleanCheckbox(row, 'query');
},
},
editRender: {},
},
{
title: '查询方式',
field: 'queryType',
showOverflow: 'tooltip',
align: 'center',
minWidth: 150,
slots: {
default: ({ row }) => {
const queryType = row.queryType;
const found = queryTypeOptions.find((item) => item.value === queryType);
if (found) {
return found.label;
}
return queryType;
},
edit: ({ row }) => {
return (
<Select
class="w-full"
getPopupContainer={getPopupContainer}
options={queryTypeOptions}
v-model:value={row.queryType}
></Select>
);
},
},
editRender: {},
},
{
title: '必填',
field: 'required',
showOverflow: 'tooltip',
align: 'center',
minWidth: 80,
slots: {
default: ({ row }) => {
return renderBooleanTag(row, 'required');
},
edit: ({ row }) => {
return renderBooleanCheckbox(row, 'required');
},
},
editRender: {},
},
{
title: '显示类型',
field: 'htmlType',
showOverflow: 'tooltip',
minWidth: 150,
align: 'center',
slots: {
default: ({ row }) => {
const htmlType = row.htmlType;
const found = componentsOptions.find((item) => item.value === htmlType);
if (found) {
return found.label;
}
return htmlType;
},
edit: ({ row }) => {
return (
<Select
class="w-full"
getPopupContainer={getPopupContainer}
options={componentsOptions}
v-model:value={row.htmlType}
></Select>
);
},
},
editRender: {},
},
{
title: '字典类型',
field: 'dictType',
showOverflow: 'tooltip',
minWidth: 230,
align: 'center',
titlePrefix: {
message: `仅'下拉框', '单选框', '复选框'支持字典类型`,
},
slots: {
default: ({ row }) => {
const dictType = row.dictType;
const found = dictOptions.find((item) => item.value === dictType);
if (found) {
return found.label;
}
return dictType;
},
edit: ({ row }) => {
// 清除的回调 需要设置为空字符串 否则不会提交
const onDeselect = () => {
row.dictType = '';
};
const disabled =
row.htmlType !== 'select' &&
row.htmlType !== 'radio' &&
row.htmlType !== 'checkbox';
return (
<Select
allowClear={true}
class="w-full"
disabled={disabled}
getPopupContainer={getPopupContainer}
onDeselect={onDeselect}
options={dictOptions}
placeholder="请选择字典类型"
v-model:value={row.dictType}
></Select>
);
},
},
editRender: {},
},
];