Skip to content
On this page

Form 表单

查询条件

useForm设置表单布局样式

使用方法操作表单

表单使用案例

下拉框使用字典

dict直接传入字典值, struc 使用方法请参照:类字典配置

ts
import { dict, struc } from '@dt-frames/core'

{
    component: 'Select',
    label: '测试',
    name: 'test',
    props: {
        options: dict('xxx')
    }
},
{
    component: 'Select',
    label: '测试1',
    name: 'test1',
    props: {
        options: struc('xxx')
    }
}

API

UseForm

属性说明类型默认值版本
mode表单使用场景'search' | 'dialog' | null'search'
model默认绑定的modelRecordable
layout对齐方式'vertical' | 'inline' | 'horizontal'horizontal
labelWidth标签的宽度Number | String100
enLabelWidth英文标签宽度Number | String100
schemas表单数据配置FormSchema[][]
labelAlignlabel 标签的文本对齐方式'left' | 'right'right
labelCollabel 标签布局样式设置,同 Col 组件ColEx
wrapperCol内容区域更多设置, 同 Col 组件ColEx
rowProps行相关样式
colProps列相关样式, 同 Col 组件ColEx
size元素的尺寸'small' | 'middle' | 'large'small
disabled表单是否禁用booleanfalse
compact是否使用紧凑布局booleantrue
colonlabel后面是否需要':'booleantrue
allowClear是否显示清除按钮booleantrue
autoFetch是否自动查询, 仅'search'模式支持booleantrue
autoFetchOnEnter回车键搜索, 仅'search'模式支持booleantrue
minShowColumn最小显示的条目数, 仅'search'模式支持number2
showAdvancedButton是否显示折叠按钮, 仅'search'模式支持booleantrue
scrollToFirstError提交失败自动滚动到第一个错误字段, 仅'dialog'模式支持booleantrue
buttons表单后面的按钮(查询条件设置后会替换原有的查询 重置按钮)ButtonProps[] | null | booleanfalse

FormSchema 公共配置

属性说明类型默认值版本
colonlable后面是否有冒号booleantrue
colProps当前item栅格布局控制ColEx
colSlot整个item使用插槽v-slot
component目前支持的表单控件类型'Input'
| 'InputWithDialog'
| 'InputGroup'
| 'InputPassword'
| 'InputSearch'
| 'InputTextArea'
| 'InputNumber'
| 'Select'
| 'TreeSelect'
| 'Radio'
| 'RadioButtonGroup'
| 'RadioGroup'
| 'Checkbox'
| 'CheckboxGroup'
| 'AutoComplete'
| 'Cascader'
| 'DatePicker'
| 'MonthPicker'
| 'RangePicker'
| 'WeekPicker'
| 'TimePicker'
| 'Switch'
| 'Upload'
| 'Slider'
| 'Rate'
| 'Divider'
defaultValue默认值any
description对表单项进行说明stringnull
disabled是否禁用boolean( ( model: Recordable ) => boolean )
dynamicRules动态规则(通过后台校验)(model: Recordable) => Rule[]
enLabelWidth英文状态标签的宽度number | string
extraName点击控件后面的删除按钮需要清空的属性string[]
label标签名string
labelCol标签样式及布局ColEx
labelWidth标签宽度number | string
name表单绑定的属性,亦作为name属性string | string[]
prefix输入框的前缀string | number | VNode | ( ( model: Recordable ) => VNode | VNode[] | string )
props表单控件参数FormSchema.props | (( model: Recordable ) => FormSchema.props)
render自定义渲染控件(model: Recordable) => VNode | VNode[] | string
renderCol自定义渲染整个item(包含label)(model: Recordable) => VNode | VNode[] | string
renderComponent在表单最后面追加一个元素,如:输入框后面添加单位(个)((model: Recordable) => Recordable) | VNode | VNode[] | string
required是否必填boolean | ( ( model: Recordable ) => boolean ) | Ref<boolean> | ComputedRef<boolean>false
rules验证规则Rule[]
rulesMessageJoinLabel提示信息是否带上lablebooleantrue
show控件是否显示boolean( ( model: Recordable ) => boolean )
slot自定义控件使用插槽v-slot
subLabel标签描述 如 这是标签(subLable): ***string
suffix输入框的后缀string | number | VNode | ( ( model: Recordable ) => VNode | VNode[] | string )
t国际化中文描述stringnull
toolTip提示信息boolean | (( model: Recordable ) => boolean)
toolTipProps提示信息TooltipProps
wrapperCol内容样式及布局ColEx

FormSchema.props

控件类型说明类型默认值版本
Input | InputGroup | InputPassword | InputSearch | InputTextArea输入框Input
InputWithDialog点击输入框弹出弹框Input & { openDialog?: (model: Recordable) => void }
InputNumber数字输入框InputNumber
Select下拉框Select
TreeSelect树形下拉数据TreeSelect
Radio | RadioButtonGroup | RadioGroup单选按钮Radio
Checkbox | CheckboxGroup复选框Checkbox
AutoComplete自动填充AutoComplete
Cascader级联选择Cascader
DatePicker | MonthPicker | RangePicker | WeekPicker | TimePicker级联选择DatePicker
Slider滑动输入条Slider
Rate评分Rate
Divider分割线Divider

ColEx

属性说明类型默认值版本
style样式CSSProperties
span占用空间大小number | string
order排序number | string
offset偏移量number | string
md中等屏幕number | string
xl小电脑屏幕number | string
xxl大屏幕number | string

FormActionMethods回调

事件名称说明回调参数
setProps设置form属性( props: FormProps ) => void
updateSchema动态根据name属性跟新表单条目(data: Partial<FormSchema> | Partial<FormSchema>[]) => void
resetSchema动态重置formSchema为传入的参数(data: Partial<FormSchema> | Partial<FormSchema>[]) => void
clearValidate清除错误信息提示(name?: string | string[]) => Promise<void>
resetForms重置表单至初始状态() => void
removeFormByName根据name删除条目(name: string | string[]) => void
setFormValues设置表单绑定的值(values: Recordable) => Promise<void>
getFormValues获取表单绑定的值() => Recordable
appendFormItems动态追加表单条目(
schema: FormSchema[],
prefixField: string | undefined,
first?: boolean | undefined
) => void
validate验证表单输入是否有效() => Promise<any>