Skip to content

Form

Form 是通用表单容器,适用于搜索、筛选、独立编辑等任何表单场景。所有 Cell 强制 edit 模式。

完整示例

json
{
  "version": "1.0",
  "id": "order-form",
  "name": "订单表单",
  "type": "Form",
  "dicts": { ... },
  "props": {
    "layout": {
      "columns": 2,
      "labelWidth": "100px",
      "labelPosition": "right"
    },
    "fields": [
      {
        "key": "orderNo", "label": "订单号", "cell": "text",
        "disabled": true
      },
      {
        "key": "amount", "label": "金额", "cell": "currency",
        "rules": [{ "required": true, "message": "请输入金额" }]
      },
      {
        "key": "status", "label": "状态", "cell": "enum",
        "cellProps": { "options": "dict:orderStatus" }
      },
      {
        "key": "remark", "label": "备注", "cell": "text",
        "editAs": "textarea", "span": 2
      }
    ],
    "buttons": {
      "submitText": "提交",
      "resetText": "重置",
      "showReset": true
    }
  }
}

layout

字段类型默认值说明
columnsnumber1每行几列
labelWidthstring"auto"label 宽度
labelPosition"left" / "right" / "top""right"label 位置
collapsiblebooleanfalse是否支持展开/收起(搜索场景常用)
defaultCollapsedbooleantrue默认是否收起
visibleRowsnumber1收起时显示几行

fields

每一项为 Cell 声明 + 表单扩展字段:

扩展字段类型默认值说明
rulesarray校验规则
defaultValueany默认值
visiblebooleantrue是否显示
disabledbooleanfalse是否禁用
spannumber1占据列数

buttons

字段类型默认值说明
submitTextstring"提交"提交按钮文字
resetTextstring"重置"重置按钮文字
showResetbooleantrue是否显示重置按钮

与 DataTable 内表单的区别

DataTable 内的表单独立 Form
存在位置DataTable schema 的 props 内部独立的 Schema
字段来源引用 columns 的 key自己定义 fields
渲染方式Dialog 弹窗直接渲染在页面中
数据回填Runtime 自动用行数据回填业务方通过 data prop 传入
用途行编辑/新增搜索、筛选、独立编辑、设置面板等

使用示例

vue
<!-- 搜索表单 -->
<SchemlyRenderer
  :schema="searchSchema"
  :providers="providers"
  @submit="onSearch"
  @reset="onReset"
/>

<!-- 独立编辑表单 -->
<SchemlyRenderer
  :schema="editFormSchema"
  :data="orderDetail"
  :providers="providers"
  @submit="onSave"
/>

Released under the MIT License.