config.ts 2.36 KB
import { h } from 'vue';
import { findDictItemByCode } from '/@/api/system/dict';
import { FormSchema } from '/@/components/Form';
import { DictEnum } from '/@/enums/dictEnum';
import { useI18n } from '/@/hooks/web/useI18n';
import HelpMessage from '../HelpMessage.vue';

export enum FormFieldsEnum {
  NAME = 'name',
  CATEGORY_NAME = 'classify',
  INTERFACE_ADDRESS = 'uri',
  REQUEST_METHOD = 'requestMethod',
  INTERFACE_PARAMS = 'param',
  DOCUMENT_URL = 'documentUrl',
}

const { t } = useI18n();

export const formSchema: FormSchema[] = [
  {
    field: FormFieldsEnum.NAME,
    label: t('application.api.text.name'),
    component: 'Input',
    required: true,
    componentProps: {
      maxLength: 255,
      placeholder: t('application.api.search.apiNamePlaceholder'),
    },
  },
  {
    field: FormFieldsEnum.CATEGORY_NAME,
    label: t('application.api.text.categoryName'),
    component: 'ApiSelect',
    required: true,
    componentProps() {
      return {
        api: findDictItemByCode,
        params: {
          dictCode: DictEnum.OPEN_API_CLASSIFY,
        },
        labelField: 'itemText',
        valueField: 'itemValue',
        getPopupContainer: () => document.body,
      };
    },
  },
  {
    field: FormFieldsEnum.REQUEST_METHOD,
    label: t('application.api.text.requestMethod'),
    component: 'ApiSelect',
    required: true,
    componentProps() {
      return {
        options: [
          { label: 'GET', value: 'GET' },
          { label: 'POST', value: 'POST' },
          { label: 'PUT', value: 'PUT' },
          { label: 'DELETE', value: 'DELETE' },
        ],
        getPopupContainer: () => document.body,
      };
    },
  },
  {
    field: FormFieldsEnum.INTERFACE_ADDRESS,
    label: h(HelpMessage) as unknown as string,
    component: 'Input',
    required: true,
    componentProps: {
      maxLength: 255,
      placeholder: t('application.api.search.interfaceAddressPlaceholder'),
    },
  },
  {
    field: FormFieldsEnum.INTERFACE_PARAMS,
    label: t('application.api.text.interfaceParams'),
    component: 'Input',
    required: true,
    slot: 'interfaceParamsSlot',
  },
  // {
  //   field: FormFieldsEnum.DOCUMENT_URL,
  //   label: t('application.api.text.documentUrl'),
  //   component: 'InputTextArea',
  //   componentProps: {
  //     maxLength: 255,
  //     placeholder: t('application.api.search.documentUrlPlaceholder'),
  //   },
  // },
];