tui-tips.vue
2.58 KB
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
<template>
<block v-if="position == 'top'">
<view class="tui-tips-class tui-toptips" :style="{backgroundColor:backgroundColor,color:color,fontSize:size+'rpx'}" :class="[show ? 'tui-top-show' : '']">{{ msg }}</view>
</block>
<block v-else>
<view class="tui-tips-class tui-toast" :class="[position == 'center' ? 'tui-centertips' : 'tui-bottomtips', show ? 'tui-toast-show' : '']">
<view class="tui-tips-content" :style="{backgroundColor:backgroundColor,color:color,fontSize:size+'rpx'}">{{ msg }}</view>
</view>
</block>
</template>
<script>
export default {
name: 'tuiTips',
props: {
//top bottom center
position: {
type: String,
default: 'top'
},
backgroundColor: {
type: String,
default: 'rgba(0, 0, 0, 0.7)'
},
color: {
type: String,
default: '#fff'
},
size: {
type: Number,
default: 30
}
},
data() {
return {
timer: null,
show: false,
msg: '无法连接到服务器~'
};
},
methods: {
showTips: function(options) {
const {duration = 2000 } = options;
clearTimeout(this.timer);
this.show = true;
// this.duration = duration < 2000 ? 2000 : duration;
this.msg = options.msg;
this.timer = setTimeout(() => {
this.show = false;
clearTimeout(this.timer);
this.timer = null;
}, duration);
}
}
};
</script>
<style scoped>
/*顶部消息提醒 start*/
.tui-toptips {
width: 100%;
padding: 18rpx 30rpx;
box-sizing: border-box;
position: fixed;
z-index: 9999;
left: 0;
top: 0;
display: flex;
align-items: center;
justify-content: center;
word-break: break-all;
opacity: 0;
transform: translateZ(0) translateY(-100%);
transition: all 0.3s ease-in-out;
}
.tui-top-show {
transform: translateZ(0) translateY(0);
opacity: 1;
}
/*顶部消息提醒 end*/
/*toast消息提醒 start*/
/*注意问题:
1、fixed 元素宽度无法自适应,所以增加了子元素
2、fixed 和 display冲突导致动画效果消失,暂时使用visibility替代
*/
.tui-toast {
width: 80%;
box-sizing: border-box;
color: #fff;
font-size: 28rpx;
position: fixed;
visibility: hidden;
opacity: 0;
left: 50%;
transition: all 0.3s ease-in-out;
z-index: 9999;
display: flex;
align-items: center;
justify-content: center;
}
.tui-toast-show {
visibility: visible;
opacity: 1;
}
.tui-tips-content {
word-wrap: break-word;
word-break: break-all;
border-radius: 8rpx;
padding: 18rpx 30rpx;
}
.tui-bottomtips {
bottom: 120rpx;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
}
.tui-centertips {
top: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
</style>