mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-01-27 05:15:43 +08:00
16cd2438dd
Co-authored-by: zhangchao3 <zhangchao3@corp.netease.com>
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { createLoading } from '/@/components/Loading';
|
|
import type { Directive, App } from 'vue';
|
|
|
|
const loadingDirective: Directive = {
|
|
mounted(el, binding) {
|
|
const tip = el.getAttribute('loading-tip');
|
|
const background = el.getAttribute('loading-background');
|
|
const size = el.getAttribute('loading-size');
|
|
const fullscreen = !!binding.modifiers.fullscreen;
|
|
const instance = createLoading(
|
|
{
|
|
tip,
|
|
background,
|
|
size: size || 'large',
|
|
loading: !!binding.value,
|
|
absolute: !fullscreen,
|
|
},
|
|
fullscreen ? document.body : el,
|
|
);
|
|
el.instance = instance;
|
|
},
|
|
updated(el, binding) {
|
|
const instance = el.instance;
|
|
if (!instance) return;
|
|
instance.setTip(el.getAttribute('loading-tip'));
|
|
if (binding.oldValue !== binding.value) {
|
|
instance.setLoading?.(binding.value && !instance.loading);
|
|
}
|
|
},
|
|
unmounted(el) {
|
|
el?.instance?.close();
|
|
},
|
|
};
|
|
|
|
export function setupLoadingDirective(app: App) {
|
|
app.directive('loading', loadingDirective);
|
|
}
|
|
|
|
export default loadingDirective;
|