primevue-mirror/components/lib/blockui/BlockUI.vue

80 lines
2.4 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
2023-05-24 14:56:02 +00:00
<div ref="container" :class="cx('root')" :aria-busy="isBlocked" v-bind="ptm('root')">
2022-09-06 12:03:37 +00:00
<slot></slot>
</div>
</template>
<script>
2023-04-24 09:32:20 +00:00
import BaseComponent from 'primevue/basecomponent';
2022-09-14 11:26:01 +00:00
import { DomHandler, ZIndexUtils } from 'primevue/utils';
2022-09-06 12:03:37 +00:00
export default {
name: 'BlockUI',
2023-04-24 09:32:20 +00:00
extends: BaseComponent,
2022-09-06 12:03:37 +00:00
emits: ['block', 'unblock'],
mask: null,
2022-12-08 11:04:25 +00:00
data() {
return {
isBlocked: false
};
},
2022-09-14 11:26:01 +00:00
watch: {
blocked(newValue) {
if (newValue === true) this.block();
else this.unblock();
}
},
2022-09-06 12:03:37 +00:00
mounted() {
if (this.blocked) {
this.block();
}
},
methods: {
block() {
let styleClass = 'p-blockui p-component-overlay p-component-overlay-enter';
2022-09-14 11:26:01 +00:00
2022-09-06 12:03:37 +00:00
if (this.fullScreen) {
styleClass += ' p-blockui-document';
this.mask = document.createElement('div');
2023-05-24 14:56:02 +00:00
!this.isUnstyled && this.mask.setAttribute('class', styleClass);
2022-09-06 12:03:37 +00:00
document.body.appendChild(this.mask);
2023-05-24 14:56:02 +00:00
!this.isUnstyled && DomHandler.addClass(document.body, 'p-overflow-hidden');
2022-09-06 12:03:37 +00:00
document.activeElement.blur();
2022-09-14 11:26:01 +00:00
} else {
2022-09-06 12:03:37 +00:00
this.mask = document.createElement('div');
2023-05-24 14:56:02 +00:00
!this.isUnstyled && this.mask.setAttribute('class', styleClass);
2022-09-06 12:03:37 +00:00
this.$refs.container.appendChild(this.mask);
}
if (this.autoZIndex) {
ZIndexUtils.set('modal', this.mask, this.baseZIndex + this.$primevue.config.zIndex.modal);
}
2022-12-08 11:04:25 +00:00
this.isBlocked = true;
2022-09-06 12:03:37 +00:00
this.$emit('block');
},
unblock() {
2023-05-24 14:56:02 +00:00
!this.isUnstyled && DomHandler.addClass(this.mask, 'p-component-overlay-leave');
2022-09-06 12:03:37 +00:00
this.mask.addEventListener('animationend', () => {
this.removeMask();
});
},
removeMask() {
ZIndexUtils.clear(this.mask);
2022-09-14 11:26:01 +00:00
if (this.fullScreen) {
2023-05-24 14:56:02 +00:00
if (!this.isUnstyled) {
document.body.removeChild(this.mask);
DomHandler.removeClass(document.body, 'p-overflow-hidden');
}
2022-09-14 11:26:01 +00:00
} else {
2022-09-06 12:03:37 +00:00
this.$refs.container.removeChild(this.mask);
}
2022-12-08 11:04:25 +00:00
this.isBlocked = false;
2022-09-06 12:03:37 +00:00
this.$emit('unblock');
}
}
2022-09-14 11:26:01 +00:00
};
2022-09-06 12:03:37 +00:00
</script>