create.config.ts
1.68 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
import { RouteLocationNormalizedLoaded } from 'vue-router';
import { RuleChainFieldsEnum, RuleChainFieldsNameEnum } from '../../../enum/formField/flow';
import { getRuleChainDetail, getRuleChains } from '/@/api/ruleDesigner';
import { FormSchema } from '/@/components/Form';
import { useI18n } from '/@/hooks/web/useI18n';
const { t } = useI18n();
const fetch = async (params: Recordable, ruleChainId: string) => {
try {
const result = await getRuleChains(params);
const data = result.data
.map((item) => ({ label: item.name, value: item.id.id }))
.filter((item) => item.value !== ruleChainId);
return data;
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
return [];
}
};
export const getFormSchemas = (route: RouteLocationNormalizedLoaded): FormSchema[] => {
const ruleChainId = (route.params as Record<'id', string>).id;
return [
{
field: RuleChainFieldsEnum.RULE_CHAIN_ID,
label: t(RuleChainFieldsNameEnum.RULE_CHAIN_ID),
component: 'ApiSearchSelect',
componentProps: () => {
return {
placeholder: '请选择规则链',
showSearch: true,
params: (textSearch: string) => {
return {
pageSize: 10,
page: 0,
type: 'CORE',
textSearch,
};
},
api: (params: Recordable) => fetch(params, ruleChainId),
queryApi: async (id: string) => {
if (!id) return;
const data = await getRuleChainDetail(id);
return { label: data.name, value: data.id.id };
},
getPopupContainer: () => document.body,
};
},
},
];
};