Commit 1056858b by ym

table

1 parent 6ede0e77
<!-- 表格+分页 -->
<!-- 表格+分页 v-show="tableShow"-->
<template>
<div class="glsx-table">
<el-table :ref="tableParams.mutiSelectName + 'MutiTable' || 'MutiTable'" :data="getListApi ? data : tableData" :row-key="tableParams.mutiSelectUniqueKey || ''" v-loading="loading" :border="border" :highlight-current-row="true" :stripe="true" @sort-change="sortChange" @selection-change="handleSelect" :size="size" :header-cell-style="headerStyle">
<div class="glsx-table" :class="{'hasTableContent':showClass}">
<el-table id="initTable" :ref="tableParams.mutiSelectName + 'MutiTable' || 'MutiTable'" :data="getListApi ? data : tableData" :row-key="tableParams.mutiSelectUniqueKey || ''" v-loading="loading" :border="border" :height="height" :highlight-current-row="true" :stripe="true" @sort-change="sortChange" @selection-change="handleSelect" :size="size" :header-cell-style="headerStyle">
<el-table-column v-if="tableParams.mutiSelectUniqueKey && tableParams.mutiSelectName" type="selection" width="55" :selectable="checkSelectable" :reserve-selection="true"></el-table-column>
<el-table-column v-if="hasNum" align="center" width="60px" label="序号" type="index" :index="index => index + (page[this.pageConf.pageNum] - 1) * page[this.pageConf.pageSize] + 1"></el-table-column>
<el-table-column v-for="(item, index) in tableColumns" :key="index" :label="item.label" :prop="item.prop" :width="item.width" :min-width="item.minWidth" :align="item.align || 'center'" :sortable="item.sortable">
......@@ -28,7 +28,7 @@
</el-table-column>
<div slot="empty" class="emptyBg">
<img class="noDataImg" :src="noDataImg" v-if="noDataImg" alt="" />
<p>{{ noDataText }}</p>
<div>{{ noDataText }}</div>
<slot name="additionalContent"></slot>
</div>
</el-table>
......@@ -37,14 +37,8 @@
</template>
<script>
import { Table, TableColumn, Pagination } from 'element-ui'
export default {
name: 'GLTable',
components: {
[Table.name]: Table,
[TableColumn.name]: TableColumn,
[Pagination.name]: Pagination
},
name: 'glsx-table',
data() {
return {
loading: false,
......@@ -54,7 +48,9 @@ export default {
total: 10,
// 多选数组
mutiSelectArr: {},
tableColumns: []
tableColumns: [],
showClass:false
}
},
......@@ -63,6 +59,14 @@ export default {
type: String,
default: 'medium'
},
height: {
type: String,
default: ''
},
// maxHeight:{
// type:String,
// default:'3000'
// },
noDataImg: {
type: String,
default: ''
......@@ -183,6 +187,13 @@ export default {
watch: {
customHeadShowList(val) {
this.isCustomHead && this.findShowHeadCol()
},
data:{
immediate:true,
handler(val){
this.showClass=val.length>0 ? true :false;
},
deep:true
}
},
......@@ -192,6 +203,25 @@ export default {
this.page[this.pageConf.pageSize] = 10
this.page[this.pageConf.pageNum] = 1
this.getListApi && this.refreshTable()
this.$nextTick(() => {
var _this=this
setTimeout(() => {
// 使用getListApi获取和返回数组为空时算高度 !(_this.getListApi && _this.data.length==0)
if(_this.getListApi ){
let offsettop = document.getElementById('initTable').offsetTop
console.log('表格距离顶部', offsettop)
let clientHeight = document.body.clientHeight
console.log(clientHeight)
// _this.height=(clientHeight - offsettop - 101)+''
document.getElementById('initTable').style.height= (clientHeight - offsettop - 231)+'px';
}
}, 200)
})
},
methods: {
......@@ -240,6 +270,7 @@ export default {
}
this.getListApi(params)
.then(res => {
console.log(res)
this.data = this.findVal(res, this.tableParams.listName)
this.total = this.findVal(res, this.pageConf.totalCount)
this.loading = false
......@@ -261,6 +292,9 @@ export default {
// 每页条数
handleSizeChange(value) {
let offsettop = document.getElementById('initTable').offsetTop
console.log('表格距离顶部1', offsettop)
this.page[this.pageConf.pageSize] = value
this.getListApi ? this.refreshTable(false, false) : this.$emit('refreshTable', this.page)
},
......@@ -295,13 +329,19 @@ export default {
padding-left: 14px !important;
padding-right: 14px !important;
}
.glsx-table .emptyBg .noDataImg {
.glsx-table .emptyBg {
display: inline-block;
margin-top: 150px;
height: 100%;
}
.glsx-table .emptyBg p {
margin-top: -20px;
.glsx-table .emptyBg div {
margin: -20px 0 10px;
height: 100%;
}
/* .hasTableContent .el-table__body{
height: 100%;
} */
/* .hasTableContent .el-table__body-wrapper{
height: 100%;
} */
</style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!