0.0.4 • Published 3 months ago

schema-table-form v0.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

安装 SchemaFormTable 🍀

npm install schema-form-table 

使用 SchemaFormTable 🍉

介绍:SchemaFormTable 分为全局引入和按需引入,是一款基于 Vue3 与 TypeScript 的声明式动态表单、表格组件,通过简洁的 JavaScript 对象配置,快速实现复杂业务场景的表单字段联动(显隐、禁用、类型切换)与数据表格渲染。无缝集成 Element Plus 设计规范,支持插槽深度自定义,助力开发者告别重复代码。

全局引入 🍏

在 main.ts 中写入一下代码,因为 SchemaFormTable 的组件是基于 element-plus 开发的,所以在引入之前 element-plus 也必须引入。

import {createApp} from 'vue'
import ElementPlus from 'element-plus'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import 'element-plus/dist/index.css'

import App from './App.vue'

import SchemaFormTable from 'schema-table-form'

const app = createApp(App)
app.use(ElementPlus, {
    locale: zhCn,
})

app.use(SchemaFormTable)
app.mount('#app')

按需引入(SchemaForm) 🍅

在需要使用 SchemaFormTable 的组件中引入 SchemaForm

<script setup lang="ts">
  import {reactive, ref} from "vue"
  import {SchemaForm, FormElemType} from 'schema-table-form'
  import type {FormItemConfig} from "schema-table-form"

  const formState = reactive<Record<string, any>>({
    name: '格子惊蛰版',
    gender: 1
  })

  const formItems = ref<FormItemConfig[]>([
    {
      component: FormElemType.INPUT,
      label: '姓名',
      name: 'name',
    },
    {
      component: FormElemType.RADIO,
      label: '性别',
      name: 'gender',
      options: [{value: 1, label: '男'}, {value: 2, label: '女'}],
    }
  ])
</script>

<template>
  <SchemaForm
      :form-items="formItems"
      v-model:model="formState"
  />
</template>

按需引入(SchemaTable)🍔

在需要使用 SchemaFormTable 的组件中引入 SchemaTable

<script setup lang="ts">
  import {reactive} from "vue";
  import {ColumnItem} from "schema-table-form";
  import {FormElemType, SchemaTable} from "schema-table-form";

  const columns = reactive<ColumnItem[]>([
    {
      name: 'name',
      label: '姓名',
      component: FormElemType.INPUT
    },
    {
      name: 'age',
      label: '年龄',
      component: FormElemType.INPUT_NUMBER
    }
  ])

  const data = reactive([
    {name: '格子', age: 18},
    {name: '格子大暑版', age: 19},
    {name: '格子惊蛰版', age: 20}
  ])
</script>

<template>
  <SchemaTable
      ref="spriteTableRef"
      :columns="columns"
      :data="data"
  />
</template>

配置 SchemaForm ⛄

FormConfig 🎋

属性名类型说明默认值必填
triggerstring表单触发时机change
rulesFormRules[]表单校验规则-
layoutRecord<string, any>表单布局配置(基于 ElRow & ElCol 组件实现)-
propsRecord<string, any>表单属性用于 ElForm 组件-
emptyTextstringVIEW 模式下空值展示的文本(优先级小于字段属性定义)-

FormItemConfig 🧸

属性名类型说明默认值必填
namestring字段名-
labelstring字段描述-
componentPropFunction<FormElemType | string>字段组件-
modePropFunction组件展示模式-
visiblePropFunction组件隐藏-
rulesPropFunction字段校验(优先级最高)-
requiredPropFunction字段必填(简要必填配置方式)-
optionsPropFunction<Record<string, any>[]>所有选项类型组件的选项数据-
remoteOptionsPropFunction<Promise<Record<string, any>[]>>所有选项类型组件的远程选项数据-
valueKeystring选项值字段-
labelKeystring选项描述字段-
slotstring字段插槽(插槽在 el-form-item 组件里面)-
columnRecord<string, any>字段布局(el-col)-
customSlotstring字段自定义插槽(插槽脱离 el-form-item 组件)-
viewSlotstringVIEW 模式的插槽-
labelSlotstring字段描述插槽-
errorSlotstring段错误提示插槽-
formItemPropsRecord<string, any>字段组件父组件配置( el-form-item)-
propsRecord<string, any>字段组件配置-
itemPropsItemProps字段组件配置子组件配置(比如下拉选择的 el-option、el-radio、el-checkbox 属性、插槽以及其他组件(el-input)的插槽)-
change(data: FormItemChangeParams) => void字段值改变时触发-
format(data: any) => any仅在 VIEW 模式下格式化展示的文本-
emptyTextstringVIEW 模式下为 undefined、null 时展示的默认文本-

配置 SchemaTable 🎉

TableConfig 🐦

属性名类型说明默认值必填
emptyTextstring空值展示的文本(优先级小于列配置定义)-
formPropsRecord<string, any>-
tablePropsRecord<string, any>-
defaultSlotstring-
appendSlotstring-
emptySlotstring-

ColumnItem 🐸

属性名类型说明默认值必填
namestring列字段名-
labelstring列字段描述-
widthstring | number列宽-
rulesPropFunction字段校验(优先级最高)-
customSlotstring字段自定义插槽(插槽脱离 el-form-item 组件)-
slotstring字段插槽(插槽在 el-form-item 组件里面)-
propsRecord<string, any>el-table-column 配置-
formItemPropsRecord<string, any>字段组件父组件配置( el-form-item)-
componentPropFunction<FormElemType | string | false>单元格表单组件(如果返回 false 则不使用表单组件)-
formatPropFunction格式化单元格的值-
change(data: CellChangeParams) => void字段值改变时触发-
optionsPropFunction<Record<string, any>[]>所有选项类型组件的选项数据-
remoteOptionsPropFunction<Promise<Record<string, any>[]>>所有选项类型组件的远程选项数据-
valueKeystring选项值字段-
labelKeystring选项描述字段-
requiredPropFunction字段必填(简要必填配置方式)-
emptyTextstring为 undefined、null 时展示的默认文本-