zhangwei
2024-08-14 9d8994790fe403935ed46ad478f83ae110bb7a01
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<template>
    <!--本文件由FirstUI授权予四川政采招投标咨询有限公司(会员ID:1 6 3,营业执照号: 9  15 1  0  13  13  3 2 0 06 193 K)专用,请尊重知识产权,勿私下传播,违者追究法律责任。-->
    <view class="fui-vtabs-content__wrap" ref="fui_vtabs__el" :id="'fui-vtabs-content__'+tabIndex">
        <slot></slot>
    </view>
</template>
 
<script>
    // #ifdef APP-NVUE
    const dom = weex.requireModule('dom')
    // #endif
    export default {
        name: "fui-vtabs-content",
        inject: ['vtabs'],
        props: {
            tabIndex: {
                type: [Number, String],
                default: 0
            }
        },
        mounted() {
            if (this.vtabs && this.vtabs.linkage) {
                this.vtabs.children.push(this)
                this.$nextTick(()=>{
                    setTimeout(() => {
                        this.calcHeight((height) => {
                            this.vtabs.getCalcHeight(height, Number(this.tabIndex))
                        })
                    }, 300)
                })
            }
        },
        // #ifndef VUE3
        // TODO vue2
        beforeDestroy() {
            this.uninstall()
        },
        // #endif
        // #ifdef VUE3
        // TODO vue3
        beforeUnmount() {
            this.uninstall()
        },
        // #endif
        methods: {
            calcHeight(callback, index = 0) {
                // #ifdef APP-NVUE
                const result = dom.getComponentRect(this.$refs['fui_vtabs__el'], option => {
                    if (option && option.result && option.size) {
                        callback && callback(option.size.height + 1)
                    }
                })
                // #endif
 
                // #ifndef APP-NVUE
                uni.createSelectorQuery()
                    // #ifndef MP-ALIPAY
                    .in(this)
                    // #endif
                    .select(`#fui-vtabs-content__${this.tabIndex}`)
                    .fields({
                        size: true
                    }, data => {
                        if (index >= 12) return
                        if (data && data.height) {
                            callback && callback(data.height)
                        } else {
                            index++
                            setTimeout(() => {
                                this.calcHeight(callback, index)
                            }, 50)
                            return
                        }
                    })
                    .exec()
                // #endif
            },
            uninstall() {
                if (this.vtabs && this.vtabs.linkage) {
                    this.vtabs.uninstall(Number(this.tabIndex),this)
                }
            }
        }
    }
</script>
 
<style scoped>
    .fui-vtabs-content__wrap {
        /* #ifdef APP-NVUE */
        flex: 1;
        /* #endif */
        /* #ifndef APP-NVUE */
        width: 100%;
        /* #endif */
    }
</style>