40f8606f
梁灏
add Notice component
|
1
2
3
4
5
6
7
8
9
|
import Notification from '../base/notification';
const prefixCls = 'ivu-notice';
const iconPrefixCls = 'ivu-icon';
const prefixKey = 'ivu_notice_key_';
let top = 24;
let defaultDuration = 4.5;
let noticeInstance;
|
833501a4
梁灏
support Notice
|
10
|
let name = 1;
|
40f8606f
梁灏
add Notice component
|
11
12
13
14
15
16
17
18
19
20
21
|
const iconTypes = {
'info': 'information-circled',
'success': 'checkmark-circled',
'warning': 'android-alert',
'error': 'close-circled'
};
function getNoticeInstance () {
noticeInstance = noticeInstance || Notification.newInstance({
prefixCls: prefixCls,
|
833501a4
梁灏
support Notice
|
22
|
styles: {
|
40f8606f
梁灏
add Notice component
|
23
24
25
26
27
28
29
30
31
32
33
|
top: `${top}px`,
right: 0
}
});
return noticeInstance;
}
function notice (type, options) {
const title = options.title || '';
const desc = options.desc || '';
|
833501a4
梁灏
support Notice
|
34
|
const noticeKey = options.name || `${prefixKey}${name}`;
|
40f8606f
梁灏
add Notice component
|
35
36
37
38
|
const onClose = options.onClose || function () {};
// todo const btn = options.btn || null;
const duration = (options.duration === 0) ? 0 : options.duration || defaultDuration;
|
833501a4
梁灏
support Notice
|
39
|
name++;
|
40f8606f
梁灏
add Notice component
|
40
41
42
43
44
|
let instance = getNoticeInstance();
let content;
|
03441255
梁灏
optimize Notice s...
|
45
46
|
const with_desc = desc === '' ? '' : ` ${prefixCls}-with-desc`;
|
40f8606f
梁灏
add Notice component
|
47
48
|
if (type == 'normal') {
content = `
|
03441255
梁灏
optimize Notice s...
|
49
|
<div class="${prefixCls}-custom-content ${prefixCls}-with-normal${with_desc}">
|
40f8606f
梁灏
add Notice component
|
50
51
52
53
54
55
56
|
<div class="${prefixCls}-title">${title}</div>
<div class="${prefixCls}-desc">${desc}</div>
</div>
`;
} else {
const iconType = iconTypes[type];
content = `
|
03441255
梁灏
optimize Notice s...
|
57
|
<div class="${prefixCls}-custom-content ${prefixCls}-with-icon ${prefixCls}-with-${type}${with_desc}">
|
40f8606f
梁灏
add Notice component
|
58
59
60
61
62
63
64
65
66
67
|
<span class="${prefixCls}-icon ${prefixCls}-icon-${type}">
<i class="${iconPrefixCls} ${iconPrefixCls}-${iconType}"></i>
</span>
<div class="${prefixCls}-title">${title}</div>
<div class="${prefixCls}-desc">${desc}</div>
</div>
`;
}
instance.notice({
|
833501a4
梁灏
support Notice
|
68
|
name: noticeKey.toString(),
|
40f8606f
梁灏
add Notice component
|
69
|
duration: duration,
|
833501a4
梁灏
support Notice
|
70
|
styles: {},
|
be0769d4
Rijn
added move up tra...
|
71
|
transitionName: 'move-notice',
|
40f8606f
梁灏
add Notice component
|
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
content: content,
onClose: onClose,
closable: true
});
}
export default {
open (options) {
return notice('normal', options);
},
info (options) {
return notice('info', options);
},
success (options) {
return notice('success', options);
},
warning (options) {
return notice('warning', options);
},
error (options) {
return notice('error', options);
},
config (options) {
if (options.top) {
top = options.top;
}
if (options.duration || options.duration === 0) {
defaultDuration = options.duration;
}
},
|
833501a4
梁灏
support Notice
|
102
103
104
|
close (name) {
if (name) {
name = name.toString();
|
40f8606f
梁灏
add Notice component
|
105
|
if (noticeInstance) {
|
833501a4
梁灏
support Notice
|
106
|
noticeInstance.remove(name);
|
40f8606f
梁灏
add Notice component
|
107
108
109
110
111
112
113
114
115
116
|
}
} else {
return false;
}
},
destroy () {
let instance = getNoticeInstance();
noticeInstance = null;
instance.destroy();
}
|
b0893113
jingsam
add eslint
|
117
|
};
|