2
This commit is contained in:
51
normal-admin/node_modules/element-plus/es/hooks/use-lockscreen/index.mjs
generated
vendored
Normal file
51
normal-admin/node_modules/element-plus/es/hooks/use-lockscreen/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
import { isRef, computed, watch, onScopeDispose } from 'vue';
|
||||
import { useNamespace } from '../use-namespace/index.mjs';
|
||||
import { throwError } from '../../utils/error.mjs';
|
||||
import { isClient } from '@vueuse/core';
|
||||
import { hasClass, addClass, getStyle, removeClass } from '../../utils/dom/style.mjs';
|
||||
import { getScrollBarWidth } from '../../utils/dom/scroll.mjs';
|
||||
|
||||
const useLockscreen = (trigger, options = {}) => {
|
||||
if (!isRef(trigger)) {
|
||||
throwError("[useLockscreen]", "You need to pass a ref param to this function");
|
||||
}
|
||||
const ns = options.ns || useNamespace("popup");
|
||||
const hiddenCls = computed(() => ns.bm("parent", "hidden"));
|
||||
if (!isClient || hasClass(document.body, hiddenCls.value)) {
|
||||
return;
|
||||
}
|
||||
let scrollBarWidth = 0;
|
||||
let withoutHiddenClass = false;
|
||||
let bodyWidth = "0";
|
||||
const cleanup = () => {
|
||||
setTimeout(() => {
|
||||
if (typeof document === "undefined")
|
||||
return;
|
||||
if (withoutHiddenClass && document) {
|
||||
document.body.style.width = bodyWidth;
|
||||
removeClass(document.body, hiddenCls.value);
|
||||
}
|
||||
}, 200);
|
||||
};
|
||||
watch(trigger, (val) => {
|
||||
if (!val) {
|
||||
cleanup();
|
||||
return;
|
||||
}
|
||||
withoutHiddenClass = !hasClass(document.body, hiddenCls.value);
|
||||
if (withoutHiddenClass) {
|
||||
bodyWidth = document.body.style.width;
|
||||
addClass(document.body, hiddenCls.value);
|
||||
}
|
||||
scrollBarWidth = getScrollBarWidth(ns.namespace.value);
|
||||
const bodyHasOverflow = document.documentElement.clientHeight < document.body.scrollHeight;
|
||||
const bodyOverflowY = getStyle(document.body, "overflowY");
|
||||
if (scrollBarWidth > 0 && (bodyHasOverflow || bodyOverflowY === "scroll") && withoutHiddenClass) {
|
||||
document.body.style.width = `calc(100% - ${scrollBarWidth}px)`;
|
||||
}
|
||||
});
|
||||
onScopeDispose(() => cleanup());
|
||||
};
|
||||
|
||||
export { useLockscreen };
|
||||
//# sourceMappingURL=index.mjs.map
|
||||
Reference in New Issue
Block a user