7c15ac9e
梁灏
add Message compo...
|
1
2
3
4
|
import Notification from '../base/notification';
const prefixCls = 'ivu-message';
const iconPrefixCls = 'ivu-icon';
|
47e58396
梁灏
message component...
|
5
|
const prefixKey = 'ivu_message_key_';
|
7c15ac9e
梁灏
add Message compo...
|
6
7
|
let defaultDuration = 1.5;
|
7c15ac9e
梁灏
add Message compo...
|
8
9
|
let top;
let messageInstance;
|
6cadeba4
梁灏
support Message
|
10
|
let name = 1;
|
7c15ac9e
梁灏
add Message compo...
|
11
12
13
14
15
16
17
18
19
20
21
22
|
const iconTypes = {
'info': 'information-circled',
'success': 'checkmark-circled',
'warning': 'android-alert',
'error': 'close-circled',
'loading': 'load-c'
};
function getMessageInstance () {
messageInstance = messageInstance || Notification.newInstance({
prefixCls: prefixCls,
|
6cadeba4
梁灏
support Message
|
23
|
styles: {
|
7c15ac9e
梁灏
add Message compo...
|
24
25
26
27
28
29
30
|
top: `${top}px`
}
});
return messageInstance;
}
|
e0bd31a6
Aresn
update Message
|
31
|
function notice (content = '', duration = defaultDuration, type, onClose = function () {}, closable = false) {
|
40f8606f
梁灏
add Notice component
|
32
|
const iconType = iconTypes[type];
|
7c15ac9e
梁灏
add Message compo...
|
33
34
35
36
37
38
39
|
// if loading
const loadCls = type === 'loading' ? ' ivu-load-loop' : '';
let instance = getMessageInstance();
instance.notice({
|
6cadeba4
梁灏
support Message
|
40
|
name: `${prefixKey}${name}`,
|
7c15ac9e
梁灏
add Message compo...
|
41
|
duration: duration,
|
6cadeba4
梁灏
support Message
|
42
|
styles: {},
|
40f8606f
梁灏
add Notice component
|
43
|
transitionName: 'move-up',
|
7c15ac9e
梁灏
add Message compo...
|
44
45
46
47
48
49
|
content: `
<div class="${prefixCls}-custom-content ${prefixCls}-${type}">
<i class="${iconPrefixCls} ${iconPrefixCls}-${iconType}${loadCls}"></i>
<span>${content}</span>
</div>
`,
|
e0bd31a6
Aresn
update Message
|
50
51
52
|
onClose: onClose,
closable: closable,
type: 'message'
|
7c15ac9e
梁灏
add Message compo...
|
53
|
});
|
47e58396
梁灏
message component...
|
54
55
56
|
// 用于手动消除
return (function () {
|
6cadeba4
梁灏
support Message
|
57
|
let target = name++;
|
47e58396
梁灏
message component...
|
58
59
60
|
return function () {
instance.remove(`${prefixKey}${target}`);
|
b0893113
jingsam
add eslint
|
61
|
};
|
47e58396
梁灏
message component...
|
62
|
})();
|
7c15ac9e
梁灏
add Message compo...
|
63
64
65
|
}
export default {
|
6e2f40ea
Rijn
assign names to C...
|
66
67
|
name: 'Message',
|
e0bd31a6
Aresn
update Message
|
68
69
70
71
72
73
74
75
|
info (options) {
const type = typeof options;
if (type === 'string') {
options = {
content: options
};
}
return notice(options.content, options.duration, 'info', options.onClose, options.closable);
|
7c15ac9e
梁灏
add Message compo...
|
76
|
},
|
e0bd31a6
Aresn
update Message
|
77
78
79
80
81
82
83
84
|
success (options) {
const type = typeof options;
if (type === 'string') {
options = {
content: options
};
}
return notice(options.content, options.duration, 'success', options.onClose, options.closable);
|
7c15ac9e
梁灏
add Message compo...
|
85
|
},
|
e0bd31a6
Aresn
update Message
|
86
87
88
89
90
91
92
93
|
warning (options) {
const type = typeof options;
if (type === 'string') {
options = {
content: options
};
}
return notice(options.content, options.duration, 'warning', options.onClose, options.closable);
|
7c15ac9e
梁灏
add Message compo...
|
94
|
},
|
e0bd31a6
Aresn
update Message
|
95
96
97
98
99
100
101
102
|
error (options) {
const type = typeof options;
if (type === 'string') {
options = {
content: options
};
}
return notice(options.content, options.duration, 'error', options.onClose, options.closable);
|
7c15ac9e
梁灏
add Message compo...
|
103
|
},
|
e0bd31a6
Aresn
update Message
|
104
105
106
107
108
109
110
111
|
loading (options) {
const type = typeof options;
if (type === 'string') {
options = {
content: options
};
}
return notice(options.content, options.duration, 'loading', options.onClose, options.closable);
|
7c15ac9e
梁灏
add Message compo...
|
112
113
114
115
116
117
118
119
|
},
config (options) {
if (options.top) {
top = options.top;
}
if (options.duration) {
defaultDuration = options.duration;
}
|
d3671687
梁灏
add destroy() for...
|
120
121
122
123
|
},
destroy () {
let instance = getMessageInstance();
messageInstance = null;
|
1c82a9ab
Lawrence Lee
bugfix: notice & ...
|
124
|
instance.destroy('ivu-message');
|
7c15ac9e
梁灏
add Message compo...
|
125
|
}
|
b0893113
jingsam
add eslint
|
126
|
};
|