File tree Expand file tree Collapse file tree 1 file changed +30
-5
lines changed
src/renderer/components/Msg Expand file tree Collapse file tree 1 file changed +30
-5
lines changed Original file line number Diff line number Diff line change
1
+ const queue = [ ]
2
+ const maxLength = 5
3
+
1
4
export default {
2
5
install : function ( Vue , Message , defaultOption = { } ) {
3
6
Vue . prototype . $msg = new Proxy ( Message , {
4
7
get ( obj , prop ) {
5
8
return ( arg ) => {
6
- if ( arg instanceof String ) {
9
+ if ( ! ( arg instanceof Object ) ) {
7
10
arg = { message : arg }
8
11
}
9
- obj [ prop ] ( {
10
- ...defaultOption ,
11
- ...arg
12
- } )
12
+ const task = {
13
+ run ( ) {
14
+ obj [ prop ] ( {
15
+ ...defaultOption ,
16
+ ...arg ,
17
+ onClose ( ...data ) {
18
+ const currentTask = queue . pop ( )
19
+ if ( currentTask ) {
20
+ currentTask . run ( )
21
+ }
22
+ if ( arg . onClose ) {
23
+ arg . onClose ( ...data )
24
+ }
25
+ }
26
+ } )
27
+ }
28
+ }
29
+
30
+ if ( queue . length >= maxLength ) {
31
+ queue . pop ( )
32
+ }
33
+ queue . unshift ( task )
34
+
35
+ if ( queue . length === 1 ) {
36
+ queue [ 0 ] . run ( )
37
+ }
13
38
}
14
39
}
15
40
} )
You can’t perform that action at this time.
0 commit comments