1.0.4 • Published 5 months ago

cus-o-components v1.0.4

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

cus-o-components

基于element-plus二次封装组件,可以通过json形式进行自定义表单配置

使用

安装

npm i cus-o-components

项目中引入

  1. 按需引入
import { CusForm } from 'cus-o-components'
  1. 全局引入
import { createApp } from 'vue'
import App from './App.vue'
import CusOComponents from 'cus-o-components'
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";

createApp(App).use(ElementPlus).use(CusOComponents).mount('#app')

CusForm

表单组件基于element-plusform组件二次封装,可以通过json对表单进行自定义配置,进行动态渲染。

表单相关配置说明

组件属性:CusFormProps(★为必填字段)

字段说明类型默认值
formRef获取form实例(form: InstanceType<typeof ElForm> \|null) => void-
★formList表单项配置内容Array<CompFormItem>[]
modelValue绑定表单数据CusFormModelValue-
cols表单栅格列数number \| GridResponsive1
colGap表单栅格列间距number16
size表单尺寸"large" | "default" | "small""default"
disabled表单是否禁用booleanfalse
editable表单是否可编辑booleantrue
scrollToError校验失败是否自动定位第一个校验失败字段booleantrue
ignoreBtnLabel是否忽略表单按钮组标签宽度booleantrue
btnSpan表单按钮组栅格占比number\|GridResponsive1
btnSpanStyle表单按钮组内联样式string""
submitBtnText提交按钮文字string确定
cancelBtnText取消按钮文字内容string取消
submitBtnProps提交按钮自定义属性Partial<ButtonProps>-
cancelBtnProps取消按钮自定义属性Partial<ButtonProps>-
tooltipProps表单默认提示语自定义样式Partial<TooltipProps>-
hideBtns隐藏表单按钮组booleanfalse
emptyText只读情况下空内容展示占位符string"-"
request表单提交远程请求方法(model: Record\<string, any\>) => Promise\<any\>-

表单配置项:CusFormItem(★为必填字段)

字段说明类型默认值
type表单项类型,text表示纯文本,comp表示组件控件"text" / "comp""comp"
★label表单项标签名string-
★field表单项绑定字段名string-
labelWidth表单字段标签名宽度,默认继承el-form配置string / number-
labelPosition表单字段标签名位置,默认继承el-form配置numberright
customClassform-item样式类string-
controlClass表单控件样式类string-
span表单字段栅格占比number / GridResponsive-
defaultValue默认值any-
tooltip表单字段名后"?"提示string-
tips表单控件下方提示文字内容string-
tipsClass表单控件下方提示文字样式string-
slot表单控件作用域插槽string[field]-control
labelSlot具名插槽string[field]-label
visible表单项是否显示或是字段联动展示配置boolean / FormItemVisibleRule / FormItemVisibleRuleConditiontrue
rules表单字段校验规则Array<FormItemRule>-
modelProp表单字段控件v-model绑定属性名string-
modelEvent表单字段控件v-model绑定事件名string-
props表单控件其他属性配置Record<string, unknown>-
comptype为comp时必填,表单控件组件名string-
childComptype为comp时,表单控件嵌套子组件名stringel-option | el-radio | el-checkbox
options表单的选项组Array<{[labelName]: string, [valueName]: any}>-
labelName表单选项组options字段名stringlabel
valueName表单选项组options字段值stringvalue
controlClass表单控件样式string-
events表单控件事件监听Record<string, Function>-

组件方法:CusFormEmits

字段说明类型
change表单控件字段值发生变化时触发(field: string, value: any, model: MaybeRef<ReFormModelValue>) => void
update:modelValue表单数据更新后触发(model: MaybeRef<CusFormModelValue>): void
submit点击默认提交按钮触发(formData: CusFormModelValue): void
cancel点击默认取消按钮触发void
success/error在表单提交远程请求方法request时触发(res: any) => void

组件插槽配置

插槽名说明
btns自定义表单按钮组(如果使用此插槽默认的提交和取消按钮不会展示,需要自定义完成)
field-label每个表单配置项都自带一个标签插槽,默认按 [field]-label 格式提供,可通过 labelSlot 自定义插槽名
field-control每个表单配置项都自带一个控件插槽,默认按 [field]-control 格式提供,可通过 slot 自定义插槽名

CusForm 暴露在外部的方法

字段说明类型
submiting表单提交状态boolean
thisFormRefElForm组件示例InstanceType<typeof ElForm>
formData表单数据对象ShallowRef<Record<string, any>>
formRules表单校验规则集合ShallowRef<Partial<FormRules>>
formItem表单配置对象集合ShallowRef<CusFormItem[]>
formVisible表单字段显示状态集合Ref<Record<string, boolean>>
validate同ElForm,校验表单(callback: FormValidateCallback) => void
clearValidate同ElForm,清除表单校验状态() => void
resetFields同ElForm,重置表单字段和校验状态(props?: Arrayable\<string\> | undefined) => void
1.0.4

5 months ago

1.0.3

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago