element表格封装(直接使用)

<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' },

            ], //表格数据

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值