[bugfix] Popup: lock-scroll not work when open multi popup (#842)
This commit is contained in:
@@ -69,7 +69,7 @@ export default create({
|
||||
// prevent long tap to close component
|
||||
const deltaTime = new Date() - this.touchStartTime;
|
||||
if (deltaTime < 100 && Math.abs(this.deltaX) < 20 && Math.abs(this.deltaY) < 20) {
|
||||
this.close();
|
||||
this.$emit('input', false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ export default {
|
||||
id: 1,
|
||||
zIndex: 2000,
|
||||
stack: [],
|
||||
lockCount: 0,
|
||||
|
||||
plusKey(key) {
|
||||
return this[key]++;
|
||||
|
||||
@@ -57,14 +57,26 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
activated() {
|
||||
/* istanbul ignore next */
|
||||
if (this.value) {
|
||||
this.open();
|
||||
}
|
||||
},
|
||||
|
||||
beforeDestroy() {
|
||||
this.close();
|
||||
},
|
||||
|
||||
deactivated() {
|
||||
/* istanbul ignore next */
|
||||
this.close();
|
||||
},
|
||||
|
||||
methods: {
|
||||
open() {
|
||||
/* istanbul ignore next */
|
||||
if (this.$isServer) {
|
||||
if (this.$isServer || this.opened) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -73,30 +85,41 @@ export default {
|
||||
context.zIndex = this.zIndex;
|
||||
}
|
||||
|
||||
if (this.lockScroll) {
|
||||
document.body.classList.add('van-overflow-hidden');
|
||||
on(document, 'touchstart', this.onTouchStart);
|
||||
on(document, 'touchmove', this.onTouchMove);
|
||||
}
|
||||
|
||||
this.opened = true;
|
||||
this.renderOverlay();
|
||||
this.$emit('input', true);
|
||||
|
||||
if (this.lockScroll) {
|
||||
if (!context.lockCount) {
|
||||
document.body.classList.add('van-overflow-hidden');
|
||||
on(document, 'touchstart', this.onTouchStart);
|
||||
on(document, 'touchmove', this.onTouchMove);
|
||||
}
|
||||
context.lockCount++;
|
||||
}
|
||||
},
|
||||
|
||||
close() {
|
||||
if (this.lockScroll) {
|
||||
document.body.classList.remove('van-overflow-hidden');
|
||||
off(document, 'touchstart', this.onTouchStart);
|
||||
off(document, 'touchmove', this.onTouchMove);
|
||||
if (!this.opened) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.lockScroll) {
|
||||
context.lockCount--;
|
||||
if (!context.lockCount) {
|
||||
document.body.classList.remove('van-overflow-hidden');
|
||||
off(document, 'touchstart', this.onTouchStart);
|
||||
off(document, 'touchmove', this.onTouchMove);
|
||||
}
|
||||
}
|
||||
|
||||
this.opened = false;
|
||||
manager.close(this._popupId);
|
||||
this.$emit('input', false);
|
||||
},
|
||||
|
||||
move() {
|
||||
if (this.getContainer) {
|
||||
this.getContainer().appendChild(this.$el);
|
||||
/* istanbul ignore if */
|
||||
} else if (this.$parent) {
|
||||
this.$parent.$el.appendChild(this.$el);
|
||||
}
|
||||
|
||||
@@ -9,10 +9,8 @@ const defaultConfig = {
|
||||
|
||||
export default {
|
||||
open(vm, config) {
|
||||
const exist = context.stack.some(item => item.vm._popupId === vm._popupId);
|
||||
|
||||
/* istanbul ignore next */
|
||||
if (!exist) {
|
||||
if (!context.stack.some(item => item.vm._popupId === vm._popupId)) {
|
||||
const el = vm.$el;
|
||||
const targetNode = el && el.parentNode && el.parentNode.nodeType !== 11 ? el.parentNode : document.body;
|
||||
context.stack.push({ vm, config, targetNode });
|
||||
@@ -66,7 +64,7 @@ export default {
|
||||
if (context.top) {
|
||||
const { vm } = context.top;
|
||||
vm.$emit('click-overlay');
|
||||
vm.closeOnClickOverlay && vm.close();
|
||||
vm.closeOnClickOverlay && vm.$emit('input', false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user