uni-table 改造源码 添加固定表头功能 附件修改后源码

github地址:https://github.com/1205093639/uni-table-Fixed_header
实现效果:

1.先找到源码 复制出来单独封装成自己的组件

组件源码位置

2.修改

2.1 uni-table

无需改动

2.2 uni-tbody

在这里插入图片描述

<template>
    <!-- #ifdef H5 -->
    <tbody class="uni-tbody" :style="{'max-height':height}">
        <slot></slot>
    </tbody>
    <!-- #endif -->
    <!-- #ifndef H5 -->
    <view class="uni-tbody" :style="{'max-height':height}">
        <slot></slot>
    </view>
    <!-- #endif -->
</template>

<script>
export default {
   
    name: 'uniBody',
    props: ['height'],
    options: {
   
        virtualHost: true
    },
    data() {
   
        return {
   

        }
    },
    created() {
    },
    methods: {
   }
}
</script>

<style>
.uni-tbody {
   
    display: block;
    width: 100%;
    overflow: auto;
}
</style>

2.3 uni-table-td

<template>
    <!-- #ifdef H5 -->
    <td class="uni-table-td" :rowspan="rowspan" :colspan="colspan" :class="{'table--border':border}" :style="{'max-width':width + 'px','text-align':align}">
        <slot></slot>
    </td>
    <!-- #endif -->
    <!-- #ifndef H5 -->
    <!-- :class="{'table--border':border}"  -->
    <view class="uni-table-td" :class="{'table--border':border}" :style="{'max-width':width + 'px','text-align':align}">
        <slot></slot>
    </view>
    <!-- #endif -->
</template>

<script>
/**
 * Td 单元格
 * @description 表格中的标准单元格组件
 * @tutorial https://ext.dcloud.net.cn/plugin?id=3270
 * @property {Number} 	align = [left|center|right]	单元格对齐方式
 */
export default {
   
    name: 'uniTd',
    options: {
   
        virtualHost: true
    },
    props: {
   
        width: {
   
            type: [String, Number],
            default: ''
        },
        align: {
   
            type: String,
            default: 'left'
        },
        rowspan: {
   
            type: [Number, String],
            default: 1
        },
        colspan: {
   
            type: [Number, String],
            default: 1
        }
    },
    data() {
   
        return {
   
            border: false
        };
    },
    created() {
   
        this.root = this.getTable()
        this.border = this.root.border
    },
    methods: {
   
        /**
         * 获取父元素实例
         */
        getTable() {
   
            let parent = this.$parent;
            let parentName = parent.$options.name;
            while (parentName !== 'uniTable') {
   
                parent = parent.$parent;
                if (!parent) return false;
                parentName = parent.$options.name;
            }
            return parent;
        },
    }
}
</script>

<style lang="scss">
$border-color: #ebeef5;

.uni-table-td {
   
    display: table-cell;
    padding: 8px 10px;
    font-size: 14px;
    border-bottom: 1px $border-color solid;
    font-weight: 400;
    color: #606266;
    line-height: 23px;
    box-sizing: border-box;
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    word-break: break-all;
    word-wrap: break-word;
}
.table--border {
   
    border-right: 1px $border-color solid;
}
</style>

2.4 uni-table-th

<template>
    <!-- #ifdef H5 -->
    <th :rowspan="rowspan" :colspan="colspan" class="uni-table-th" :class="{ 'table--border': border }" :style="{ 'max-width': width + 'px', 'text-align': align }">
        <view class="uni-table-th-row">
            <view class="uni-table-th-content" :style="{ 'justify-content': contentAlign }" @click="sort">
                <slot></slot>
                <view v-if="sortable" class="arrow-box">
                    <text class="arrow up" :class="{ active: ascending }" @click.stop="ascendingFn"
  • 11
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 11
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值