方便基础业务开发封装的一套组件,基于vue2.5.x和element-ui,可以通过配置自动生成表格展示,表格新增、编辑功能、分页、筛选项、自定义显示表格数据等功能。
先上演示图片
----------------------------------
筛选部分
-----------------------------------------------------------
自定义按钮部分
--------------------------------
表格主体部分
------------
整体效果
以下为代码部分,都比较基础简单,就直接贴代码了
分别有,baseTable,baseDialogForm,customDisplay,filterGroup 4个小组件组成
baseTable部分(表格主体)
1 2374 75 76 307 3084 513 14for="item in topBtnConfig" :key="item.title" :to="item.jumpPage?item.jumpAddress:''"> 6 9 10if="item.jumpPage">{{item.title}} 7else>{{item.title}} 811 更新数据 12table 15 class="baseTable" 16 :data="tableData" 17 border 18 size="small" 19 v-loading="loading" 20 tooltip-effect="dark" 21 ref="table" 22 @selection-change="handleSelectionChange" 23 > 24 if="otherConfig.needSelect"> 25column 26 v-for="(item,index) in tableConfig" 27 :key="index" 28 :prop="item.prop" 29 :label="item.label" 30 :width="item.width?item.width:''" 31 :min-width="item.minWidth?item.minWidth:''" 32 :sortable="item.sortable?true:false" 33 v-if="customDisplayList[index].show" 34 > 35 36 if="item.render" :row="scope.row" :column="item" :index="scope.$index" :render="item.render"> | 37 else>{{scope.row[item.prop]}} 38 39 40if="tableBtnConfig.width" :width="tableBtnConfig.width" fixed="right" class-name="btns"> 41 42 43 55 56 57button 44 @click="handleEmit(item.emitName, scope.row)" 45 v-if="tableBtnConfig.expands && tableBtnConfig.expands.length>0" 46 v-for="(item,index) in tableBtnConfig.expands" 47 :key="index" 48 :type="item.type?item.type:'primary'" 49 >{{item.name}} 50 54if="tableBtnConfig.update&&!tableBtnConfig.isUpdateInNewPage" @click="createOrUpdate(scope.row)">编辑 51else-if="tableBtnConfig.update&&tableBtnConfig.isUpdateInNewPage" @click="goTo(scope.row.id,tableBtnConfig.updateAddress)">编辑 52if="tableBtnConfig.delete" @click.native="deleteItem(scope.row.id)">删除 535862 63 <BaseDialogForm 64 :title="dialogTitle" 65 :width="formWidth" 66 ref="dialogForm" 67 :config="formConfig" 68 :form-data="formModel" 69 :err-form="formError" 70 :is-edit="isEdit" 71 @submit="dialogSubmit" 72 > 73if="otherConfig.needSelect" type="info" @click="toggleSelection(tableData)">全选 59if="otherConfig.needSelect" type="info" @click="batchDelete()">批量删除 6061
customDisplay部分(自定义显示按钮)
1 2318 19 20 60自定义显示 4if="customDisplayShow"> 5176
14 15 16- 当前展示的信息
7- 8
10全选 9- for="(item,index) in list" :key="index"> 11
13{{item.label}} 12
baseDialogForm部分(基于表格的弹出框表单)
1 23 39 40 41 100 1014 33 34 385 32for="(item,index) in config" :key="index"> 6 317 8 30input 9 v-if="item.type === 'text' || item.type === 'password' || item.type === 'textarea'" 10 :type="item.type" 11 v-model="formData[item.prop]" 12 :placeholder="item.placeholder?item.placeholder:'请输入'" 13 > 14 15 if="item.type === 'el-input-number'" v-model="formData[item.prop]" :min="1" :step="1" label="描述文字"> 16 17if="item.type === 'checkbox'" v-model="formData[item.prop]" :placeholder="item.placeholder?item.placeholder:'请选择'"> 18 20 21for="option in item.data" :label="option.id" :key="option.id">{{option.name}} 19if="item.type === 'radio'" v-model="formData[item.prop]" :placeholder="item.placeholder?item.placeholder:'请选择'"> 22 24 25for="option in item.data" :label="option.id" :key="option.id">{{option.name}} 23if="item.type === 'select'" v-model="formData[item.prop]" :placeholder="item.placeholder?item.placeholder:'请选择'"> 26 28for="option in item.data" :key="option.id" :label="option.label" :value="option.id"> 27if="item.type === 'datepicker'" v-model="formData[item.prop]" type="date" :placeholder="item.placeholder?item.placeholder:'请选择日期'"> 29
filterGroup部分(表格上方筛选项集合)
1 2393 94 954 579 806 78if="filterOptions.search"> 7 188 9 17if="search_list[0]"> 1015 else>暂无可搜索项 16支持的搜索条件
1112
14- for="(item, index) in search_list" :key="index">{{item}}
13if="filterOptions.classify"> 19 2320 22for="(item,index) in classifyList" :key="item.value" :label="item.label" :value="item.value"> 21if="filterOptions.year"> 24 2825 27for="(item,index) in years" :key="index" :label="item" :value="item"> 26if="filterOptions.activation"> 29 3330 32for="(item,index) in activationList" :key="index.value" :label="item.label" :value="item.value"> 31if="filterOptions.examine"> 34 3835 37for="(item,index) in examineList" :key="index.value" :label="item.label" :value="item.value"> 36if="filterOptions.operator"> 39 4340 42for="(item,index) in operatorList" :key="index.value" :label="item.label" :value="item.value"> 41if="filterOptions.event"> 44 4845 47for="(item,index) in eventList" :key="index.value" :label="item.label" :value="item.value"> 46if="filterOptions.recommend"> 49 5150 if="filterOptions.date_scope" class="date-filter"> 52 64picker 53 v-model="filterData.date_scope" 54 type="daterange" 55 align="right" 56 unlink-panels 57 range-separator="至" 58 start-placeholder="开始日期" 59 end-placeholder="结束日期" 60 format="yyyy-MM-dd" 61 value-format="yyyy-MM-dd" 62 > 63 if="!sure"> 65 74查 询 66button 67 v-if="open_btn_show" 68 type="primary" 69 plain 70 @click="open = !open;btn_text = !open?'展开':'收起'" 71 :icon="!open?'el-icon-arrow-down':'el-icon-arrow-up'" 72 >{{btn_text}} 73 else> 75 77确 定 76if="filter_arr[0]"> 819282
91- 83 84 检索项: 85
86- for="item in filter_arr" :key="item.key" v-if="item.title"> 87
89{{`${item.title} : ${item.value}`}} 88- if="showClearAllBtn !== false">清空
90
页面调用
1 23 4 <baseTable 5 :theApi="table_ajax" 6 :table-config="configData.tableConfig" 7 :top-btn-config="configData.topBtnConfig" 8 :table-btn-config="configData.tableBtnConfig" 9 :other-config="configData.otherConfig" 10 :filter-config="configData.filterConfig" 11 :grid-edit-width="200" 12 form-title="会员" 13 form-width="40%" 14 :form-config="configData.formConfig" 15 :form-data="configData.formModel" 16 @checkRegistration="checkRegistration" 17 ref="basetable" 18 > 1920 21