config.ts
7.54 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
import { BasicColumn, FormSchema } from '/@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import { findDictItemByCode } from '/@/api/system/dict';
import { USER_INFO_KEY } from '/@/enums/cacheEnum';
import { getAuthCache } from '/@/utils/auth';
import { isAdmin } from '/@/enums/roleEnum';
import { defaultField } from './constants';
import { useUtils } from '../hooks/useUtils';
// 表格配置
export const columns: BasicColumn[] = [
{
title: '接口名称',
dataIndex: 'interfaceName',
width: 150,
},
{
title: '接口类型',
dataIndex: 'interfaceType',
width: 80,
format(text) {
return text === 'SYSTEM' ? '系统默认' : '自定义';
},
},
{
title: '请求方式',
dataIndex: 'requestContentType',
width: 90,
format(text) {
return Number(text) === 0 ? '普通请求' : Number(text) === 1 ? 'SQL请求' : 'websocket请求';
},
},
{
title: '接口内容',
dataIndex: 'content',
width: 80,
slots: { customRender: 'content' },
},
{
title: '状态',
dataIndex: 'state',
width: 80,
customRender: ({ record }) => {
const color = record.state == 1 ? 'green' : 'red';
const text = record.state == 1 ? '发布' : '未发布';
return h(Tag, { color: color }, () => text);
},
},
];
// 查询配置
export const searchFormSchema: FormSchema[] = [
{
field: 'name',
label: '接口名称',
component: 'Input',
componentProps: {
maxLength: 36,
placeholder: '请输入接口名称',
},
},
{
field: 'state',
label: '发布状态',
component: 'Select',
componentProps: {
options: [
{
label: '发布',
value: 1,
},
{
label: '未发布',
value: 0,
},
],
placeholder: '请选择发布状态',
},
},
{
field: 'interfaceType',
label: '接口类型',
component: 'Select',
colProps: { span: 7 },
componentProps: {
options: [
{
label: '系统默认',
value: 'SYSTEM',
},
{
label: '自定义',
value: 'CUSTOM',
},
],
placeholder: '请选择接口类型',
},
ifShow: ({}) => {
const userInfo: any = getAuthCache(USER_INFO_KEY);
const role: string = userInfo?.roles[0];
if (isAdmin(role)) return true;
else return false;
},
},
];
//表单配置
export const schemas: FormSchema[] = [
{
field: 'interfaceName',
label: '接口名称',
colProps: { span: 24 },
required: true,
component: 'Input',
componentProps: {
maxLength: 255,
placeholder: '请输入接口名称',
},
},
{
field: 'interfaceType',
component: 'ApiRadioGroup',
label: '接口类型',
required: true,
colProps: {
span: 8,
},
defaultValue: 'CUSTOM',
componentProps: {
api: findDictItemByCode,
params: {
dictCode: 'interface_Type',
},
labelField: 'itemText',
valueField: 'itemValue',
},
ifShow: ({}) => {
const userInfo = getAuthCache(USER_INFO_KEY) as any;
const role: string = userInfo?.roles[0];
if (isAdmin(role)) return true;
else return false;
},
},
{
field: 'requestContentType',
label: '请求方式',
component: 'ApiSelect',
required: true,
colProps: { span: 24 },
defaultValue: '0',
componentProps: ({ formActionType }) => {
const { updateSchema, setFieldsValue } = formActionType;
return {
api: findDictItemByCode,
params: {
dictCode: 'dataview_select_methods',
},
placeholder: '请选择请求方式',
labelField: 'itemText',
valueField: 'itemValue',
getPopupContainer: () => document.body,
onChange(e) {
if (!e) return;
const { usePlaceholder } = useUtils();
const setDefaultPlaceholder = usePlaceholder(e);
setFieldsValue(defaultField);
updateSchema({
field: 'requestHttpTypeAndUrl',
componentProps: {
type: e,
},
});
updateSchema({
field: 'requestOriginUrl',
componentProps: {
placeholder: setDefaultPlaceholder,
},
});
},
};
},
},
{
field: 'originUrlType',
label: '地址类型',
component: 'ApiSelect',
required: true,
colProps: { span: 24 },
defaultValue: 'server_url',
componentProps: ({ formActionType }) => {
const { setFieldsValue } = formActionType;
return {
placeholder: '请选择地址类型',
api: findDictItemByCode,
params: {
dictCode: 'dataview_select_origin_type',
},
labelField: 'itemText',
valueField: 'itemValue',
onChange: (e) => {
if (!e) return;
setFieldsValue({
requestOriginUrl: '',
});
},
};
},
},
{
field: 'requestOriginUrl',
label: '源地址',
colProps: { span: 24 },
required: true,
component: 'Input',
componentProps: ({ formActionType }) => {
const { getFieldsValue } = formActionType;
const type = getFieldsValue()?.requestContentType;
const { usePlaceholder } = useUtils();
return {
placeholder: usePlaceholder(type),
};
},
ifShow: ({ values }) => values['originUrlType'] === 'custom_url',
},
{
field: 'requestHttpTypeAndUrl',
label: '请求类型&地址',
component: 'InputGroup',
required: true,
colProps: { span: 24 },
componentProps: ({ formActionType }) => {
const { getFieldsValue } = formActionType;
return {
type: getFieldsValue().requestContentType,
};
},
},
{
field: 'fillAddress',
label: '完整地址',
component: 'Input',
slot: 'slotFillAddress',
colProps: { span: 24 },
ifShow: ({ values }) => {
return values['originUrlType'] === 'custom_url' && values['requestOriginUrl'];
},
},
{
field: 'slotServerAddress',
label: '完整地址',
component: 'Input',
slot: 'slotServerAddress',
colProps: { span: 24 },
ifShow: ({ values }) => {
return values['originUrlType'] === 'server_url';
},
},
{
field: 'requestSQLKey',
label: '键名',
colProps: { span: 6 },
component: 'Input',
defaultValue: 'sql',
componentProps: {
disabled: true,
},
ifShow: ({ values }) => values['requestContentType'] === '1',
},
{
field: 'requestSQLContent',
label: '键值',
colProps: { span: 24 },
component: 'InputTextArea',
defaultValue: 'select * from where',
componentProps: {
maxLength: 255,
placeholder: '请输入键值',
rows: 6,
},
ifShow: ({ values }) => values['requestContentType'] === '1',
},
{
field: 'slot',
label: '参数设置',
component: 'Input',
slot: 'selectMethods',
colProps: { span: 24 },
ifShow: ({ values }) => values['requestContentType'] !== '1',
},
{
field: 'testSlot',
label: '',
component: 'Input',
slot: 'testSql',
colProps: { span: 24 },
ifShow: ({ values }) => values['requestContentType'] === '1',
},
];
//表格表头配置
export const editCellTableTHeadConfig = ['序号', '内置参数', '参数名', '是否必须', '操作'];
export const editTestCellTableTHeadConfig = ['内置参数', '参数名', '参数值'];
export const editTestCellTableTHeaderConfig = ['序号', '参数名', '参数值', '是否必须', '操作'];