Commit 1056858b by ym

table

1 parent 6ede0e77
<!-- 表格+分页 --> <!-- 表格+分页 v-show="tableShow"-->
<template> <template>
<div class="glsx-table"> <div class="glsx-table" :class="{'hasTableContent':showClass}">
<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"> <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="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-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"> <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 @@ ...@@ -28,7 +28,7 @@
</el-table-column> </el-table-column>
<div slot="empty" class="emptyBg"> <div slot="empty" class="emptyBg">
<img class="noDataImg" :src="noDataImg" v-if="noDataImg" alt="" /> <img class="noDataImg" :src="noDataImg" v-if="noDataImg" alt="" />
<p>{{ noDataText }}</p> <div>{{ noDataText }}</div>
<slot name="additionalContent"></slot> <slot name="additionalContent"></slot>
</div> </div>
</el-table> </el-table>
...@@ -37,14 +37,8 @@ ...@@ -37,14 +37,8 @@
</template> </template>
<script> <script>
import { Table, TableColumn, Pagination } from 'element-ui'
export default { export default {
name: 'GLTable', name: 'glsx-table',
components: {
[Table.name]: Table,
[TableColumn.name]: TableColumn,
[Pagination.name]: Pagination
},
data() { data() {
return { return {
loading: false, loading: false,
...@@ -54,7 +48,9 @@ export default { ...@@ -54,7 +48,9 @@ export default {
total: 10, total: 10,
// 多选数组 // 多选数组
mutiSelectArr: {}, mutiSelectArr: {},
tableColumns: [] tableColumns: [],
showClass:false
} }
}, },
...@@ -63,6 +59,14 @@ export default { ...@@ -63,6 +59,14 @@ export default {
type: String, type: String,
default: 'medium' default: 'medium'
}, },
height: {
type: String,
default: ''
},
// maxHeight:{
// type:String,
// default:'3000'
// },
noDataImg: { noDataImg: {
type: String, type: String,
default: '' default: ''
...@@ -183,6 +187,13 @@ export default { ...@@ -183,6 +187,13 @@ export default {
watch: { watch: {
customHeadShowList(val) { customHeadShowList(val) {
this.isCustomHead && this.findShowHeadCol() this.isCustomHead && this.findShowHeadCol()
},
data:{
immediate:true,
handler(val){
this.showClass=val.length>0 ? true :false;
},
deep:true
} }
}, },
...@@ -192,6 +203,25 @@ export default { ...@@ -192,6 +203,25 @@ export default {
this.page[this.pageConf.pageSize] = 10 this.page[this.pageConf.pageSize] = 10
this.page[this.pageConf.pageNum] = 1 this.page[this.pageConf.pageNum] = 1
this.getListApi && this.refreshTable() 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: { methods: {
...@@ -240,6 +270,7 @@ export default { ...@@ -240,6 +270,7 @@ export default {
} }
this.getListApi(params) this.getListApi(params)
.then(res => { .then(res => {
console.log(res)
this.data = this.findVal(res, this.tableParams.listName) this.data = this.findVal(res, this.tableParams.listName)
this.total = this.findVal(res, this.pageConf.totalCount) this.total = this.findVal(res, this.pageConf.totalCount)
this.loading = false this.loading = false
...@@ -261,6 +292,9 @@ export default { ...@@ -261,6 +292,9 @@ export default {
// 每页条数 // 每页条数
handleSizeChange(value) { handleSizeChange(value) {
let offsettop = document.getElementById('initTable').offsetTop
console.log('表格距离顶部1', offsettop)
this.page[this.pageConf.pageSize] = value this.page[this.pageConf.pageSize] = value
this.getListApi ? this.refreshTable(false, false) : this.$emit('refreshTable', this.page) this.getListApi ? this.refreshTable(false, false) : this.$emit('refreshTable', this.page)
}, },
...@@ -295,13 +329,19 @@ export default { ...@@ -295,13 +329,19 @@ export default {
padding-left: 14px !important; padding-left: 14px !important;
padding-right: 14px !important; padding-right: 14px !important;
} }
.glsx-table .emptyBg .noDataImg { .glsx-table .emptyBg {
display: inline-block; display: inline-block;
margin-top: 150px; margin-top: 150px;
height: 100%; height: 100%;
} }
.glsx-table .emptyBg p { .glsx-table .emptyBg div {
margin-top: -20px; margin: -20px 0 10px;
height: 100%; height: 100%;
} }
/* .hasTableContent .el-table__body{
height: 100%;
} */
/* .hasTableContent .el-table__body-wrapper{
height: 100%;
} */
</style> </style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!