Skip to content
On this page

Form组件

通过配置JSON快速构建表单

快捷搜索配置

select-v2虚拟列表

  • 适用于数据量庞大列表

select-options静态数据配置

select-options动态数据配置

select-options筛选选项配置

select-options远程搜索配置

select-options联动配置

select-options字段映射配置

options操作的数据是valuelabel,如果数据返回的不是valuelabel,可以通过optionsLabelKeyoptionsValueKey配置自动转换

Form 表单

表单布局采用的是el-col,默认每个表单是宽度是24/6=4(一行可以排列4个表单),可以手动指定span属性设置,例如span="12"

Form Prop

属性名说明类型默认值属性
model-value / v-model绑定值
models表单数据回显
formPropselement-plus FormPropsFormProps查看
gutter栅格间隔 (同el-row)number24
span栅格占据的列数 (同el-col)number6
components组件列表
查看
buttonsPosition操作按钮的位置
end
buttonsSpan栅格占据的列数 (同el-col)number默认是span的值
hiddenSubmit是否隐藏查询按钮booleanfalse
hiddenResetForm是否重置取消按钮booleanfalse
submitText查询按钮文本string查询
resetFormText重置按钮文本string重置
isResetFormApi重置按钮是否触发提交booleantrue
submit表单验证成功接口执行成功后触发
resetForm重置按钮点击触发

ComponentsProps

组件列表属性(components)

属性名说明类型默认值属性
model表单的keystring
components组件的类型
subComponents组件的类型(select,checkbox,radio需要)
props组件的属性(同组件的属性)
查看
events组件事件(同组件的事件)
optionsselect,checkbox,radio
查看
optionsLabelKey映射options labelstringlabel
optionsValueKey映射options valuestringvalue
stypeProps自定义样式

TypeComponentsProps

每个组件(props)

属性名说明类型默认值属性
label表单项的名称string
rules表单项验证(同element-plus)Array<any>
span表单项栅格占据的列数number
hidden是否隐藏表单项booleanfalse
defaultValue表单项默认值number
labelWidth表单项名字长度string
*同element-plus表单项

SelectOptions

el-select、el-checkbox、el-radio(options)

属性名说明类型默认值属性
labellabel
valuevalue
disabled是否禁用booleanfalse
*任意key值[key: string]: any

Form Emits

名称描述类型
submitSucceed表单提交重置后触发

Form Exposes

名称描述类型
ref表单实例FormInstance
loading是否加载中boolean

Form Slot

名称描述类型
modelmodel就是Slot名称{scope:ComponentsProps}

类型声明

显示类型声明
ts
import type {
  CheckboxGroupEmits,
  CheckboxGroupProps,
  DatePickerProps,
  FormInstance,
  FormProps,
  InputEmits,
  InputNumberEmits,
  InputNumberProps,
  InputProps,
  RadioGroupEmits,
  RadioGroupProps,
  RateEmits,
  RateProps,
  SliderEmits,
  SliderProps,
  SwitchEmits,
  SwitchProps,
	SelectContext,
	SelectV2Context
} from 'element-plus';

interface ExtendProps {
  label: string;
  rules: Array<any>;
  span: number;
  hidden: boolean;
  defaultValue: any;
  labelWidth?: string;
}

type SelectProps = SelectContext['props'];
type SelectV2Props = SelectV2Context['props'];

type TreeSelectProps = Record<string, any>;
type TypeComponentsProps =
  | (InputProps & ExtendProps)
  | (SelectProps & ExtendProps)
	| (SelectV2Props & ExtendProps)
  | (DatePickerProps & ExtendProps)
  | (CheckboxGroupProps & ExtendProps)
  | (RadioGroupProps & ExtendProps)
  | (SwitchProps & ExtendProps)
  | (InputNumberProps & ExtendProps)
  | (RateProps & ExtendProps)
  | (SliderProps & ExtendProps)
  | (TreeSelectProps & ExtendProps);

type SelectEmits = Record<string, any>;
type SelectV2Emits = Record<string, any>;
type TreeSelecttEmits = Record<string, any>;
type DatePickerEmits = Record<string, any>;
type ComponentsEvents =
  | InputEmits
  | SelectEmits
	| SelectV2Emits
  | DatePickerEmits
  | CheckboxGroupEmits
  | RadioGroupEmits
  | SwitchEmits
  | InputNumberEmits
  | RateEmits
  | SliderEmits
  | TreeSelecttEmits;
export interface OptionsGroups {
  [key: string]: {
    loading: boolean;
    list: Array<SelectOptions>;
  };
}

export interface SelectOptions {
  label?: string | number;
  value?: string | number | boolean | object;
  disabled?: boolean;
  [key: string]: any;
}

export interface ComponentsProps {
  model: string;
  components:
    | 'el-input'
    | 'el-select'
    | 'el-select-v2'
    | 'el-date-picker'
    | 'el-checkbox-group'
    | 'el-radio-group'
    | 'el-switch'
    | 'el-input-number'
    | 'el-rate'
    | 'el-slider'
    | 'el-tree-select';
  subComponents?: 'el-option' | 'el-checkbox' | 'el-radio';
  props?: Partial<TypeComponentsProps>;
  events?: Partial<ComponentsEvents>;
  dictKey?: string;
  options?: Array<SelectOptions> | ((keyword: string) => Promise<Array<SelectOptions>>);
  optionsLabelKey?: string;
  optionsValueKey?: string;
  stypeProps?: Record<string, any>;
}

export interface AdFormPorps<T = any> {
  modelValue?: T;
  models?: T;
  formProps?: Partial<FormProps>;
  gutter?: number;
  span?: number;
  components: Array<ComponentsProps>;
  buttonsPosition?: 'start' | 'center' | 'end';
  buttonsSpan?: number;
  hiddenSubmit?: boolean;
  hiddenResetForm?: boolean;
  submitText?: string;
  resetFormText?: string;
  isResetFormApi?: boolean;
  submit: (models: T) => Promise<void> | void;
  resetForm?: () => void;
}

export interface AdFormEmits<T = Record<string, any>> {
  (event: 'update:modelValue', models: T): void;
  (event: 'submitSucceed'): void;
}

export interface AdFormInstance {
  ref: FormInstance;
  loading: boolean;
}