create.config.ts 1.33 KB
import { RouteLocationNormalizedLoaded } from 'vue-router';
import { RuleChainFieldsEnum, RuleChainFieldsNameEnum } from '../../../enum/formField/flow';
import { getRuleChains } from '/@/api/ruleDesigner';
import { FormSchema } from '/@/components/Form';

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) {
    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: RuleChainFieldsNameEnum.RULE_CHAIN_ID,
      component: 'ApiSearchSelect',
      componentProps: () => {
        return {
          placeholder: '请选择规则链',
          showSearch: true,
          params: {
            pageSize: 50,
            page: 0,
            type: 'CORE',
          },
          api: (params: Recordable) => fetch(params, ruleChainId),
          searchApi: (params: Recordable) => fetch(params, ruleChainId),
          getPopupContainer: () => document.body,
        };
      },
    },
  ];
};