[improvement] optimize popup mixin (#1979)

This commit is contained in:
neverland
2018-10-25 13:10:09 +08:00
committed by GitHub
parent 5564fbf624
commit 88d8eb0897
3 changed files with 15 additions and 22 deletions
+8 -8
View File
@@ -10,23 +10,23 @@ const defaultConfig = {
export default {
open(vm, config) {
/* istanbul ignore next */
if (!context.stack.some(item => item.vm._popupId === vm._popupId)) {
if (!context.stack.some(item => item.vm === vm)) {
const el = vm.$el;
const targetNode = el && el.parentNode && el.parentNode.nodeType !== 11 ? el.parentNode : document.body;
context.stack.push({ vm, config, targetNode });
const target = el && el.parentNode ? el.parentNode : document.body;
context.stack.push({ vm, config, target });
this.update();
};
},
close(id) {
close(vm) {
const { stack } = context;
if (stack.length) {
if (context.top.vm._popupId === id) {
if (context.top.vm === vm) {
stack.pop();
this.update();
} else {
context.stack = stack.filter(item => item.vm._popupId !== id);
context.stack = stack.filter(item => item.vm !== vm);
}
}
},
@@ -48,9 +48,9 @@ export default {
}
if (context.top) {
const { targetNode, config } = context.top;
const { target, config } = context.top;
targetNode.appendChild(modal.$el);
target.appendChild(modal.$el);
Object.assign(modal, {
...defaultConfig,
...config,