[bugfix] Popup: lock-scroll not work when open multi popup (#842)

This commit is contained in:
neverland
2018-04-10 10:39:54 +08:00
committed by GitHub
parent 91f44010e7
commit 1b6f9ba075
6 changed files with 111 additions and 49 deletions
+36 -13
View File
@@ -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);
}