Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Element
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
林焕东
Element
Commits
6e51f658
Commit
6e51f658
authored
Oct 29, 2016
by
baiyaaaaa
Committed by
GitHub
Oct 29, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #716 from Leopoldthecoder/msgbox-overwriting
MessageBox: fix a callback overwriting bug
parents
2c339bbf
4cff9bc1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
49 deletions
+54
-49
packages/message-box/src/main.js
packages/message-box/src/main.js
+54
-49
No files found.
packages/message-box/src/main.js
View file @
6e51f658
import
{
$t
}
from
'
element-ui/src/locale
'
;
var
CONFIRM_TEXT
=
$t
(
'
el.messagebox.confirm
'
);
var
CANCEL_TEXT
=
$t
(
'
el.messagebox.cancel
'
);
const
CONFIRM_TEXT
=
$t
(
'
el.messagebox.confirm
'
);
const
CANCEL_TEXT
=
$t
(
'
el.messagebox.cancel
'
);
var
defaults
=
{
const
defaults
=
{
title
:
'
提示
'
,
message
:
''
,
type
:
''
,
...
...
@@ -31,12 +31,12 @@ var defaults = {
import
Vue
from
'
vue
'
;
import
msgboxVue
from
'
./main.vue
'
;
var
merge
=
function
(
target
)
{
for
(
var
i
=
1
,
j
=
arguments
.
length
;
i
<
j
;
i
++
)
{
var
source
=
arguments
[
i
];
for
(
var
prop
in
source
)
{
const
merge
=
function
(
target
)
{
for
(
let
i
=
1
,
j
=
arguments
.
length
;
i
<
j
;
i
++
)
{
let
source
=
arguments
[
i
];
for
(
let
prop
in
source
)
{
if
(
source
.
hasOwnProperty
(
prop
))
{
var
value
=
source
[
prop
];
let
value
=
source
[
prop
];
if
(
value
!==
undefined
)
{
target
[
prop
]
=
value
;
}
...
...
@@ -47,19 +47,14 @@ var merge = function(target) {
return
target
;
};
var
MessageBoxConstructor
=
Vue
.
extend
(
msgboxVue
);
const
MessageBoxConstructor
=
Vue
.
extend
(
msgboxVue
);
var
currentMsg
,
instance
;
var
msgQueue
=
[];
let
currentMsg
,
instance
;
let
msgQueue
=
[];
var
initInstance
=
function
()
{
instance
=
new
MessageBoxConstructor
({
el
:
document
.
createElement
(
'
div
'
)
});
instance
.
callback
=
function
(
action
)
{
const
defaultCallback
=
action
=>
{
if
(
currentMsg
)
{
var
callback
=
currentMsg
.
callback
;
let
callback
=
currentMsg
.
callback
;
if
(
typeof
callback
===
'
function
'
)
{
if
(
instance
.
showInput
)
{
callback
(
instance
.
inputValue
,
action
);
...
...
@@ -68,7 +63,7 @@ var initInstance = function() {
}
}
if
(
currentMsg
.
resolve
)
{
var
$type
=
currentMsg
.
options
.
$type
;
let
$type
=
currentMsg
.
options
.
$type
;
if
(
$type
===
'
confirm
'
||
$type
===
'
prompt
'
)
{
if
(
action
===
'
confirm
'
)
{
if
(
instance
.
showInput
)
{
...
...
@@ -84,10 +79,17 @@ var initInstance = function() {
}
}
}
};
};
var
showNextMsg
=
function
()
{
const
initInstance
=
()
=>
{
instance
=
new
MessageBoxConstructor
({
el
:
document
.
createElement
(
'
div
'
)
});
instance
.
callback
=
defaultCallback
;
};
const
showNextMsg
=
()
=>
{
if
(
!
instance
)
{
initInstance
();
}
...
...
@@ -96,12 +98,15 @@ var showNextMsg = function() {
if
(
msgQueue
.
length
>
0
)
{
currentMsg
=
msgQueue
.
shift
();
var
options
=
currentMsg
.
options
;
for
(
var
prop
in
options
)
{
let
options
=
currentMsg
.
options
;
for
(
let
prop
in
options
)
{
if
(
options
.
hasOwnProperty
(
prop
))
{
instance
[
prop
]
=
options
[
prop
];
}
}
if
(
options
.
callback
===
undefined
)
{
instance
.
callback
=
defaultCallback
;
}
[
'
modal
'
,
'
showClose
'
,
'
closeOnClickModal
'
,
'
closeOnPressEscape
'
].
forEach
(
prop
=>
{
if
(
instance
[
prop
]
===
undefined
)
{
instance
[
prop
]
=
true
;
...
...
@@ -116,7 +121,7 @@ var showNextMsg = function() {
}
};
var
MessageBox
=
function
(
options
,
callback
)
{
const
MessageBox
=
function
(
options
,
callback
)
{
if
(
typeof
options
===
'
string
'
)
{
options
=
{
title
:
options
...
...
@@ -132,7 +137,7 @@ var MessageBox = function(options, callback) {
}
if
(
typeof
Promise
!==
'
undefined
'
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
// eslint-disable-line
return
new
Promise
(
(
resolve
,
reject
)
=>
{
// eslint-disable-line
msgQueue
.
push
({
options
:
merge
({},
defaults
,
MessageBox
.
defaults
||
{},
options
),
callback
:
callback
,
...
...
@@ -152,11 +157,11 @@ var MessageBox = function(options, callback) {
}
};
MessageBox
.
setDefaults
=
function
(
defaults
)
{
MessageBox
.
setDefaults
=
defaults
=>
{
MessageBox
.
defaults
=
defaults
;
};
MessageBox
.
alert
=
function
(
message
,
title
,
options
)
{
MessageBox
.
alert
=
(
message
,
title
,
options
)
=>
{
if
(
typeof
title
===
'
object
'
)
{
options
=
title
;
title
=
''
;
...
...
@@ -170,7 +175,7 @@ MessageBox.alert = function(message, title, options) {
},
options
));
};
MessageBox
.
confirm
=
function
(
message
,
title
,
options
)
{
MessageBox
.
confirm
=
(
message
,
title
,
options
)
=>
{
if
(
typeof
title
===
'
object
'
)
{
options
=
title
;
title
=
''
;
...
...
@@ -183,7 +188,7 @@ MessageBox.confirm = function(message, title, options) {
},
options
));
};
MessageBox
.
prompt
=
function
(
message
,
title
,
options
)
{
MessageBox
.
prompt
=
(
message
,
title
,
options
)
=>
{
if
(
typeof
title
===
'
object
'
)
{
options
=
title
;
title
=
''
;
...
...
@@ -197,7 +202,7 @@ MessageBox.prompt = function(message, title, options) {
},
options
));
};
MessageBox
.
close
=
function
()
{
MessageBox
.
close
=
()
=>
{
instance
.
value
=
false
;
msgQueue
=
[];
currentMsg
=
null
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment