tui-alert.vue
2.64 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
130
131
132
133
134
135
136
137
138
139
140
<template>
<view>
<view class="tui-alert-class tui-alert-box" :class="[show?'tui-alert-show':'']">
<view class="tui-alert-content" :style="{fontSize:size+'rpx',color:color}">
<slot></slot>
</view>
<view class="tui-alert-btn" :style="{color:getColor}" hover-class="tui-alert-btn-hover"
:hover-stay-time="150" @tap.stop="handleClick">{{btnText}}</view>
</view>
<view class="tui-alert-mask" :class="[show?'tui-alert-mask-show':'']" @tap.stop="handleClickCancel"></view>
</view>
</template>
<script>
export default {
name: "tuiAlert",
emits: ['click', 'cancel'],
props: {
//控制显示
show: {
type: Boolean,
default: false
},
//提示信息字体大小
size: {
type: Number,
default: 30
},
//提示信息字体颜色
color: {
type: String,
default: "#333"
},
//按钮字体颜色
btnColor: {
type: String,
default: ""
},
btnText: {
type: String,
default: "确定"
},
//点击遮罩 是否可关闭
maskClosable: {
type: Boolean,
default: false
}
},
computed: {
getColor() {
return this.btnColor || (uni && uni.$tui && uni.$tui.color.danger) || '#EB0909';
}
},
methods: {
handleClick(e) {
if (!this.show) return;
this.$emit('click', {});
},
handleClickCancel() {
if (!this.maskClosable) return;
this.$emit('cancel');
}
}
}
</script>
<style scoped>
.tui-alert-box {
position: fixed;
width: 560rpx;
left: 50%;
top: 50%;
background-color: #fff;
transition: all 0.3s ease-in-out;
transform: translate(-50%, -50%) scale(0);
opacity: 0;
border-radius: 6rpx;
overflow: hidden;
z-index: 1001;
}
.tui-alert-show {
transform: translate(-50%, -50%) scale(1);
opacity: 1;
}
.tui-alert-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
z-index: 999;
transition: all 0.3s ease-in-out;
opacity: 0;
visibility: hidden;
}
.tui-alert-mask-show {
visibility: visible;
opacity: 1;
}
.tui-alert-content {
text-align: center;
color: #333333;
padding: 98rpx 48rpx 92rpx 48rpx;
box-sizing: border-box;
word-break: break-all;
}
.tui-alert-btn {
width: 100%;
height: 90rpx;
display: flex;
align-items: center;
justify-content: center;
background-color: #fff;
box-sizing: border-box;
position: relative;
font-size: 32rpx;
line-height: 32rpx;
}
.tui-alert-btn-hover {
background-color: #f7f7f7;
}
.tui-alert-btn::before {
width: 100%;
content: "";
position: absolute;
border-top: 1rpx solid #E0E0E0;
-webkit-transform: scaleY(0.5);
transform: scaleY(0.5);
left: 0;
top: 0;
}
</style>