<template>
<div class="table">
<el-row>
<el-table :data="tableData" border @selection-change="handleSelectionChange" :height="screenHeight - height"
align="center" :row-key="rowKey" fit v-bind="$attrs" v-loading="tableLoading">
<el-table-column type="selection" width="50" show-overflow-tooltip v-if="selection">
</el-table-column>
<el-table-column type="index" width="50" show-overflow-tooltip label="序号" :index="handleIndex"
v-if="index">
</el-table-column>
<template v-for="item in columnList">
<el-table-column :prop="item.dataIndex" :label="item.name" :key="item.dataIndex"
:width="item.width || ''" show-overflow-tooltip :fixed="item.fixed"></el-table-column>
</template>
<el-table-column label="操作" :width="actionWidth" show-overflow-tooltip v-if="action" fixed="right">
<template slot-scope="scope">
<div class="stance">
<slot name="action" :scope="scope" />
</div>
</template>
</el-table-column>
</el-table>
</el-row>
<div class="page_bottom">
<el-pagination v-if="pagination" @size-change="handleSizeChange" @current-change="handleCurrentChange"
:current-page="pageOp.currentPage" :page-sizes="[10, 20, 30, 40]" :page-size.sync="pageOp.pageSize"
layout="total, sizes, prev, pager, next, jumper" :total="pageOp.total" background>
</el-pagination>
</div>
</div>
</template>
<script>
export default {
props: {
tableData: {
type: Array,
default: () => [],
},
columnList: {
type: Array,
default: () => [],
},
pageOp: {
type: Object,
default: {
currentPage: 1,
pageSize: 10,
total: 10,
},
},
rowKey: {
type: String,
default: "id",
},
height: {
default: 120,
},
actionWidth: {
default: "100px",
},
screenHeight: {
type: Number,
default: null,
},
selection: Boolean, //是否展示多选列 默认false
pagination: Boolean, //是否展示分页 默认false
needInit: Boolean, // 是否自定义表格高度 默认false
action: Boolean, //是否展示操作列 默认false
index: Boolean, //是否展示序号列 默认false
loading: Boolean, // 表格加载状态
},
methods: {
//多选回调
handleSelectionChange(val) {
this.$emit("handleSelectionChange", val);
},
//handleSizeChange
handleSizeChange(val) {
this.$emit("handleSizeChange", val);
},
handleCurrentChange(val) {
this.$emit("handleCurrentChange", val);
},
handleIndex(index) {
return (this.pageOp.currentPage - 1) * this.pageOp.pageSize + index + 1;
},
//
init() {
this.screenHeight =
document.getElementsByClassName("form-template")[0].clientHeight;
window.onresize = () => {
console.log('变化变化----')
return (() => {
this.screenHeight =
document.getElementsByClassName("form-template")[0].clientHeight;
})();
};
},
},
data() {
return {
// screenHeight: null, //table高度
};
},
computed: {
tableLoading: {
get() {
return this.loading
},
set(val) {
console.log('val', val)
this.$emit('update:loading', val)
}
}
},
mounted() {
//是否需要初始化表格高度
if (this.needInit) {
this.init();
}
},
};
</script>
<style lang="scss" scoped>
.page_bottom {
margin-top: 15px;
width: 100%;
display: flex;
justify-content: flex-end;
}
/* 兼容ie 除了第一个元素都加5的左边距 */
.stance:not(:first-child) {
margin-left: 10px;
}
</style>
import PublicTable from "../../components/common/table/PublicTable.vue";
components: {
PublicTable,
},
<PublicTable :columnList="columnList" :tableData="tableData"
@handleSelectionChange="handleSelectionChange" @handleSizeChange="handleSizeChange"
@handleCurrentChange="handleCurrentChange" :loading.sync="loading" :empty-text="emptyText"
:pageOp="pageOp" selection pagination needInit action index>
<template v-slot:action="scope">
<el-button @click="handleEdit(scope)" type="text" size="small">编辑</el-button>
<el-button @click="handleView(scope)" type="text" size="small">查看</el-button>
</template>
</PublicTable>
columnList: [
{ name: "题干", dataIndex: "longPipelineNumber" },
{ name: "专项类型", dataIndex: "material" },
{ name: "题型", dataIndex: "entrustNumber" },
{ name: "创建人", dataIndex: "heatTreatUnit" },
{ name: "创建时间", dataIndex: "entrustPerson" },
],
tableData: [
{ longPipelineNumber: 'asd' },
], //表格数据