likeToast.js
1.74 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
// pages/tab/index/components/likeToast/likeToast.js
import { IMG_URL } from "~/utils/constantData.js";
// `${IMG_URL}index/car2.png`,
//本地图片路径
let IMG_URLLocal = "../../../../../images/";
Component({
data: {
IMG_URL,
IMG_URLLocal,
type: "fail",
title: "你还没有勾选呢!",
isShow: false,
animationData: "",
},
methods: {
showToast: function (data) {
const self = this;
if (this._showTimer) {
clearTimeout(this._showTimer);
}
if (this._animationTimer) {
clearTimeout(this._animationTimer);
}
// display需要先设置为block之后,才能执行动画
this.setData({
title: data.title,
type: data.type,
isShow: true,
});
this._animationTimer = setTimeout(() => {
const animation = wx.createAnimation({
duration: 500,
timingFunction: "ease",
delay: 0,
});
animation.opacity(1).step();
self.setData({
animationData: animation.export(),
});
}, 50);
this._showTimer = setTimeout(function () {
self.hideToast();
if (data.compelete && typeof data.compelete === "function") {
data.compelete();
}
}, 1200 || 50 + data.duration);
},
hideToast: function () {
if (this._hideTimer) {
clearTimeout(this._hideTimer);
}
let animation = wx.createAnimation({
duration: 200,
timingFunction: "ease",
delay: 0,
});
animation.opacity(0).step();
this.setData({
animationData: animation.export(),
});
this._hideTimer = setTimeout(() => {
this.setData({
isShow: false,
});
}, 250);
},
},
});