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

107 lines
3.3 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>
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,
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';
2023-08-04 10:40:59 +00:00
this.mask = DomHandler.createElement('div', {
'data-pc-section': 'mask',
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);
DomHandler.addClass(document.body, 'p-overflow-hidden');
2023-09-25 10:05:27 +00:00
document.body.style.setProperty('--scrollbar-width', DomHandler.calculateScrollbarWidth() + 'px');
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', {
'data-pc-section': 'mask',
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);
DomHandler.removeClass(document.body, 'p-overflow-hidden');
2023-09-25 10:05:27 +00:00
document.body.style.removeProperty('--scrollbar-width');
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>