2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2024-02-11 08:10:29 +00:00
|
|
|
<div ref="container" :class="cx('root')" :aria-busy="isBlocked" v-bind="ptmi('root')">
|
2022-09-06 12:03:37 +00:00
|
|
|
<slot></slot>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-09-14 11:26:01 +00:00
|
|
|
import { DomHandler, ZIndexUtils } from 'primevue/utils';
|
2023-06-09 08:30:38 +00:00
|
|
|
import BaseBlockUI from './BaseBlockUI.vue';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'BlockUI',
|
2023-06-09 08:30:38 +00:00
|
|
|
extends: BaseBlockUI,
|
2024-02-11 08:10:29 +00:00
|
|
|
inheritAttrs: false,
|
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() {
|
2024-04-08 12:01:20 +00:00
|
|
|
let styleClass = 'p-blockui-mask 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) {
|
2024-04-08 12:01:20 +00:00
|
|
|
styleClass += ' p-blockui-mask-document';
|
2023-08-04 10:40:59 +00:00
|
|
|
|
|
|
|
this.mask = DomHandler.createElement('div', {
|
|
|
|
style: {
|
|
|
|
position: 'fixed',
|
|
|
|
top: '0',
|
|
|
|
left: '0',
|
|
|
|
width: '100%',
|
|
|
|
height: '100%'
|
|
|
|
},
|
|
|
|
class: !this.isUnstyled && styleClass,
|
|
|
|
'p-bind': this.ptm('mask')
|
|
|
|
});
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
document.body.appendChild(this.mask);
|
2023-10-10 22:36:20 +00:00
|
|
|
DomHandler.blockBodyScroll();
|
2022-09-06 12:03:37 +00:00
|
|
|
document.activeElement.blur();
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2023-08-04 10:40:59 +00:00
|
|
|
this.mask = DomHandler.createElement('div', {
|
|
|
|
style: {
|
|
|
|
position: 'absolute',
|
|
|
|
top: '0',
|
|
|
|
left: '0',
|
|
|
|
width: '100%',
|
|
|
|
height: '100%'
|
|
|
|
},
|
|
|
|
class: !this.isUnstyled && styleClass,
|
|
|
|
'p-bind': this.ptm('mask')
|
|
|
|
});
|
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');
|
2023-08-04 10:40:59 +00:00
|
|
|
|
|
|
|
if (DomHandler.hasCSSAnimation(this.mask) > 0) {
|
|
|
|
this.mask.addEventListener('animationend', () => {
|
|
|
|
this.removeMask();
|
|
|
|
});
|
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.removeMask();
|
2023-08-04 10:40:59 +00:00
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
removeMask() {
|
|
|
|
ZIndexUtils.clear(this.mask);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
if (this.fullScreen) {
|
2023-08-04 10:40:59 +00:00
|
|
|
document.body.removeChild(this.mask);
|
2023-10-10 22:36:20 +00:00
|
|
|
DomHandler.unblockBodyScroll();
|
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>
|