定制开发小程序vue3+ts+element-plus el-table组件二次封装(新增vuepress2文档示例地址)

一、需求

定制开发小程序对于后台管理系统项目定制开发小程序必不可少的列表数据渲染;而的table定制开发小程序组件还是需要写很多代码;定制开发小程序为了方便因此封装了TTable组件(一行代码,定制开发小程序可以实现表格编辑/分页/表格内/定制开发小程序外按钮操作/排序/定制开发小程序显示隐藏表格内操作按钮)

二、组件功能

1、基础表格2、带斑马线、带边框、固定列/表头3、多级表头4、自定义表头5、单个单元格编辑功能6、可以设置表格标题7、可集成了分页组件8、表格可以自定义插槽渲染某列数据9、表格可以render渲染某列数据(支持jsx方式)10、集成了表格内操作和表格外操作
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

三、最终效果

四、参数配置

1、代码示例:

     <t-table          :table="table"          :columns="table.columns"          @size-change="handlesSizeChange"          @page-change="handlesCurrentChange"        />
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

2、events 其他事件按照el-table直接使用(如sort-change排序事件)

事件名说明返回值
page-change当前页码当前选中的页码
save保存按钮编辑后的所有数据
handleEvent单个输入触发事件configEdit 中的 event 值和对应输入的 value 值
radioChange单选选中事件返回当前选中的整行数据

Methods 方法

事件名说明参数
clearSelection用于多选表格,清空用户的选择-
clearSort清空排序条件-
toggleRowSelection取消某一项选中项-

3、配置参数(Table Attributes)

参数说明类型是否必须
table表格数据对象Object
—data展示数据Array
—toolbar表格外操作栏选中表格某行,可以将其数据传出Array
—operator表格内操作栏数据Array
-------show表格内操作栏根据状态显示Object
-------noshow表格内操作栏根据多种状态不显示Array
—operatorConfig表格内操作栏样式Object
—firstColumn表格首列(序号 index,复选框 selection)排列object
—total数据总条数Number
—pageSize页数量Number
—currentPage是否需要显示切换页条数Number
columns表头信息Array
----sort排序 (设置:sort:true)Boolean
----renderHeader列标题 Label 区域渲染使用的 Function(val) 可以用 jsx 方式Function
----bindel-table-column AttributesObject
----noShowTip是否换行 (设置:noShowTip:true)Boolean
----slotName插槽显示此列数据(其值是具名作用域插槽String
----------param具名插槽获取此行数据必须用解构接收{scope}.row是当前行数据 }Object
----canEdit是否开启单元格编辑功能Boolean
----configEdit表格编辑配置(开启编辑功能有效)Object
----------labelplaceholder 显示String
----------editComponent组件名称可直接指定全局注册的组件,也可引入’element/abtd’如:‘a-input/el-input’String
----------bind第三方 UI 的 Attributes,如 el-input 中的 clearable 清空功能Object
----------event触发 handleEvent 事件的标志String
----------type下拉或者复选框显示(select-arr/select-obj/checkbox)String
----------list下拉选择数据源名称String
----------arrLabeltype:select-arr 时对应显示的中文字段String
----------arrKeytype:select-arr 时对应显示的数字字段String
----filters字典过滤Object-
----------listlistTypeInfo 里面对应的下拉数据源命名String-
----------key数据源的 key 字段String‘value’
----------label数据源的 label 字段String‘label’
listTypeInfo下拉选择数据源Object
footer底部操作区(默认隐藏,使用插槽展示“保存”按钮)slot
isShowFooterBtn是否显示保存按钮Boolean
title表格左上标题String /slot
isShowPagination是否显示分页(默认显示分页)Boolean
isTableColumnHidden是否开启合计行隐藏复选框/单选框Boolean
isCopy是否允许双击单元格复制Booleantrue
rowClickRadio是否开启点击整行选中单选框Booleantrue
columnSetting是否显示设置(隐藏/显示列)Booleanfalse
name与 columnSetting 配合使用标记隐藏/显示列唯一性Stringtitle

五、

<template>  <div class="t-table">    <div class="header_wrap">      <div class="header_title">        {{title}}        <slot name="title" />      </div>      <div class="toolbar_top">        <!-- 表格外操作 -->        <slot name="toolbar"></slot>        <!--列设置按钮-->        <div class="header_right_wrap" :style="{marginLeft:isShow('toolbar')?'12px':0}">          <slot name="btn" />          <column-set v-if="columnSetting" v-bind="$attrs" :columns="columns"            @columnSetting="v => state.columnSet = v" />        </div>      </div>    </div>    <el-table ref="TTable" :data="state.tableData" :class="{'highlightCurrentRow':highlightCurrentRow}" v-bind="$attrs"      size="default" :highlight-current-row="highlightCurrentRow" :border="table.border"      :cell-class-name="cellClassNameFuc">      <!-- 复选框 -->      <el-table-column v-if="table.firstColumn.type==='selection'" :type="table.firstColumn.type"        :width="table.firstColumn.width||55" :reserve-selection="table.firstColumn.isPaging||false"        :label="table.firstColumn.label" :align="table.firstColumn.align||'center'" :fixed="table.firstColumn.fixed"        v-bind="$attrs"></el-table-column>      <!-- 序列号 -->      <el-table-column :type="table.firstColumn.type" :width="table.firstColumn.width||55"        :label="table.firstColumn.label||'序列'" :fixed="table.firstColumn.fixed"        :align="table.firstColumn.align||'center'" v-if="table.firstColumn.type==='index'" v-bind="$attrs">        <template #default="scope">          <span>{{isShowPagination?((table.currentPage - 1) * table.pageSize + scope.$index + 1):scope.$index +          1}}</span>        </template>      </el-table-column>      <!-- 主体内容 -->      <template v-for="(item,index) in renderColumns">        <template v-if="!item.children">          <!-- 常规列 -->          <el-table-column v-if="item.isShowCol===false?item.isShowCol:true" :key="index+'i'" :type="item.type"            :label="item.label" :prop="item.prop" :min-width="item['min-width'] || item.minWidth || item.width"            :sortable="item.sort||sortable" :align="item.align || 'center'" :fixed="item.fixed"            :show-overflow-tooltip="item.noShowTip===false?item.noShowTip:true" v-bind="{...item.bind,...$attrs}">            <template #header v-if="item.renderHeader">              <render-header :column="item" :render="item.renderHeader" />            </template>            <template #default="scope">              <!-- render渲染 -->              <template v-if="item.render">                <render-col :column="item" :row="scope.row" :render="item.render" :index="scope.$index" />              </template>              <!-- 自定义插槽 -->              <template v-if="item.slotName">                <slot :name="item.slotName" :scope="scope"></slot>              </template>              <!-- 单个单元格编辑 -->              <template v-if="item.canEdit">                <single-edit-cell :canEdit="item.canEdit" :configEdit="item.configEdit"                  v-model="scope.row[scope.column.property]" :prop="item.prop" :record="scope"                  @handleEvent="handleEvent" v-bind="$attrs" ref="editCell">                  <slot v-if="item.configEdit&&item.configEdit.editSlotName" :name="item.configEdit.editSlotName"                    :scope="scope" />                </single-edit-cell>              </template>              <div v-if="!item.render&&!item.slotName&&!item.canEdit">                <span>{{scope.row[item.prop]}}</span>              </div>            </template>          </el-table-column>        </template>        <!-- 表头合并单元格 -->        <t-table-column v-else :key="index+'m'" :item="item" />      </template>      <slot></slot>      <!-- 操作按钮 -->      <el-table-column v-if="table.operator" :fixed="table.operatorConfig && table.operatorConfig.fixed"        :label="(table.operatorConfig && table.operatorConfig.label) || '操作'"        :min-width="(table.operatorConfig && (table.operatorConfig.width || table.operatorConfig.minWidth)) || 100"        :align="table.operatorConfig && table.operatorConfig.align||'center'" class-name="operator">        <template #default="scope">          <div class="operator_btn" :style="table.operatorConfig && table.operatorConfig.style">            <el-button v-for="(item, index) in table.operator" :key="index"              @click="item.fun&&item.fun(scope.row,scope.$index,state.tableData)" :type="item.type" text              :style="item.style" :icon="item.icon?item.icon:''" :disabled="item.disabled" size="small"              v-show="checkIsShow(scope,item)">              <!-- render渲染 -->              <template v-if="item.render">                <render-col :column="item" :row="scope.row" :render="item.render" :index="scope.$index" />              </template>              <span v-if="!item.render">{{item.text}}</span>            </el-button>          </div>        </template>      </el-table-column>    </el-table>    <!-- 分页器 -->    <el-pagination v-show="(state.tableData && state.tableData.length) && isShowPagination" small      :current-page="table.currentPage" @current-change="handlesCurrentChange" :page-sizes="[10, 20, 50, 100]"      :page-size="table.pageSize" layout="total, prev, pager, next, jumper" :total="table.total" v-bind="$attrs"      background>    </el-pagination>    <!-- 表格底部按钮 -->    <footer class="handle_wrap" v-if="isShowFooterBtn&&(state.tableData&&state.tableData.length>0)">      <slot name="footer" />      <div v-if="!$slots.footer">        <el-button type="primary" @click="save">保存</el-button>      </div>    </footer>  </div></template>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110

六、组件地址

七、相关文章


网站建设定制开发 软件系统开发定制 定制软件开发 软件开发定制 定制app开发 app开发定制 app开发定制公司 电商商城定制开发 定制小程序开发 定制开发小程序 客户管理系统开发定制 定制网站 定制开发 crm开发定制 开发公司 小程序开发定制 定制软件 收款定制开发 企业网站定制开发 定制化开发 android系统定制开发 定制小程序开发费用 定制设计 专注app软件定制开发 软件开发定制定制 知名网站建设定制 软件定制开发供应商 应用系统定制开发 软件系统定制开发 企业管理系统定制开发 系统定制开发