-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwepy-message.wpy
84 lines (73 loc) · 2.41 KB
/
wepy-message.wpy
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="wepy-message {{params.position}} " animation="{{animationData}}" wx:if="{{params.visable}}">
<view class="wepy-message-container {{params.type}}">
<span class="wepy-message-icon iconfont icon-{{params.type}}"></span>
{{tips}}
</view>
</view>
</template>
<script>
import wepy from 'wepy'
let commonTimer=3000;
let translateTimer=500;
export default class MyPage extends wepy.component {
props = {
}
data = {
animationData:{},
params:{
visable:false,
position:"bottom",
type:"info"
},
tips:""
}
watch = {
}
methods = {
success:function (tips,timer) {
this.params.type="success";
return this.commonFun(tips,timer);
},
error:function (tips,timer) {
this.params.type="error";
return this.commonFun(tips,timer);
},
info:function (tips,timer) {
this.params.type="info";
return this.commonFun(tips,timer);
},
warning:function (tips,timer,position) {
this.params.type="warning";
return this.commonFun(tips,timer);
},
}
commonFun(tips,timer){
return new Promise((resolve,reject)=>{
let _timer=timer && typeof (timer)=="number"?timer:commonTimer;
this.tips=tips;
this.params.visable=true;
this.$apply();
var animation = wx.createAnimation({
duration: translateTimer,
timingFunction: 'ease-in',
})
animation.bottom(0).step()
this.animationData=animation.export()
this.$apply();
let self=this;
setTimeout( () =>{
animation.bottom("-100%").step();
this.animationData=animation.export()
self.$apply()
setTimeout(function () {
self.params.visable=false;
self.$apply();
resolve();
},translateTimer)
},_timer)
})
}
}
</script>
<style lang="less" src="./wepy-message.scss"></style>