Skip to content

Component

Form Designer(MakingForm)

API

Props

Parameter
Description
Type
Default
previewShow the designer preview action buttonBooleanfasle
generate-jsonShow the designer generates the JSON buttonBooleanfalse
generate-codeShow the designer generates the code buttonBooleanfalse
clearableShow the designer empty buttonBooleanfalse
uploadShow the designer import JSON buttonBooleanfalse
basic-fieldsShow the left base field configuration of the designerArray['input', 'textarea', 'number', 'radio', 'checkbox', 'time', 'date', 'rate', 'color', 'select', 'switch', 'slider', 'text']
advance-fieldsShow the advanced field configuration on the left side of the designerArray['blank', 'imgupload', 'editor', 'cascader']
layout-fieldsShow the layout field configuration on the left of the designerArray['grid']

Slots

nameDescriptions
actionDesigner head action button custom area

Method

Through ref ↗, we can get MakingForm instance and invoke the instance methods.

Mthod NameDescriptionsParameter
getJSONGet the JSON data for the designer configuration-
getHtmlGet the HTML code generated by the designer that can be used directly-
setJSONSets the configuration information for the designer(value) The JSON data obtained through the getJSON method
clearEmpty the designer-

Code Demonstration

Custom Action Buttons

html
<template>
  <fm-making-form 
    ref="makingform" 
    style="height: 500px;" 
  >
    <template slot="action">
      <!-- Custom operation area slots -->
      <el-button type="text" icon="el-icon-upload">Save</el-button>
    </template>
  </fm-making-form>
</template>

Field Configuration

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

Get JSON Data

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

Form Generator(GenerateForm)

API

Props

Parameter
Descriptions
Type
Default
dataForm json configuration dataObject-
valueForm dataObject-
remoteremote method used for get Form dataObject{}

Events

Event Name
Descriptions
CallBack Parameter
on-changeTriggered when the form data changesfield: The field identification of the data changed
value: The value of the data after the changed
data: Form data

Method

Through ref ↗, we can get GenerateForm instance and invoke the instance methods

Method NameDescriptionsParameter
getDataGet form data-
resetReset form data-

Code Demonstration

Form Generation

The form can be rendered directly according to the json generated in the designer, and the form data can be obtained.

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 => {
      })
    }
  }
}

Loading Form Data

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: {
        /* The form data to be loaded can be set here */
        name: 'Gavin'
      },
    }
  }
}

Form Field Value changed Event

The on-change event is triggered when the value of the form field changed.

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
      }
    }
  }
}