create.config.ts 6.35 KB
import { ProtocolEnum, ProtocolNameEnum, RequestMethodEnum } from '../../../enum/form';
import { RestApiCallFieldsEnum, RestApiCallFieldsNameEnum } from '../../../enum/formField/external';
import { FormSchema } from '/@/components/Form';
import { useI18n } from '/@/hooks/web/useI18n';

const { t } = useI18n();

export const formSchemas: FormSchema[] = [
  {
    field: RestApiCallFieldsEnum.REST_ENDPOINT_URL_PATTERN,
    label: t(RestApiCallFieldsNameEnum.REST_ENDPOINT_URL_PATTERN),
    component: 'Input',
    required: true,
    helpMessage:
      'Hint: use ${metadataKey} for value from metadata, $[messageKey] for value from message body',
    componentProps: {
      placeholder: `请输入${t(RestApiCallFieldsNameEnum.REST_ENDPOINT_URL_PATTERN)}`,
    },
  },
  {
    field: RestApiCallFieldsEnum.REQUEST_METHOD,
    label: t(RestApiCallFieldsNameEnum.REQUEST_METHOD),
    component: 'Select',
    required: true,
    componentProps: {
      options: Object.keys(RequestMethodEnum).map((value) => ({ label: value, value })),
      getPopupContainer: () => document.body,
      placeholder: `请选择${t(RestApiCallFieldsNameEnum.REQUEST_METHOD)}`,
    },
  },
  {
    field: RestApiCallFieldsEnum.ENABLE_PROXY,
    label: '',
    component: 'Checkbox',
    renderComponentContent: () => ({
      default: () => t(RestApiCallFieldsNameEnum.ENABLE_PROXY),
    }),
  },
  {
    field: RestApiCallFieldsEnum.USE_SIMPLE_CLIENT_HTTP_FACTORY,
    label: '',
    component: 'Checkbox',
    show: ({ model }) => !model[RestApiCallFieldsEnum.ENABLE_PROXY],
    renderComponentContent: () => ({
      default: () => t(RestApiCallFieldsNameEnum.USE_SIMPLE_CLIENT_HTTP_FACTORY),
    }),
  },
  {
    field: RestApiCallFieldsEnum.IGNORE_REQUEST_BODY,
    label: '',
    component: 'Checkbox',
    renderComponentContent: () => ({
      default: () => t(RestApiCallFieldsNameEnum.IGNORE_REQUEST_BODY),
    }),
  },
  {
    field: RestApiCallFieldsEnum.USE_SYSTEM_PROXY_PROPERTIES,
    label: '',
    component: 'Checkbox',
    show: ({ model }) => model[RestApiCallFieldsEnum.ENABLE_PROXY],
    renderComponentContent: () => ({
      default: () => t(RestApiCallFieldsNameEnum.USE_SYSTEM_PROXY_PROPERTIES),
    }),
  },
  {
    field: RestApiCallFieldsEnum.PROXY_SCHEME,
    label: t(RestApiCallFieldsNameEnum.PROXY_SCHEME),
    component: 'Select',
    required: true,
    colProps: { span: 8 },
    componentProps: {
      options: Object.keys(ProtocolEnum).map((value) => ({
        label: ProtocolNameEnum[value],
        value,
      })),
      getPopupContainer: () => document.body,
      placeholder: `请选择${t(RestApiCallFieldsEnum.PROXY_SCHEME)}`,
    },
    ifShow: ({ model }) => {
      const ifShowField = model[RestApiCallFieldsEnum.ENABLE_PROXY];
      return ifShowField && !model[RestApiCallFieldsEnum.USE_SYSTEM_PROXY_PROPERTIES];
    },
  },
  {
    field: RestApiCallFieldsEnum.PROXY_HOST,
    label: t(RestApiCallFieldsNameEnum.PROXY_HOST),
    component: 'Input',
    required: true,
    colProps: { span: 8 },
    componentProps: {
      placeholder: `请输入${t(RestApiCallFieldsNameEnum.PROXY_HOST)}`,
    },
    ifShow: ({ model }) => {
      const ifShowField = model[RestApiCallFieldsEnum.ENABLE_PROXY];
      return ifShowField && !model[RestApiCallFieldsEnum.USE_SYSTEM_PROXY_PROPERTIES];
    },
  },
  {
    field: RestApiCallFieldsEnum.PROXY_PORT,
    label: t(RestApiCallFieldsNameEnum.PROXY_PORT),
    component: 'InputNumber',
    required: true,
    colProps: { span: 8 },
    componentProps: {
      placeholder: `请输入${t(RestApiCallFieldsNameEnum.PROXY_HOST)}`,
    },
    ifShow: ({ model }) => {
      const ifShowField = model[RestApiCallFieldsEnum.ENABLE_PROXY];
      return ifShowField && !model[RestApiCallFieldsEnum.USE_SYSTEM_PROXY_PROPERTIES];
    },
  },
  {
    field: RestApiCallFieldsEnum.PROXY_USER,
    label: t(RestApiCallFieldsNameEnum.PROXY_USER),
    component: 'Input',
    componentProps: {
      placeholder: `请输入${t(RestApiCallFieldsNameEnum.PROXY_USER)}`,
    },
    ifShow: ({ model }) => {
      const ifShowField = model[RestApiCallFieldsEnum.ENABLE_PROXY];
      return ifShowField && !model[RestApiCallFieldsEnum.USE_SYSTEM_PROXY_PROPERTIES];
    },
  },
  {
    field: RestApiCallFieldsEnum.PROXY_PASSWORD,
    label: t(RestApiCallFieldsNameEnum.PROXY_PASSWORD),
    component: 'Input',
    componentProps: {
      placeholder: `请输入${t(RestApiCallFieldsNameEnum.PROXY_PASSWORD)}`,
    },
    ifShow: ({ model }) => {
      const ifShowField = model[RestApiCallFieldsEnum.ENABLE_PROXY];
      return ifShowField && !model[RestApiCallFieldsEnum.USE_SYSTEM_PROXY_PROPERTIES];
    },
  },
  {
    field: RestApiCallFieldsEnum.READ_TIMEOUT_MS,
    label: t(RestApiCallFieldsNameEnum.READ_TIMEOUT_MS),
    component: 'InputNumber',
    componentProps: {
      min: 0,
      placeholder: `请输入${t(RestApiCallFieldsNameEnum.READ_TIMEOUT_MS)}`,
    },
  },
  {
    field: RestApiCallFieldsEnum.MAX_PARALLEL_REQUESTS_COUNT,
    label: t(RestApiCallFieldsNameEnum.MAX_PARALLEL_REQUESTS_COUNT),
    component: 'InputNumber',
    componentProps: {
      min: 0,
      placeholder: `请输入${t(RestApiCallFieldsNameEnum.MAX_PARALLEL_REQUESTS_COUNT)}`,
    },
  },
  {
    field: RestApiCallFieldsEnum.HEADERS,
    label: t(RestApiCallFieldsNameEnum.HEADERS),
    component: 'Input',
    slot: RestApiCallFieldsEnum.HEADERS,
  },
  {
    field: RestApiCallFieldsEnum.USE_REDIS_QUEUE_FOR_MSG_PERSISTENCE,
    label: '',
    component: 'Checkbox',
    renderComponentContent: () => ({
      default: () => t(RestApiCallFieldsNameEnum.USE_REDIS_QUEUE_FOR_MSG_PERSISTENCE),
    }),
  },
  {
    field: RestApiCallFieldsEnum.TRIM_QUEUE,
    label: '',
    component: 'Checkbox',
    ifShow: ({ model }) => model[RestApiCallFieldsEnum.USE_REDIS_QUEUE_FOR_MSG_PERSISTENCE],
    renderComponentContent: () => ({
      default: () => t(RestApiCallFieldsNameEnum.TRIM_QUEUE),
    }),
  },
  {
    field: RestApiCallFieldsEnum.MAX_QUEUE_SIZE,
    label: t(RestApiCallFieldsNameEnum.MAX_QUEUE_SIZE),
    component: 'InputNumber',
    ifShow: ({ model }) => model[RestApiCallFieldsEnum.USE_REDIS_QUEUE_FOR_MSG_PERSISTENCE],
    componentProps: {
      min: 0,
      placeholder: `请输入${t(RestApiCallFieldsNameEnum.MAX_QUEUE_SIZE)}`,
    },
  },
  {
    field: RestApiCallFieldsEnum.CREDENTIALS,
    label: t(RestApiCallFieldsNameEnum.CREDENTIALS),
    component: 'Input',
    slot: RestApiCallFieldsEnum.CREDENTIALS,
  },
];