1.0.1 • Published 2 years ago

el-form-item-generater v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

el-form-item-generater

根据传入的数据自动生成el-form-item

属性

参数说明类型可选值默认值
forms用于生成formItem的数组ArrayformItemData--[]
modelsitem的值绑定到该对象属性上Object{}{}
justShow是否为展示模式Booleantrue或falsefalse
showValuesjustShow为true时formItem使用该对象的key值Object--{}

formItemData属性

参数说明类型可选值是否必填默认值
type生成的item类型,slot为true时可以不填Stringinput、number、date、daterange、select、radio、checkbox、textarea、upload、link--
labelel-form-item中label的值String----
name从modelsname获取初始值,默认绑定到name值对应的key上String----
placeholder提示信息String----
class自定义el-form-item的classString----
width自定义el-form-item中lalel的宽度Boolean--300
bindKey绑定到models上的keyString----
disabled是否禁止Booleantrue或者falsefalse
required是否必填Booleantrue或者falsefalse
multipleselect是否多选Booleantrue或者falsefalse
clearableselect是否可以清除Booleantrue或者falsefalse
col在一行中占用的列数,参考element-ui Layout布局Number1~248
data用于生成select、radio、checkbox的选项Arrayobject--[]
optionValue选项中value的keyString--value
optionLabel选项中label的keyString--label
optionKey选项中key的keyString--value
formattype为date或者daterange时日期格式String--yyyy-MM-dd HH:mm:ss
slot是否为插槽booleantrue或者falsefalse

type为upload时可用的属性

参数说明类型可选值是否必填默认值
uploadType上传的类型Stringimage、file--
action上传地址String----
imageUrl图片预览地址Stringimage、file--
fileName文件名称(uploadType为file时生效)String----
limit文件大小限制Number--1
patterns允许的文件类型Arraystring--'image/jpeg', 'image/png'
onSuccess上传成功回调Function----
handleChange选择的文件改变时回调Function----

forms传值示例

    <GenerateFormItem
          :forms="projectForms"
          :models="projectData"
          :just-show="justShow"
          :show-values="projectData"

        <template v-slot:slotName>
            <p>自定义的form item</p>
        </template>
    </GenerateFormItem>

<!-- projectForms -->
[
    // 输入框
    {
      type: 'input',
      label: '项目名称',
      name: 'projectName',
    },
    // 日期
    {
      type: 'date',
      label: '离岗日期',
      name: 'leaveTime',
      disabled: this.disabled,
      col: 12,
      required: true,
    },
    // 选择
    {
      type: 'select',
      label: '门禁卡',
      name: 'doorState',
      data: [
        {
          dictValue: '已归还',
          dictKey: 0,
        },
        {
          dictValue: '未归还',
          dictKey: 1,
        },
      ],
      col: 12,
      optionValue: 'dictKey',
      optionLabel: 'dictValue',
      optionKey: 'dictKey',
      required: true,
      bindKey: 'doorState',
    },
    // 上传文件
     {
      type: 'upload',
      label: '个人身份证',
      name: 'personIdUrl',
      action: '/api/futurelab/oss/file/upload',
      imageUrl: this.form.personIdUrl,
      col: 12,
    },
    // 链接只有在展示模式下生效
    {
      type: 'link',
      label: '详细信息',
      name: '查看详细信息',
      tolink: 'http://www.baidu.com',
    },
    // slot
    {
      slot: true,
      name: 'slotName',
    },
    // 单选
    {
        type: 'radio',
        data:[
            {label: '男', value: 1},
            {label: '女', value: 2}
        ]
    }
]