index.ts 2.48 KB
import { BasicColumn, FormSchema } from '/@/components/Table';
import { findDictItemByCode } from '/@/api/system/dict';

import { DictEnum } from '/@/enums/dictEnum';

export const columns: BasicColumn[] = [
  {
    title: '名称',
    dataIndex: 'name',
  },
  {
    title: '领域',
    dataIndex: 'dictItemName',
  },
  {
    title: '状态',
    dataIndex: 'status',
    slots: { customRender: 'status' },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '名称',
    component: 'Input',
    colProps: { span: 6 },
    componentProps: {
      maxLength: 255,
      placeholder: '请输入品类名称',
    },
  },
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    colProps: { span: 6 },
    componentProps: {
      options: [
        { label: '启用', value: '1' },
        { label: '禁用', value: '0' },
      ],
      placeholder: '请选择品类状态',
    },
  },
  {
    field: 'dictItemId',
    label: '领域',
    component: 'ApiSelect',
    colProps: { span: 6 },
    componentProps() {
      return {
        api: findDictItemByCode,
        params: {
          dictCode: DictEnum.CATEGORY_FIELD,
        },
        labelField: 'itemText',
        valueField: 'itemValue',
        placeholder: '请选择领域',
        getPopupContainer: () => document.body,
      };
    },
  },
];

export const schemas: FormSchema[] = [
  {
    field: 'name',
    label: '品类名称',
    component: 'Input',
    colProps: { span: 21 },
    required: true,
    componentProps: {
      maxLength: 20,
    },
  },
  {
    field: 'dictItemId',
    label: '领域',
    component: 'ApiSelect',
    colProps: { span: 21 },
    required: true,
    componentProps({ formActionType }) {
      return {
        api: findDictItemByCode,
        params: {
          dictCode: DictEnum.CATEGORY_FIELD,
        },
        onChange(value, options) {
          formActionType.setFieldsValue({ dictItemName: value ? options.label : '' });
        },
        labelField: 'itemText',
        valueField: 'itemValue',
        placeholder: '请选择领域',
        getPopupContainer: () => document.body,
      };
    },
  },
  {
    field: 'dictItemName',
    label: '领域名称',
    ifShow: false,
    component: 'Input',
  },
  {
    field: 'status',
    label: '状态',
    component: 'RadioButtonGroup',
    defaultValue: 1,
    componentProps: {
      options: [
        { label: '启用', value: 1 },
        { label: '禁用', value: 0 },
      ],
    },
  },
];