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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
| <template>
| <!--本文件由FirstUI授权予四川政采招投标咨询有限公司(会员ID: 1 63,营业执照号: 9 1 5 10131 3 3 2006 19 3 K)专用,请尊重知识产权,勿私下传播,违者追究法律责任。-->
| <view class="fui-backtop__wrap"
| :style="{width:width+'rpx',height:width+'rpx',borderRadius:isNvue?width+'rpx':'50%' ,bottom: bottom + 'rpx', right: right + 'rpx',background:background }"
| v-if="isShow && visible" @tap.stop="goBacktop">
| <fui-icon :name="name" :size="52" :color="color" v-if="!custom"></fui-icon>
| <slot></slot>
| </view>
| </template>
|
| <script>
| // #ifdef APP-NVUE
| const dom = weex.requireModule('dom')
| // #endif
| //非easycom模式取消注释引入字体组件,按实际路径进行调整
| // import fuiIcon from "@/components/firstui/fui-icon/fui-icon.vue"
| export default {
| name: "fui-backtop",
| emits: ['click'],
| // components:{
| // fuiIcon
| // },
| props: {
| scrollTop: {
| type: [Number, String]
| },
| targetRef: {
| type: [String, Object],
| default () {
| return {}
| }
| },
| threshold: {
| type: [Number, String],
| default: 320
| },
| width: {
| type: [Number, String],
| default: 80
| },
| bottom: {
| type: [Number, String],
| default: 160
| },
| right: {
| type: [Number, String],
| default: 40
| },
| background: {
| type: String,
| default: '#FFFFFF'
| },
| name: {
| type: String,
| default: 'top'
| },
| color: {
| type: String,
| default: '#333333'
| },
| custom: {
| type: Boolean,
| default: false
| }
| },
| watch: {
| scrollTop(newValue, oldValue) {
| this.scrollChange();
| }
| },
| data() {
| let isNvue = false;
| // #ifdef APP-NVUE
| isNvue = true;
| // #endif
| return {
| isNvue: isNvue,
| isShow: false,
| visible: true
| };
| },
| methods: {
| goBacktop: function() {
| // #ifndef APP-NVUE
| //防止fixed元素先消失再显示
| this.visible = false;
| uni.pageScrollTo({
| scrollTop: 0,
| duration: 120
| });
| setTimeout(() => {
| this.visible = true;
| }, 220);
| // #endif
|
| // #ifdef APP-NVUE
| if (this.targetRef) {
| dom.scrollToElement(this.targetRef, {});
| }
| // #endif
| this.$emit('click', {})
| },
| scrollChange() {
| let show = this.scrollTop > this.threshold;
| if ((show && this.isShow) || (!show && !this.isShow)) return;
| this.isShow = show;
| }
| }
| }
| </script>
|
| <style scoped>
| .fui-backtop__wrap {
| /* #ifndef APP-NVUE */
| display: flex;
| /* #endif */
| position: fixed;
| z-index: 888;
| /* #ifndef APP-NVUE */
| box-shadow: 0 0 6px rgb(0 0 0 / 12%);
| /* #endif */
|
| /* #ifdef APP-NVUE */
| box-shadow: 0 0 6px rgba(0, 0, 0, 0.1);
| /* #endif */
| justify-content: center;
| align-items: center;
| /* #ifdef H5 */
| cursor: pointer;
| /* #endif */
| }
| </style>
|
|