Skip to content

dynamic-form(动态表单)

基础用法

示例:动态表单

代码示例:

vue
<template>
  <div class="bs-bg-color-white w640 p20">
    <div class="pct40 dib mr16 mt8" :key="e" v-for="e in FORM_TYPE">
      <span>{{ FORM_TYPE_LABEL[e] }}:</span>
      <v-dynamic-form v-model="data[e]" :type="e" :options="DATA_LIST"></v-dynamic-form>
    </div>
  </div>
</template>

<script>

/**
 * 表单类型
 */
const FORM_TYPE = {
  INPUT: 'input', //输入框
  FORMAT_INPUT: 'formatInput', //金额输入框
  TEXTAREA: 'textarea', //文本域输入框
  SELECT: 'select', //选择框
  RADIO: 'radio', //单选框
  CHECKBOX: 'checkbox', //复选框
  DATE: 'date', //日期选择框
  DATE_TIME: 'datetime', //日期时间选择框
  MONTH: 'month', //月份选择框
  SWITCH: 'switch', //是否选择框
  TREE: 'tree', //树形选择框
  SELECT_INPUT: 'selectInput', //输入选择框
  FILE: 'file', //文件上传框
  AREA_INPUT: 'areaInput', //区域选择框
  BANK_INPUT: 'bankInput', //银行输入框
};

/**
 * 表单类型名称
 */
const FORM_TYPE_LABEL = {
  input: '输入框',
  formatInput: '金额输入框',
  textarea: '文本域输入框',
  select: '选择框',
  radio: '单选框',
  checkbox: '复选框',
  date: '日期选择框',
  datetime: '日期时间选择框',
  month: '月份选择框',
  switch: '是否选择框',
  tree: '树形选择框',
  selectInput: '输入选择框',
  file: '文件上传框',
  areaInput: '区域选择框',
  bankInput: '银行输入框',
};

const DATA_LIST = [
  {code: '01', name: '一'},
  {code: '02', name: '二'},
]
export default {
  data() {
    return {
      data: {checkbox: []},
      FORM_TYPE,
      FORM_TYPE_LABEL,
      DATA_LIST,
    };
  },
  methods: {
  },
};
</script>

属性:

参数说明类型可选值默认值
unit单位(支持金额输入框元、万元、亿元切换)String'yuan','wanyuan','yiyuan''yuan'
type表单类型(默认为输入框)Stringinput,formatInput,textarea,select,radio,checkbox,date,datetime,month,switch,tree,selectInput,file,areaInput,bankInput'input'
value当前组件的值String, Number, Array--
options选项数据Array-[]
optionsProps选项数据属性字段Object-id:'code',label:'name',pid:'pcode',children:'children',disabled:'disabled'
placeholderplaceholderString-''
readonly是否为只读状态Boolean-false
disabled是否为禁用状态Boolean-false
maxlengthtype为textarea时,最大长度Number-9999
showWordLimittype为textarea时,是否显示字数统计Boolean-false
inputAutosizetype为textarea时,自适应高度Boolean-false
inputNegativetype为format-input时,是否可以输入负数Boolean-true
clearable是否可以清除Boolean-true
multiple是否为多选状态Boolean-false
displaytype为tree-input时,显示内容String-'NAME'
showSecond是否可以选择时间Boolean-false
triggerOnFocustype为select-input时,是否在输入框focus时显示选项Boolean-false
collapseTagstype为tree-input时,多选状态下是否折叠已选项Boolean-true
bindPropstype为datetime、selectInput时,绑定的字段String--
encrypttype为select-input时,数据项是否加密显示Boolean-false
selectInputTooltiptype为select-input时,组件是否显示提示信息Boolean-false
tiptype为select-input时,提示信息String--
displayRmbtype为format-input时,是否显示人民币符号Boolean-false
uploadUrltype为file-input时,上传的urlString--
formatDecimaltype为format-input时,组件小数位数Number--
treeDataTypetype为tree-input时,组件数据类型String-'ARRAY'
treeLeaftype为tree-input时,组件默认的显示级次Boolean-false
treeExpandtype为tree-input时,组件是否默认展开Boolean-true
treeSortKeytype为tree-input时,排序字段对应的键名String--
verifyValue是否校验数据(用于当前组件的值在选项数据中不存在,解决下拉框显示为code的问题)Boolean-false

事件:

事件名说明参数参数说明
input输入事件event-
removetype为file-input时,删除事件attachIdList文件id
verify校验数据verifyResult校验结果(true/false)
focus获取焦点事件event-
blur失去焦点事件event-
change组件的值变化时触发事件...event-
clear清除事件event-
visible-change显示隐藏改变时触发event-
remove-tag删除标签触发事件event-

方法:

方法名说明参数参数说明
focus使组件获得焦点--
blur使组件失去焦点--
select使组件选中--
clear使组件清空--

插槽:

插槽名说明参数参数说明
select-displaytype为select时的插槽node节点数据
option-righttype为select-input时,内容项右侧插槽data选项数据
select-inputtype为select-input时,提示信息内容插槽data选项数据