1.1.3--beta.11 • Published 2 years ago

common-element-ui v1.1.3--beta.11

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

common-element-ui

安装

组件依赖element-plus组件库,需要先安装element-plus

npm install element-plus

然后安装本组件库

npm install common-element-ui

使用

// main.ts
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'

import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'

import commonElementUi from 'common-element-ui'
import 'common-element-ui/common-ui.css'

createApp(App).use(router).use(ElementPlus).use(commonElementUi).mount('#app')

common-ui.css

common-ui.css集成了一些基本样式,包括组件库的全局样式和一些常用变量,例如fs--12到fs—50代表font-size的样式,相同的还有mg-t—数字,mg-t/r/l/b/x/y—数字,pd-t/r/l/b/x/y—数字

样式名说明例子
mg-t/r/l/b—数字控制margin的原子样式名,范围是0px~200px, 间隔是5px。mg-l—5,mg-r—10
pd-t/r/l/b—数字控制padding的原子样式名,范围是0px~200px, 间隔是5px。pd-l—5,pd-r—20
fs—数字控制font-size的原子样式名,范围是12px~50px, 间隔是1px。fs—15, fs—16
field-required-after字段必填小红点(后)
field-required-before字段必填小红点(前)

WidgetItem

prop

declare type WidgetItemType = {
  widgetType?: string,
  prop: string,
  formatter?: Function,
  [propName: string]: any
}

const props = defineProps({
  widgetConfig: {
    type: Object as PropType<WidgetItemType>,
    required: true
  },
  widgetData: {
    type: Object,
    required: true
  },
  scopeData: {
    type: Object,
    default: {}
  }
})

widgetType是组件的基本配置

属性说明类型可选值默认值
widgetType小组件的类型stringinput/date/Select/allCheck/buttons/switch,详情可查看widgetType—,默认为text文本组件
propwidgetData中的属性名string
formatter格式化text组件的数据,可接收一个html片段function:(value,widgetData,widgetConfig) ⇒ string不传则默认显示widgetDatapropwidgetDataprop

widgetData是组件的数据,是一个Object

scopeData是一个预留属性,在table中是column插槽的scope字段

widgetType基本是对element-plus的二次封装,也有自己写的组件

可选值说明额外属性
input属性继承el-input`
date属性继承el-date
Select对el-select的二次封装,属性继承el-select。1. 选项为对象数组时,指定labelKey和valueKey,默认为label和value。2. 属性completeValue为true则获取整个object为value。3. list,el-options的选项数据,数组类型
allCheck对el-checkbox的二次封装。属性继承el-checkbox1. showAllCheck:是否显示全选。Boolean值,默认值为true。2. options: 选项数组。3. 选项为对象数组时,指定labelKey和valueKey,默认为label和value。
buttons对el-button的二次封装。每个button的属性继承于el-button1. buttonsList:对象数组,每个对象代表一个按钮配置。下面是对象的属性。2. label: 按钮的名字。3. func:按钮的点击事件,参数是widgetData。4. controller:控制按钮配置的函数,返回值为Boolean值,意味着显示或隐藏。参数是(btn,widgetData),当前按钮的配置信息和数据
switch对el-switch的二次封装,属性继承el-switch
test/不传widgetType文本标签1. click:文本被点击触发,click(value,widgetData)。2. formatter: 文本格式化函数,返回值为string或者html字符串,参数→ formatter:(value,widgetData,widgetConfig)⇒string

CommonTable

对el-table的二次封装,集合了分页

declare type TableConfigType = {
  // 表格数据
  data: Array<DefaultObjectType>,
  // 表格头的按钮
  btnConfig?: DefaultObjectType,
  // 表格分页数据
  paginationConfig?: paginationConfigType,
  render?: Function
} & DefaultObjectType

declare type ColumnConfigType = {
  // 表格头配置数据
  columnList?: Array<ColumnListType>,
  // 格式化表格数据函数
  formatData?: Function,
  // 表格内的按钮
} & DefaultObjectType

declare type PaginationConfigType = {
  page: number,
  limit: number,
  total: number
} & DefaultObjectType

const props = defineProps({
  render: {
    type: Function,
  },
  tableConfig: {
    type: Object as PropType<TableConfigType>,
    default: () => ({}),
  },
  columnConfig: {
    type: Object as PropType<ColumnConfigType>,
    default: {}
  },
  paginationConfig: {
    type: Object as PropType<PaginationConfigType>,
    default: () => ({}),
  },
})

prop

render

获取表格数据的函数,在分页改变的时候会触发

tableConfig

属性说明类型默认值
data表格数据array[]
isCardBlock是否有卡片风格背景booleantrue
showPageBar是否显示分页booleantrue
paginationConfig分页配置信息,详情查看PaginationConfigTypePaginationConfigType

columnConfig

详情查看Column组件

paginationConfig

PaginationConfigType:

属性说明类型默认值
page当前页number1
limit每页条数number10
total数据总条数number0

Column

对el-column的二次封装

declare type ColumnListType = {
  // 标题的文字
  label: string;
  // 标题是否有必填样式
  required?: Boolean,
  // 控制表格列的函数
  controller?: ColumnControllerType,
  // 表格内按钮配置
  buttonsList?: Array<ColumnBtnsType>,
  // 多级表头
  headerChildren?: Array<ColumnListType>
  [propName: string]: any,
} & WidgetItemType

declare type ColumnControllerType = (config: ColumnListType) => Boolean

declare type ColumnBtnsType = {
  label: string,
  func: Function,
  [propName: string]: any,
}

const props = defineProps({
  columnList: {
    type: Array as PropType<ColumnListType[]>,
    default: []
  },
  formatData: {
    type: Function
  },
})

prop

columnList: ColumnListType & WidgetItemType

属性说明类型默认值
label标题的文字string
required标题是否有必填样式booleanfalse
controller控制表格列的函数ColumnControllerTypetrue
buttonsList表格内按钮配置ColumnBtnsType
headerChildren多级表头ColumnListType
cellSlot该列是否显示插槽Booleanfalse

formatData

暂时舍弃

插槽

插槽名说明
cellSlot配合ColumnListType 中的cellSlot使用,当其为true是显示这个插槽里面的内容
title列头的插槽,当使用这个插槽时显示里面的内容

FormTable

利用原生table和el-form进行二次封装

declare type FormItemType = {
  label: string,
  // 控制FormItem的函数
  controller?: ControllerType,
  // 是否插入td插槽
  tdSlot?: boolean,
  // 是否插入formItem插槽
  itemSlot?: boolean,
  // 合并列
  colspan?: number,
	// 是否显示必填样式
  required?: boolean,
  [propName: string]: any,
} & WidgetItemType

declare type FormListType = Array<FormItemType[]>

declare type FormConfigType = {
  // 分配每一列的宽度
  col?: string[],
  // formItem,二维数组
  formList: FormListType,
  // form表单数据
  formData: DefaultObjectType,
  [propName: string]: any,
} & DefaultObjectType

const props = defineProps({
  col: {
    type: Array as PropType<string[]>,
    default: ['30%','70%']
  },
  formData: {
    type: Object,
    default: {}
  },
  formList: {
    type: Array as PropType<FormListType>,
    default: []
  },
  formatData: {
    type: Function
  }
})

prop

col

字符串数组,一项表示一列的宽度,分配每一列的宽度。eg:'20%', '30%', '20%', '30%'

formData

表单数据对象

formList

FormItemType类型的二维数组

详情查看FormItem组件

formatData

暂弃

FormItem

对el-form-item的二次封装

declare type FormItemType = {
  label: string,
  // 控制FormItem的函数
  controller?: ControllerType,
  // 是否插入td插槽
  tdSlot?: boolean,
  // 是否插入formItem插槽
  itemSlot?: boolean,
  // 合并列
  colspan?: number,
	// 是否显示必填样式
  required?: boolean,
  [propName: string]: any,
} & WidgetItemType

declare type ControllerType = (value: any, data: any, config: FormItemType) => Boolean

const props = defineProps({
  formItem: {
    type: Array as PropType<FormItemType[]>,
    default: []
  },
  formData: {
    type: Object,
    default: {}
  },
  formatData: {
    type: Function
  }
})

prop

formItem:FormItemType & WidgetItemType

属性说明类型默认值
label表单项文本string
required是否显示必填样式、或者传入rulesBooleanfalse
controller控制FormItem的函数,返回一个Boolean值表示是否显示ControllerTypetrue
colspan合并列number1
itemSlot是否插入formItem插槽Booleanfalse
tdSlot是否插入td插槽booleanfalse
rules校验数据Object

插槽

插槽名说明
itemSlot配合formItem.itemSlot使用,在td内部插入插槽
tdSlot配合formItem.tdSlot使用,替换整个td的插槽

MDialog

declare type DialogConfigType = {
  title: string;
  isShowFooter?: boolean,
  isShowConfirm?: boolean,
  headerClass?: string,
} & DefaultObjectType

const props = defineProps({
  modelValue: {
    type: Boolean,
    default: false,
  },
  dialogConfig: {
    type: Object as PropType<DialogConfigType>,
    default: () => ({}),
  },
  nativeConfig: {
    type: Object,
    default: {}
  }
})

prop

属性说明类型默认值
modelValue控制弹框显示或隐藏Booleanfalse
nativeConfig可填入el-dialog的属性值Object{}
dialogConfig组件的额外属性。1. title: 弹框的标题。2. headerClass:标题的样式名。3. isShowConfirm:是否显示确定按钮。4. isShowFooter:是否显示底部按钮。Object{}

插槽

插槽名说明
header标题的插槽,不包括关闭按钮
footer底部按钮的插槽。

SearchForm

查询条件表单,利用el-col做不同分辨率的响应式

// SearchForm,继承WidgetItemType
declare type SearchItemType = {
  label: string;
  prop: string;
  span?: string;
  class?: string;
  labelWidth: string | number;
} & WidgetItemType

const props = defineProps({
  isInline: {
    type: Boolean,
    default: true,
  },
  // 表达对象
  formData: {
    type: Object,
    default: () => ({}),
  },
  // 表单校验对象
  formRules: {
    type: Object,
    default: () => ({}),
  },
  // labe默认长度
  labelWidth: {
    type: String,
    default: '120px', // 120px
  },
  // 表单列表
  formList: {
    type: Array as PropType<SearchItemType[]>,
    default: () => [],
    // default: [],
  },
  size: {
    type: Object,
    default: {
      sm: 24,
      md: {},
      lg: 12,
      xl: 8,
      xs: {},
    },
  },
  gutter: {
    type: Number,
    default: 130,
  },
})

prop

属性说明类型默认值
formList搜索项的配置信息,和widget配置一样SearchItemType[][]
formData数据对象Object{}
sizeel-col的配置项Object{ sm: 24, md: {}, lg: 12, xl: 8, xs: {}, }
gutterel-row属性Number130
formRules搜索项的数据校验,也是el-form的rules属性Array[]

插槽

插槽名说明
searchBtn按钮位置的插槽,默认在右边
1.1.3--beta.11

2 years ago

1.1.3--beta.10

2 years ago

1.1.3--beta.9

2 years ago

1.1.3--beta.8

2 years ago

1.1.3--beta.6

2 years ago

1.1.3--beta.5

2 years ago

1.1.3--beta.4

2 years ago

1.1.3--beta.3

2 years ago

1.1.3--beta.2

2 years ago

1.1.3--beta.1

2 years ago

1.1.3--beta

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago