mirror of
https://github.com/un-pany/v3-admin-vite.git
synced 2025-04-23 04:19:20 +08:00
2 lines
4.4 KiB
JavaScript
2 lines
4.4 KiB
JavaScript
import{as as e,aq as n,aP as t,N as o,b2 as l,b4 as s,u as i,a3 as a,bb as r,b9 as u,Y as c,bg as d}from"./runtime-core.esm-bundler-1857aef3.js";import{a6 as v,c as b,m as g,T as m,a$ as f,R as p,ai as x,bf as y,a_ as C}from"./index-98eefc51.js";function k(a){let r;const u=v("loading"),c=e(!1),d=n({...a,originalPosition:"",originalOverflow:"",visible:!1});function p(){var e,n;null==(n=null==(e=C.$el)?void 0:e.parentNode)||n.removeChild(C.$el)}function x(){if(!c.value)return;const e=d.parent;c.value=!1,e.vLoadingAddClassList=void 0,function(){const e=d.parent;if(!e.vLoadingAddClassList){let n=e.getAttribute("loading-number");n=Number.parseInt(n)-1,n?e.setAttribute("loading-number",n.toString()):(f(e,u.bm("parent","relative")),e.removeAttribute("loading-number")),f(e,u.bm("parent","hidden"))}p(),y.unmount()}()}const y=b({name:"ElLoading",setup:()=>()=>{const e=d.spinner||d.svg,n=o("svg",{class:"circular",viewBox:d.svgViewBox?d.svgViewBox:"0 0 50 50",...e?{innerHTML:e}:{}},[o("circle",{class:"path",cx:"25",cy:"25",r:"20",fill:"none"})]),t=d.text?o("p",{class:u.b("text")},[d.text]):void 0;return o(m,{name:u.b("fade"),onAfterLeave:x},{default:l((()=>[s(i("div",{style:{backgroundColor:d.background||""},class:[u.b("mask"),d.customClass,d.fullscreen?"is-fullscreen":""]},[o("div",{class:u.b("spinner")},[n,t])]),[[g,d.visible]])]))})}}),C=y.mount(document.createElement("div"));return{...t(d),setText:function(e){d.text=e},removeElLoadingChild:p,close:function(){var e;a.beforeClose&&!a.beforeClose()||(c.value=!0,clearTimeout(r),r=window.setTimeout(x,400),d.visible=!1,null==(e=a.closed)||e.call(a))},handleAfterLeave:x,vm:C,get $el(){return C.$el}}}let w;const L=function(e={}){if(!p)return;const n=$(e);if(n.fullscreen&&w)return w;const t=k({...n,closed:()=>{var e;null==(e=n.closed)||e.call(n),n.fullscreen&&(w=void 0)}});h(n,n.parent,t),A(n,n.parent,t),n.parent.vLoadingAddClassList=()=>A(n,n.parent,t);let o=n.parent.getAttribute("loading-number");return o=o?`${Number.parseInt(o)+1}`:"1",n.parent.setAttribute("loading-number",o),n.parent.appendChild(t.$el),a((()=>t.visible.value=n.visible)),n.fullscreen&&(w=t),t},$=e=>{var n,t,o,l;let s;return s=r(e.target)?null!=(n=document.querySelector(e.target))?n:document.body:e.target||document.body,{parent:s===document.body||e.body?document.body:s,background:e.background||"",svg:e.svg||"",svgViewBox:e.svgViewBox||"",spinner:e.spinner||!1,text:e.text||"",fullscreen:s===document.body&&(null==(t=e.fullscreen)||t),lock:null!=(o=e.lock)&&o,customClass:e.customClass||"",visible:null==(l=e.visible)||l,target:s}},h=async(e,n,t)=>{const{nextZIndex:o}=x(),l={};if(e.fullscreen)t.originalPosition.value=y(document.body,"position"),t.originalOverflow.value=y(document.body,"overflow"),l.zIndex=o();else if(e.parent===document.body){t.originalPosition.value=y(document.body,"position"),await a();for(const n of["top","left"]){const t="top"===n?"scrollTop":"scrollLeft";l[n]=e.target.getBoundingClientRect()[n]+document.body[t]+document.documentElement[t]-Number.parseInt(y(document.body,`margin-${n}`),10)+"px"}for(const n of["height","width"])l[n]=`${e.target.getBoundingClientRect()[n]}px`}else t.originalPosition.value=y(n,"position");for(const[s,i]of Object.entries(l))t.$el.style[s]=i},A=(e,n,t)=>{const o=v("loading");["absolute","fixed","sticky"].includes(t.originalPosition.value)?f(n,o.bm("parent","relative")):C(n,o.bm("parent","relative")),e.fullscreen&&e.lock?C(n,o.bm("parent","hidden")):f(n,o.bm("parent","hidden"))},B=Symbol("ElLoading"),V=(n,t)=>{var o,l,s,i;const a=t.instance,c=e=>u(t.value)?t.value[e]:void 0,v=t=>(n=>{const t=r(n)&&(null==a?void 0:a[n])||n;return t?e(t):t})(c(t)||n.getAttribute(`element-loading-${d(t)}`)),b=null!=(o=c("fullscreen"))?o:t.modifiers.fullscreen,g={text:v("text"),svg:v("svg"),svgViewBox:v("svgViewBox"),spinner:v("spinner"),background:v("background"),customClass:v("customClass"),fullscreen:b,target:null!=(l=c("target"))?l:b?void 0:n,body:null!=(s=c("body"))?s:t.modifiers.body,lock:null!=(i=c("lock"))?i:t.modifiers.lock};n[B]={options:g,instance:L(g)}},P={mounted(e,n){n.value&&V(e,n)},updated(e,n){const t=e[B];n.oldValue!==n.value&&(n.value&&!n.oldValue?V(e,n):n.value&&n.oldValue?u(n.value)&&((e,n)=>{for(const t of Object.keys(n))c(n[t])&&(n[t].value=e[t])})(n.value,t.options):null==t||t.instance.close())},unmounted(e){var n;null==(n=e[B])||n.instance.close()}},E={install(e){e.directive("loading",P),e.config.globalProperties.$loading=L},directive:P,service:L};export{E};
|