xuruiqian
2025-06-04 17ce21955b4e3402d3d5868b52e50bfdd55bc572
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
<template>
    <view class="use-totop fixed-top animated" @tap.stop="totop" :class="{ 'fade-in': visible, 'dn': !visible, 'margin-b-50': type == 'tabbar', 'safe-area-inset-bottom-plus': safeAreaInsetBottom }"
        :style="{ bottom: bottom + 'rpx', right: right + 'rpx' }">
        <text class="iconfont iconzhiding"></text>
    </view>
</template>
 
<script>
    export default {
        props: {
            top: {
                type: Number,
                default: 100
            },
            right: {
                type: String,
                default: '30'
            },
            bottom: {
                type: String,
                default: '30'
            },
            duration: {
                type: Number,
                default: 120
            },
            scrollTop: {
                type: Number,
                default: 0
            },
            type: {
                type: String,
                default: 'normal'
            },
            safeAreaInsetBottom: {
                type: Boolean,
                default: false
            }
        },
        watch: {
            scrollTop(nv, ov) {
                this.s_top = nv;
                this.change();
            }
        },
        data() {
            return {
                s_top: 0,
                visible: false
            };
        },
        methods: {
            totop() {
                uni.pageScrollTo({
                    scrollTop: 0,
                    duration: this.duration
                })
 
                this.$emit('to', {
                    type: 'to',
                    scrollTop: this.s_top
                });
            },
            change(scrollTop) {
                this.s_top = scrollTop;
                if (this.s_top > this.top) {
                    if (!this.visible) this.visible = true;
                } else {
                    if (this.visible) this.visible = false;
                }
            }
        }
    }
</script>
 
<style lang="scss">
    .use-totop {}
    
    .margin-b-50 {
        /* #ifdef H5 */
        margin-bottom: calc(env(safe-area-inset-bottom) + 50px);
        /* #endif */
    }
</style>