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
| import fmtEvent from '../_util/fmtEvent';
| var SUPPORT_COMPONENT2 = my.canIUse('component2');
| var TYPE_MAP = {
| success: 'check_',
| fail: 'close_',
| cancel: 'close_',
| info: 'help_',
| warn: 'warn_',
| waiting: 'time-5_'
| };
| Component({
| props: {
| className: '',
| type: 'success',
| title: '',
| onTapMain: function onTapMain() {},
| onTapSub: function onTapSub() {}
| },
| data: {
| // message 的 icon 图标样式
| iconType: 'check_',
| // message 的 icon 类型(颜色)
| iconType_: 'success'
| },
| onInit: function onInit() {
| this.setType(this.props.type);
| },
| didMount: function didMount() {
| if (!SUPPORT_COMPONENT2) {
| this.setType(this.props.type);
| }
| },
| didUpdate: function didUpdate(prevProps) {
| if (!SUPPORT_COMPONENT2 && this.props.type !== prevProps.type) {
| this.setType(this.props.type);
| }
| },
| deriveDataFromProps: function deriveDataFromProps(nextProps) {
| if (this.props.type !== nextProps.type) {
| this.setType(nextProps.type);
| }
| },
| methods: {
| tapMain: function tapMain(e) {
| var event = fmtEvent(this.props, e);
| this.props.onTapMain(event);
| },
| tapSub: function tapSub(e) {
| var event = fmtEvent(this.props, e);
| this.props.onTapSub(event);
| },
| setType: function setType(type) {
| var realType = TYPE_MAP[type] || 'check_'; // 根据 props 中的 type 值选择 icon 的图标以及颜色
|
| this.setData({
| iconType: realType,
| iconType_: type
| });
| }
| }
| });
|
|