WXL
4 天以前 9bce51f651aad297ef9eb6df832bfdaf1de05d84
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
<template>
    <view class="u-th" :style="[thStyle]">
        <slot></slot>
    </view>
</template>
 
<script>
    import { props } from './props';
    import { mpMixin } from '../../libs/mixin/mpMixin';
    import { mixin } from '../../libs/mixin/mixin';
    import { addUnit, $parent } from '../../libs/function/index';
    /** 
     * Td 表格中的单元格
     * @description 
     * @tutorial url
     * @property {String | Number} 
     * @event {Function}
     * @example
     */
    export default {
        name: 'u-th',
        mixins: [mpMixin, mixin, props],
        props: {
            // 宽度,百分比或者具体带单位的值,如30%, 200rpx等,一般使用百分比
            width: {
                type: [String],
                default: ''
            }
        },
        data() {
            return {
                thStyle: {}
            }
        },
        created() {
            this.parent = false;
        },
        mounted() {
            this.parent = $parent.call(this, 'u-table');
            if (this.parent) {
                // 将父组件的相关参数,合并到本组件
                let style = {};
                if (this.width) style.flex = `0 0 ${this.width}`;
                style.textAlign = this.parent.align;
                style.padding = this.parent.padding;
                style.borderBottom = `solid 1px ${this.parent.borderColor}`;
                style.borderRight = `solid 1px ${this.parent.borderColor}`;
                Object.assign(style, this.parent.thStyle);
                this.thStyle = style;
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    .u-th {
        @include flex;
        flex-direction: column;
        flex: 1;
        justify-content: center;
        font-size: 28rpx;
        color: $u-main-color;
        font-weight: bold;
        background-color: rgb(245, 246, 248);
    }
</style>