1.0.4 • Published 4 years ago

chem-form v1.0.4

Weekly downloads
38
License
-
Repository
github
Last release
4 years ago

chem-form

使用 json 的方式便捷开发 form

安装

npm install chem-form
# or
yarn add chem-form

为什么

Vue.js + Element-ui 的组合加快了我们开发中台系统的速度,但是开发中发现存在大量的重复的操作,根据业内比较 🔥 的 scheme 的方式配置表单的方式,对其进行二次开发,加速实际开发速度。

如何使用

// main.js
import chemForm from "chem-form"
Vue.use(chemForm)

// common.vue
<template>
  <chem-form v-model="formData" :scheme="formConfig"></chem-form>
</template>

<script lang="ts">
  import { Vue, Component } from "vue-property-decorator";
  @Component
  export default class extends Vue {
    formData:Record<string, any> = {}
    formConfig = {
      DEBUG: true,
      items: [
        { prop: "name", label: "姓名" },
        { prop: "age", label: "年龄", "x-component": "number"},
        // ... add other form config
      ]
    }
  }
</script>

form Prop

NameDescriptionType
v-model表单数据{ }
scheme表单配置
auth表单权限Array

scheme

NameDescriptionparams
DEBUG开启调试模式Boolean
layout展示的形态 type 为展示类型, span 为表格模式下每个 form-item 占的大小{ type: "default / inline / table", span: 8 }
onlyRead是否为只读模式Boolean
attrs扩充属性 element-ui 中 form 自带的属性Object
items表单要展示的内容配置参照 form-item props 配置

form methods

NameDescriptioncallbackparams
resetForm重置表单--
validateForm校验表单Promise-
clearValidate清空校验-propName?: string | string[]
setItem设置某字段的值-propName: string, value: any
getItemRef获取某字段 RefVuepropName: string
getFormModel获取所有表单数据ObjectremoveNull:boolean
submit表单提交Function(model)-

form-item props

Name说明类型默认值
prop绑定的值(对应后端字段)string必填
label页面中显示的名称string必填
isRender是否显示boolean | Functiontrue
required是否进行校验booleanfalse
rules校验规则Array[{ required: true, message: "label 为必填项"}]
description对字段填写的提示信息string | VNodenull
slot插槽的名字 - 该字段使用插槽内容展示stringnull
x-component自带的组件名字stringinput (input / number / select / radio / checkbox / switch /slider / timePicker/ datePicker/ rate / upload )
attrs扩展属性,element-ui 中自带的的属性Record<string, any>{}
listeners扩展监听器,element-ui 该组件自带的监听器Record<string, Function>{}
source源数据,radio,select,checkbox 用来展示的数据{ labelKey: string, valueKey: string, data: any[] | Function }radio / checkbox / select 为必填项
colSpan表格模式下 form-item 占的大小 - 参照饿了么组件 el-col 中的 span 字段number8
supportEntry表格模式下该字段是否支持booleaninput / number / select 默认是 true
1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.2.0

4 years ago

0.1.5

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago