index.js
1.59 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
import { IMG_URL } from '~/utils/constantData'
Component({
options: {
addGlobalClass: true
},
properties: {
show: {
type: Boolean,
value: false
},
type: {
type: String,
value: 'success' // 'success' | 'fail'
},
title: {
type: String,
value: '提交成功'
},
description: {
type: String,
value: ''
},
okText: {
type: String,
value: '我知道了'
},
maskClosable: {
type: Boolean,
value: false
},
useSlot: {
type: Boolean,
value: false
}
},
data: {
IMG_URL,
cardAnimation: ''
},
observers: {
show(n) {
if (n) {
this.startAnim()
}
}
},
methods: {
open(opts = {}) {
const { type, title, description, okText, useSlot } = opts
this.setData({
type: type ?? this.data.type,
title: title ?? this.data.title,
description: description ?? this.data.description,
okText: okText ?? this.data.okText,
useSlot: useSlot ?? this.data.useSlot,
show: true
})
this.startAnim()
},
close() {
this.setData({ show: false })
this.triggerEvent('close')
},
onOk() {
this.close()
this.triggerEvent('ok')
},
onMaskTap() {
if (this.data.maskClosable) this.close()
},
startAnim() {
const animation = wx.createAnimation({
duration: 200,
timingFunction: 'ease'
})
animation.scale(1).opacity(1).step()
this.setData({ cardAnimation: animation.export() })
},
noop() {}
}
})