Blame view

components/thorui/tui-toast/tui-toast.vue 2.46 KB
46b6767c   刘淇   init 提交到库
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
  <template>
  	<view class="tui-toast" :class="[visible?'tui-toast-show':'',content?'tui-toast-padding':'',icon?'':'tui-unicon-padding']" :style="{width:getWidth(icon,content),zIndex:zIndex}">
  		<image :src="imgUrl" class="tui-toast-img" v-if="icon"></image>
  		<view class="tui-toast-text" :class="[icon?'':'tui-unicon']">{{title}}</view>
  		<view class="tui-toast-text tui-content-ptop" v-if="content && icon">{{content}}</view>
  	</view>
  </template>
  
  <script>
  	export default {
  		name: "tuiToast",
  		props: {
  			zIndex:{
  				type:Number,
  				default:99999
  			}
  		},
  		data() {
  			return {
  				timer: null,
  				//是否显示
  				visible: false,
  				//显示标题
  				title: "操作成功",
  				//显示内容
  				content: "",
  				//是否有icon
  				icon:false,
  				imgUrl:""
  			};
  		},
  		methods: {
  			show: function(options) {
  				let {
  					duration = 2000,
  					icon=false
  				} = options;
  				clearTimeout(this.timer);
  				this.visible = true;
  				this.title = options.title || "";
  				this.content = options.content || "";
  				this.icon=icon;
  				if(icon && options.imgUrl){
  					this.imgUrl=options.imgUrl
  				}
  				this.timer = setTimeout(() => {
  					this.visible = false;
  					clearTimeout(this.timer);
  					this.timer = null;
  				}, duration);
  			},
  			getWidth(icon,content){
  				let width="auto";
  				if(icon){
  					width=content?'420rpx':'360rpx'
  				}
  				return width
  			}
  		}
  	}
  </script>
  
  <style scoped>
  	.tui-toast {
  		background-color: rgba(0, 0, 0, 0.75);
  		border-radius: 10rpx;
  		position: fixed;
  		visibility: hidden;
  		opacity: 0;
  		left: 50%;
  		top: 48%;
  		-webkit-transform: translate(-50%, -50%);
  		transform: translate(-50%, -50%);
  		transition:  0.3s ease-in-out;
  		transition-property:opacity,visibility;
  		display: flex;
  		align-items: center;
  		justify-content: center;
  		flex-direction: column;
  		padding: 60rpx 20rpx 54rpx 20rpx;
  		box-sizing: border-box;
  	}
  
  	.tui-toast-padding {
  		padding-top: 50rpx !important;
  		padding-bottom: 50rpx !important;
  	}
  	.tui-unicon-padding {
  		padding: 24rpx 40rpx !important;
  		word-break: break-all;
  	}
  
  	.tui-toast-show {
  		visibility: visible;
  		opacity: 1;
  	}
  
  
  	.tui-toast-img {
  		width: 120rpx;
  		height: 120rpx;
  		display: block;
  		margin-bottom: 28rpx;
  	}
  
  	.tui-toast-text {
  		font-size: 30rpx;
  		line-height: 30rpx;
  		font-weight: 400;
  		color: #fff;
  		text-align: center;
  	}
  	.tui-unicon{
  		line-height: 40rpx !important;
  		font-size: 32rpx !important;
  	}
  	.tui-content-ptop {
  		padding-top: 10rpx;
  		font-size: 26rpx !important;
  	}
  </style>