Sanakey
2021-01-31 53cc6f817625897935fb10c3845ad7be400f3036
提交 | 用户 | age
d98d05 1 import { VantComponent } from '../common/component';
S 2 import { WHITE } from '../common/color';
53cc6f 3 import { getSystemInfoSync } from '../common/utils';
d98d05 4 VantComponent({
S 5   props: {
6     message: String,
7     background: String,
8     type: {
9       type: String,
10       value: 'danger',
11     },
12     color: {
13       type: String,
14       value: WHITE,
15     },
16     duration: {
17       type: Number,
18       value: 3000,
19     },
20     zIndex: {
21       type: Number,
22       value: 110,
23     },
24     safeAreaInsetTop: {
25       type: Boolean,
26       value: false,
27     },
28     top: null,
29   },
30   data: {
31     show: false,
53cc6f 32     onOpened: null,
S 33     onClose: null,
34     onClick: null,
d98d05 35   },
S 36   created() {
53cc6f 37     const { statusBarHeight } = getSystemInfoSync();
d98d05 38     this.setData({ statusBarHeight });
S 39   },
40   methods: {
41     show() {
42       const { duration, onOpened } = this.data;
43       clearTimeout(this.timer);
44       this.setData({ show: true });
45       wx.nextTick(onOpened);
46       if (duration > 0 && duration !== Infinity) {
47         this.timer = setTimeout(() => {
48           this.hide();
49         }, duration);
50       }
51     },
52     hide() {
53       const { onClose } = this.data;
54       clearTimeout(this.timer);
55       this.setData({ show: false });
56       wx.nextTick(onClose);
57     },
58     onTap(event) {
59       const { onClick } = this.data;
60       if (onClick) {
61         onClick(event.detail);
62       }
63     },
64   },
65 });