dict.data.ts 3.24 KB
import { getDictList } from '/@/api/system/dict';
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { useI18n } from '/@/hooks/web/useI18n';

const { t } = useI18n();

export const columns: BasicColumn[] = [
  {
    title: t('system.dict.dictName'),
    dataIndex: 'dictName',
    width: 200,
    format(text) {
      return t(text);
    },
  },
  {
    title: t('system.dict.dictCode'),
    dataIndex: 'dictCode',
    slots: { customRender: 'dictCode' },
  },
  {
    title: t('system.dict.table.dictRemark'),
    dataIndex: 'description',
    width: 380,
  },
  {
    title: t('common.createTimeText'),
    dataIndex: 'createTime',
    width: 180,
  },
  {
    title: t('common.updateTimeText'),
    dataIndex: 'updateTime',
    width: 180,
  },
];

export const searchFormSchema: FormSchema[] = [
  // {
  //   field: 'dictName',
  //   label: t('system.dict.dictName'),
  //   component: 'Input',
  //   colProps: { span: 6 },
  //   componentProps: {
  //     maxLength: 32,
  //   },
  //   dynamicRules: () => {
  //     return [
  //       {
  //         required: false,
  //         validator: (_, value) => {
  //           if (String(value).length > 32) {
  //             return Promise.reject(t('system.dict.textRule32'));
  //           }
  //           return Promise.resolve();
  //         },
  //       },
  //     ];
  //   },
  // },
  {
    field: 'dictName',
    label: t('system.dict.dictName'),
    component: 'ApiSelect',
    colProps: { span: 6 },
    componentProps: {
      api: async () => {
        const { data: values } = await getDictList();
        return (values || []).map((item) => ({
          label: t(item.dictName) ? t(item.dictName) : item.dictName,
          value: item.dictName,
        }));
      },

      showSearch: true,
      filterOption: (inputValue: string, options: Record<'label', string>) => {
        return options.label.includes(inputValue);
      },
    },
  },
  {
    field: 'dictCode',
    label: t('system.dict.dictCode'),
    component: 'Input',
    colProps: { span: 6 },
    componentProps: {
      maxLength: 32,
    },
    dynamicRules: () => {
      return [
        {
          required: false,
          validator: (_, value) => {
            if (String(value).length > 32) {
              return Promise.reject(t('system.dict.textRule32'));
            }
            return Promise.resolve();
          },
        },
      ];
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'dictName',
    label: t('system.dict.dictName'),
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 32,
    },
  },
  {
    field: 'dictCode',
    label: t('system.dict.dictCode'),
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 32,
    },
  },
  {
    label: t('common.remarkText'),
    field: 'description',
    component: 'InputTextArea',
    componentProps: {
      maxLength: 255,
    },
    dynamicRules: () => {
      return [
        {
          required: false,
          validator: (_, value) => {
            if (String(value).length > 255) {
              return Promise.reject(t('system.dict.textRule255'));
            }
            return Promise.resolve();
          },
        },
      ];
    },
  },
];