Appearance
- default
- chenghua
- shijingshan
- sybz
- gulou
无数据
Appearance
https://element-plus.org/zh-CN/component/form.html
<s-form :model="model" :fieldList="fieldList" :rules="rules" ref="gFormRef"></s-form>切换主题查看表单及其 schema 控件的联动样式,单项 attrs.theme 可覆盖表单主题。基础用法:通过顶部选项切换主题。theme 可选值 default / chenghua / shijingshan / sybz / gulou,默认值 default。
subLabel(默认值为空) 16px type="title" isShow | 插槽名 | 说明 | 插槽参数 |
|---|---|---|
prop / slotName | 内容插槽;useSlot: true 时启用,未设置 slotName 时使用当前 prop | SFormContext |
${prop}-label / labelSlotName | label 插槽;未设置 labelSlotName 时使用 ${prop}-label | SFormContext |
slotName | 分组标题插槽;type="title" 且 useSlot: true 时启用 | SFormContext |
s-form 的根节点是 Element Plus 的 el-form(原生 <form>),组件内部已默认阻止原生 submit 的页面跳转,避免表单内输入框回车触发整页刷新(例如在 s-dialog 中新建数据时弹窗被刷新关闭)。内部只调用 event.preventDefault(),不阻止事件冒泡,通过 @submit 传入的监听仍会正常触发。
true) tooltip(默认值为空) | 属性名 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| fieldList | 表单 schema 配置 | array / object | - |
| model | 表单数据对象 | object | - |
| theme | 主题,传递给 s-* 控件和分组标题 | default / chenghua / shijingshan / sybz | default |
| column | 默认每行展示几项 | 1 / 2 / 3 / 4 / 5 / 6 | 1 |
| gap | 多列表单项左右间距,仅 column > 1 时生效 | string / number | 16px |
| align | 表单项垂直对齐 | center / top / flex-end | top |
| showFooter | 是否显示调试按钮 | boolean | 开发环境为 true |
| footer | showFooter 的别名,设置后优先级更高 | boolean | - |
| autoSetDefaultValue | 是否自动写入字段默认值 | boolean | true |
| trim | 是否自动去除字符串字段值的前后空格;字段 normalize / transform 优先级更高 | boolean | true |
| componentDefaults | 所有控件的默认透传属性 | object | { clearable: true, filterable: true, width: '100%' } |
fieldList 是 s-form 的表单 schema 配置。每一项只保留表单编排需要的字段;控件属性统一放到 attrs,表单项属性统一放到 formItemAttrs。例如 type="title" 时,s-title 的 title、subTitle、theme、type 等属性都写到 attrs 里。
TypeScript 项目中建议从 sybz-components/types 引入表单项类型,让动态函数里的 model、value、setFieldValue 等上下文有明确提示:
import type { SFormFieldItem } from 'sybz-components/types'
const fieldList: SFormFieldItem[] = [
{ label: '账号', prop: 'account', required: true },
{ label: '角色', prop: 'role', comp: 's-select', attrs: { options: roleOptions } },
]import type { SFormFieldItem } from 'sybz-components/types'
const fieldList: SFormFieldItem[] = [
{ label: '账号', prop: 'account', required: true },
{ label: '角色', prop: 'role', comp: 's-select', attrs: { options: roleOptions } },
]| 属性名 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| label | 左侧显示的 label 值 | string | - |
| subLabel | label 下方的副文本,支持函数动态返回 | string / Function | - |
| prop | 值对应路径,支持 a.b、a.0.b、a[0].b | string | - |
| comp | 要渲染的组件名称或组件对象 | string / Component | s-input |
| attrs | 透传给表单控件;type="title" 时透传给 s-title,标题文案也写在这里 | object / Function | - |
| formItemAttrs | 透传给 el-form-item | object / Function | - |
| rules | 当前项校验规则,函数参数为表单上下文 | object / array / Function | - |
| required | 快速生成必填规则;传字符串时作为错误提示 | boolean / string | - |
| defaultValue | 默认值,model 对应路径不存在时写入 | any | - |
| render | 自定义内容渲染,参数为表单上下文 | Function | - |
| isShow | 是否展示当前项,函数参数为表单上下文 | boolean / Function | true |
| useSlot | 使用插槽渲染 | boolean | false |
| slotName | 内容插槽名;未设置时使用 prop,type="title" 时也作为标题插槽名 | string | - |
| labelSlotName | label 插槽名,未设置时使用 ${prop}-label | string | - |
| labelRender | 自定义标签渲染,可与 tooltip 同时使用,优先于标签插槽 | Function | - |
| tooltip | 标签右侧提示图标的悬浮内容,支持函数动态返回,可与 labelRender 或标签插槽同时使用 | string / Function | - |
| tooltipAttrs | 提示图标及 Tooltip 属性,支持 dangerouslyUseHTMLString | object / Function | - |
| copy | 是否显示 tooltip 复制图标;传字符串时复制指定文本 | boolean / string | true |
| type | 项类型;设置为 title 时渲染分组标题,attrs 会透传给 s-title | string | - |
| trim | 提交/校验前是否对当前字段去除前后空格,可覆盖表单级配置 | boolean | 跟随 s-form.trim |
attrs、formItemAttrs、rules、isShow、render 和插槽都会拿到同一份上下文:{ option, model, value, prop, index, formRef, getValue, setValue, setFieldValue }。其中 option 是当前 fieldList 配置项,model 是完整表单数据。
| 名称 | 说明 | 类型 | | :----------------: | ------------------------------------ | --------------------------------------------------------- | --- | | validate | 校验 form 表单,成功后返回当前 model | Function(isResetFieldsOrParams = false, otherParams = {}) | | validateField | 校验指定字段 | Function | | resetFields | 重置 form 表单 | Function | | clearValidate | 清除校验 | Function(props?: string / string[]) | | scrollToField | 滚动到指定字段 | Function(prop: string) | | submit | 调用 validate | Function | | getModel | 获取当前 model | Function | | getValue | 获取指定路径的值 | Function(prop: string) | | setValue | 设置指定路径的值 | Function(prop: string, value: any) | | getFields | 获取全部字段配置 | Function | | getField | 获取指定字段配置 | Function(prop: string) | | getVisibleFields | 获取当前可见字段配置 | Function | | formRef / sFormRef | 获取内部 el-form 实例 | Ref | --> |