queenwuli
2020-12-10 7d2f48fd1cd8cba220f47e59615640bdd413fa28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<template>
    <view class="uni-table-th" :class="{'table--border':border}" :style="{width:width + 'px','text-align':align}">
        <slot></slot>
    </view>
</template>
 
<script>
    /**
     * Th 表头
     * @description 表格内的表头单元格组件
     * @tutorial https://ext.dcloud.net.cn/plugin?id=
     * @property {Number}     width                         单元格宽度
     * @property {Number}     align = [left|center|right]    单元格对齐方式
     * @value left       单元格文字左侧对齐
     * @value center    单元格文字居中
     * @value right        单元格文字右侧对齐
     */
 
    export default {
        name: 'uniTh',
        options: {
            virtualHost: true
        },
        props: {
            width: {
                type: [String, Number],
                default: ''
            },
            align: {
                type: String,
                default: 'left'
            }
        },
        data() {
            return {
                border:false
            };
        },
        created() {
            this.root = this.getTable('uniTable')
            this.rootTr = this.getTable('uniTr')
            this.rootTr.minWidthUpdate(this.width?this.width:140)
            this.border = this.root.border
        },
        methods:{
            /**
             * 获取父元素实例
             */
            getTable(name) {
                let parent = this.$parent;
                let parentName = parent.$options.name;
                while (parentName !== name) {
                    parent = parent.$parent;
                    if (!parent) return false;
                    parentName = parent.$options.name;
                }
                return parent;
            }
        }
    }
</script>
 
<style lang="scss">
    .uni-table-th {
        padding: 12px 10px;
        display: table-cell;
        // text-align: center;
        color: #333;
        font-weight: 500;
        border-bottom: 1px #ddd solid;
        font-size: 14px;
        // background-color: #efefef;
        box-sizing: border-box;
    }
    .table--border {
        border-right: 1px #ddd solid;
    }
</style>