Skip to content
关注微信公众号,获取最新动态
官方QQ交流群:985558286

组件

表单设计器(MakingForm)

API

Props

参数
说明
类型
默认值
preview设计器预览操作按钮显示Booleanfasle
generate-json设计器生成JSON按钮显示Booleanfalse
generate-code设计器生成代码按钮显示Booleanfalse
clearable设计器清空按钮显示Booleanfalse
upload设计器导入JSON按钮显示Booleanfalse
basic-fields设计器左侧基础字段配置Array['input', 'textarea', 'number', 'radio', 'checkbox', 'time', 'date', 'rate', 'color', 'select', 'switch', 'slider', 'text']
advance-fields设计器左侧高级字段配置Array['blank', 'imgupload', 'editor', 'cascader']
layout-fields设计器左侧布局字段配置Array['grid']

Slots

name说明
action设计器头部操作按钮自定义区域

方法

通过 ref ↗ 可以获取到 MakingForm 实例并调用实例方法

方法名说明参数
getJSON获取设计器配置的JSON数据-
getHtml获取设计器生成的可以直接使用的HTML代码-
setJSON设置设计器的配置信息(value) 通过getJSON方法获取的JSON数据
clear清空设计器-

代码演示

自定义操作按钮

html
<template>
  <fm-making-form 
    ref="makingform" 
    style="height: 500px;" 
  >
    <template slot="action">
      <!-- 自定义操作区域插槽 -->
      <el-button type="text" icon="el-icon-upload">保存</el-button>
    </template>
  </fm-making-form>
</template>

字段配置

html
<template>
  <fm-making-form 
    ref="makingform" 
    style="height: 500px;"
    :basic-fields="['input', 'textarea']"
    :advance-fields="['blank', 'fileupload']"
    :layout-fields="[]"
  >
  </fm-making-form>
</template>

获取 json 数据

html
<fm-making-form 
  ref="makingform" 
  style="height: 500px;" 
  preview 
  generate-code 
  generate-json
>
</fm-making-form>
js
const json = this.$refs.makingform.getJSON()

表单生成器(GenerateForm)

API

Props

参数
说明
类型
默认值
data表单json配置数据Object-
value表单数据Object-
remote表单获取数据远端方法Object{}

Events

事件名
说明
回调参数
on-change表单数据变化时触发field: 数据改变的字段标识
value: 数据改变后的值
data: 表单数据

方法

通过 ref ↗ 可以获取到 GenerateForm 实例并调用实例方法

方法名说明参数
getData获取表单数据-
reset重置表单数据-

代码演示

表单生成

直接根据设计器中生成的 json 即可渲染出表单,获取表单数据。

html
<template>
  <div>
    <fm-generate-form 
      :data="jsonData" 
      ref="generateForm"
    >
    </fm-generate-form>
    <el-button type="primary" @click="handleSubmit">Submit</el-button>
  </div>
</template>
js
export default {
  data () {
    return {
      jsonData: {"list":[{"type":"input","icon":"icon-input","options":{"width":"100%","defaultValue":"","required":false,"dataType":"string","pattern":"","placeholder":"","customClass":"","disabled":false,"labelWidth":100,"isLabelWidth":false,"hidden":false,"dataBind":true,"showPassword":false,"remoteFunc":"func_1575897887618","remoteOption":"option_1575897887618"},"name":"单行文本","key":"1575897887618","model":"input_1575897887618","rules":[{"type":"string","message":"单行文本格式不正确"}]}],"config":{"labelWidth":100,"labelPosition":"right","size":"small","customClass":""}},
    }
  },
  methods: {
    handleSubmit () {
      this.$refs.generateForm.getData().then(data => {
        alert(JSON.stringify(data))
      }).catch(e => {
      })
    }
  }
}

加载表单数据

html
<template>
  <div>
    <fm-generate-form 
      :data="jsonData"
      :value="editData" 
      ref="generateForm"
    >
    </fm-generate-form>
  </div>
</template>
js
export default {
  data () {
    return {
      jsonData: {"list":[{"type":"input","icon":"icon-input","options":{"width":"100%","defaultValue":"","required":false,"dataType":"string","pattern":"","placeholder":"","customClass":"","disabled":false,"labelWidth":100,"isLabelWidth":false,"hidden":false,"dataBind":true,"showPassword":false,"remoteFunc":"func_1575897887618","remoteOption":"option_1575897887618"},"name":"名称","key":"1575897887618","model":"name","rules":[{"type":"string","message":"名称格式不正确"}]}],"config":{"labelWidth":100,"labelPosition":"right","size":"small","customClass":""}},
      editData: {
        /* 需要加载的表单数据可以在这里进行设置 */
        name: 'Gavin'
      },
    }
  }
}

表单字段值改变事件

表单字段值改变后会触发 on-change 事件。

html
<template>
  <div>
    <fm-generate-form 
      :data="jsonData" 
      @on-change="onChange"
      :value="formData"
      ref="generateForm"
    >
    </fm-generate-form>
  </div>
</template>
js
export default {
  data () {
    return {
      jsonData: {"list":[{"type":"input","icon":"icon-input","options":{"width":"100%","defaultValue":"","required":false,"dataType":"string","pattern":"","placeholder":"","customClass":"","disabled":false,"labelWidth":100,"isLabelWidth":false,"hidden":false,"dataBind":true,"showPassword":false,"remoteFunc":"func_1575897887618","remoteOption":"option_1575897887618"},"name":"名称","key":"1575897887618","model":"name","rules":[{"type":"string","message":"名称格式不正确"}]},{"type":"text","icon":"icon-wenzishezhi-","options":{"defaultValue":"","customClass":"","labelWidth":100,"isLabelWidth":false,"hidden":false,"dataBind":true,"remoteFunc":"func_1575906202073","remoteOption":"option_1575906202073"},"name":"","key":"1575906202073","model":"show","rules":[]}],"config":{"labelWidth":100,"labelPosition":"right","size":"small","customClass":""}},
      formData: {
        show: ''
      }
    }
  },
  methods: {
    onChange (field, value) {
      if (field == 'name') {
        this.formData.show = value
      }
    }
  }
}