# Create-Form 创建表单

# install

tnpm i -S @sula-template/create-form

# usage

import CreateForm from "@sula-template/create-form";

# API

# ref

获取 form 实例

# container

  • 类型:ReactElement | (ctx) => ReactElement |RenderType
  • 默认值:'card'

表单容器,容器组件会包裹表单, 同form container

# layout

  • 类型: 'horizontal' | 'vertical' | 'inline'
  • 默认值: 'horizontal'

# itemLayout

  • 类型:object
  • 默认值:{ span: 24, labelCol: { span: 6 }, wrapperCol: { span: 12 } }

表单项布局分布,同itemLayout

# mode

  • 类型:'create' | 'view' | 'edit'
  • 默认值: 'create'

表单模式,create👉 创建模式,view👉 查看模式,edit👉 编辑模式

# initialValues

  • 类型: object
  • 默认值: -

表单初始值

# remoteValues

表单初始值远程请求配置

示例:

{
  url: '表单初始值数据请求地址',
  method: '请求方法',
  params: {
    // 请求参数
  },
  converter: (ctx, config) => {
    //请求返回数据转化 可通过ctx.data获取接口返回数据
  },
}

# fields

  • 类型:Array<Field>
  • 默认值:-

表单控件配置

示例:

[
  {
    name: "表单控件name属性",
    label: "label标签",
    render: RenderType
  }
];

# footerActions

  • 类型:Array
  • 默认值:-

底部按钮配置,完整参数配置同footerRender

示例:

[
  {
    type: "button",
    text: "Create",
    path: "/task/new",
    query: { id: "s500" },
    props: {
      icon: "plus",
      type: "success",
      shape: "round"
    }
  }
];

使用 tips:

  • 配置在页面页脚处
  • 不传默认显示back按钮

# actionsPosition

  • 类型:bottom | inner | innerRight
  • 默认值:bottom

按钮组位置

# formProps

表单其他配置,详细配置请查看sula-form

# submit

向后端提交表单信息

示例:

{
  url: "https://jsonplaceholder.typicode.com/posts/1",
  type: "get",
  params: {
   id: '0323',
  },
  final() {},
  finish({ result }) {}, // 完成后要串联的下个动作
};

配置参数:

参数 说明 类型 默认值
url 请求路径 string -
type 请求方式 string -
params 请求参数 object -
final 最后回调 () => void -
finish 成功回调 (result) => void -

使用 tips:

  • params和表单的value进行合并
  • final在finally中执行,无论成功失败都会调用。
  • finish请求成功时执行。
Last Updated: 2020/3/16 上午10:04:47