index-PbVC8mB0.js 8.3 KB

1
  1. var z=Object.defineProperty,J=Object.defineProperties;var Q=Object.getOwnPropertyDescriptors;var S=Object.getOwnPropertySymbols;var _=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var D=Math.pow,T=(n,e,t)=>e in n?z(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,w=(n,e)=>{for(var t in e||(e={}))_.call(e,t)&&T(n,t,e[t]);if(S)for(var t of S(e))$.call(e,t)&&T(n,t,e[t]);return n},F=(n,e)=>J(n,Q(e));var H=(n,e)=>{var t={};for(var s in n)_.call(n,s)&&e.indexOf(s)<0&&(t[s]=n[s]);if(n!=null&&S)for(var s of S(n))e.indexOf(s)<0&&$.call(n,s)&&(t[s]=n[s]);return t};var B=(n,e,t)=>T(n,typeof e!="symbol"?e+"":e,t);var U=(n,e,t)=>new Promise((s,r)=>{var u=c=>{try{i(t.next(c))}catch(f){r(f)}},o=c=>{try{i(t.throw(c))}catch(f){r(f)}},i=c=>c.done?s(c.value):Promise.resolve(c.value).then(u,o);i((t=t.apply(n,e)).next())});import{u as P,f as v,w as j,h as C,b as y,c as X,r as Y,o as Z,I as G}from"./vue-DM5HGU8Z.js";import{b1 as W,bu as k}from"./antd-BfqWtMX3.js";const V=(n,{manual:e,ready:t=!0,defaultParams:s=[],refreshDeps:r=[],refreshDepsAction:u})=>{const o=v(!1);return j(()=>P(t),i=>{!P(e)&&i&&(o.value=!0,n.run(...s))}),r.length&&j(r,()=>{o.value||e||(u?u():n.refresh())}),{onBefore:()=>{if(!P(t))return{stopNow:!0}}}};V.onInit=({ready:n=!0,manual:e})=>({loading:!P(e)&&P(n)});const p=new Map,K=(n,e,t)=>{const s=p.get(n);s!=null&&s.timer&&clearTimeout(s.timer);let r;e>-1&&(r=setTimeout(()=>{p.delete(n)},e)),p.set(n,F(w({},t),{timer:r}))},I=n=>p.get(n),be=n=>{n?(Array.isArray(n)?n:[n]).forEach(t=>p.delete(t)):p.clear()},R=new Map,ee=n=>R.get(n),ne=(n,e)=>{R.set(n,e),e.then(t=>(R.delete(n),t)).catch(()=>{R.delete(n)})},h={},te=(n,e)=>{h[n]&&h[n].forEach(t=>t(e))},x=(n,e)=>(h[n]||(h[n]=[]),h[n].push(e),function(){const s=h[n].indexOf(e);h[n].splice(s,1)}),se=(n,{cacheKey:e,cacheTime:t=5*60*1e3,staleTime:s=0,setCache:r,getCache:u})=>{const o=v(),i=v(),c=(a,l)=>{r?r(l):K(a,t,l),te(a,l.data)},f=(a,l=[])=>u?u(l):I(a);return C(()=>{if(!e)return;const a=f(e);a&&Object.hasOwnProperty.call(a,"data")&&(n.state.data=a.data,n.state.params=a.params,(s===-1||new Date().getTime()-a.time<=s)&&(n.state.loading=!1)),o.value=x(e,l=>{n.setState({data:l})})}),y(()=>{var a;(a=o.value)==null||a.call(o)}),e?{onBefore:a=>{const l=f(e,a);return!l||!Object.hasOwnProperty.call(l,"data")?{}:s===-1||new Date().getTime()-l.time<=s?{loading:!1,data:l==null?void 0:l.data,error:void 0,returnNow:!0}:{data:l==null?void 0:l.data,error:void 0}},onRequest:(a,l)=>{let d=ee(e);return d&&d!==i.value?{servicePromise:d}:(d=a(...l),i.value=d,ne(e,d),{servicePromise:d})},onSuccess:(a,l)=>{var d;e&&((d=o.value)==null||d.call(o),c(e,{data:a,params:l,time:new Date().getTime()}),o.value=x(e,O=>{n.setState({data:O})}))},onMutate:a=>{var l;e&&((l=o.value)==null||l.call(o),c(e,{data:a,params:n.state.params,time:new Date().getTime()}),o.value=x(e,d=>{n.setState({data:d})}))}}:{}},ie=(n,{debounceWait:e,debounceLeading:t,debounceTrailing:s,debounceMaxWait:r})=>{const u=v(),o=X(()=>{const i={};return t!==void 0&&(i.leading=t),s!==void 0&&(i.trailing=s),r!==void 0&&(i.maxWait=r),i});return C(()=>{if(e){const i=n.runAsync.bind(n);return u.value=W(c=>{c()},e,o.value),n.runAsync=(...c)=>new Promise((f,a)=>{var l;(l=u.value)==null||l.call(u,()=>{i(...c).then(f).catch(a)})}),()=>{var c;(c=u.value)==null||c.cancel(),n.runAsync=i}}}),e?{onCancel:()=>{var i;(i=u.value)==null||i.cancel()}}:{}},re=(n,{loadingDelay:e,ready:t})=>{const s=v();if(!e)return{};const r=()=>{s.value&&clearTimeout(s.value)};return{onBefore:()=>(r(),P(t)!==!1&&(s.value=setTimeout(()=>{n.setState({loading:!0})},e)),{loading:!1}),onFinally:()=>{r()},onCancel:()=>{r()}}},E=!!(typeof window!="undefined"&&window.document&&window.document.createElement);function M(){return E?document.visibilityState!=="hidden":!0}const b=[];if(E){const n=()=>{if(M())for(let e=0;e<b.length;e++){const t=b[e];t()}};window.addEventListener("visibilitychange",n,!1)}function ue(n){return b.push(n),function(){const t=b.indexOf(n);b.splice(t,1)}}const oe=(n,{pollingInterval:e,pollingWhenHidden:t=!0,pollingErrorRetryCount:s=-1})=>{const r=v(),u=v(),o=v(0),i=()=>{var c;r.value&&clearTimeout(r.value),(c=u.value)==null||c.call(u)};return j(()=>e,()=>{e||i()}),e?{onBefore:()=>{i()},onError:()=>{o.value+=1},onSuccess:()=>{o.value=0},onFinally:()=>{s===-1||s!==-1&&o.value<=s?r.value=setTimeout(()=>{!t&&!M()?u.value=ue(()=>{n.refresh()}):n.refresh()},e):o.value=0},onCancel:()=>{i()}}:{}};function ae(n,e){let t=!1;return(...s)=>{t||(t=!0,n(...s),setTimeout(()=>{t=!1},e))}}function le(){return E&&typeof navigator.onLine!="undefined"?navigator.onLine:!0}const A=[];if(E){const n=()=>{if(!(!M()||!le()))for(let e=0;e<A.length;e++){const t=A[e];t()}};window.addEventListener("visibilitychange",n,!1),window.addEventListener("focus",n,!1)}function ce(n){return A.push(n),function(){const t=A.indexOf(n);t>-1&&A.splice(t,1)}}const fe=(n,{refreshOnWindowFocus:e,focusTimespan:t=5e3})=>{const s=v(),r=()=>{var u;(u=s.value)==null||u.call(s)};return C(()=>{if(e){const u=ae(n.refresh.bind(n),t);s.value=ce(()=>{u()})}return()=>{r()}}),y(()=>{r()}),{}},de=(n,{retryInterval:e,retryCount:t})=>{const s=v(),r=v(0),u=v(!1);return t?{onBefore:()=>{u.value||(r.value=0),u.value=!1,s.value&&clearTimeout(s.value)},onSuccess:()=>{r.value=0},onError:()=>{if(r.value+=1,t===-1||r.value<=t){const o=e!=null?e:Math.min(1e3*D(2,r.value),3e4);s.value=setTimeout(()=>{u.value=!0,n.refresh()},o)}else r.value=0},onCancel:()=>{r.value=0,s.value&&clearTimeout(s.value)}}:{}},ve=(n,{throttleWait:e,throttleLeading:t,throttleTrailing:s})=>{const r=v(),u={};return t!==void 0&&(u.leading=t),s!==void 0&&(u.trailing=s),C(()=>{if(e){const o=n.runAsync.bind(n);return r.value=k(i=>{i()},e,u),n.runAsync=(...i)=>new Promise((c,f)=>{var a;(a=r.value)==null||a.call(r,()=>{o(...i).then(c).catch(f)})}),()=>{var i;n.runAsync=o,(i=r.value)==null||i.cancel()}}}),e?{onCancel:()=>{var o;(o=r.value)==null||o.cancel()}}:{}},ge=n=>typeof n=="function";class he{constructor(e,t,s,r={}){B(this,"pluginImpls",[]);B(this,"count",0);B(this,"state",Y({loading:!1,params:void 0,data:void 0,error:void 0}));this.serviceRef=e,this.options=t,this.subscribe=s,this.initState=r,this.setState(w({loading:!t.manual},r))}setState(e={}){Object.assign(this.state,e),this.subscribe()}runPluginHandler(e,...t){const s=this.pluginImpls.map(r=>{var u;return(u=r[e])==null?void 0:u.call(r,...t)}).filter(Boolean);return Object.assign({},...s)}runAsync(...e){return U(this,null,function*(){var i,c,f,a,l,d,O,q,L,N;this.count+=1;const t=this.count,o=this.runPluginHandler("onBefore",e),{stopNow:s=!1,returnNow:r=!1}=o,u=H(o,["stopNow","returnNow"]);if(s)return new Promise(()=>{});if(this.setState(w({loading:!0,params:e},u)),r)return Promise.resolve(u.data);(c=(i=this.options).onBefore)==null||c.call(i,e);try{let{servicePromise:g}=this.runPluginHandler("onRequest",this.serviceRef,e);g||(g=this.serviceRef(...e));const m=yield g;return t!==this.count?new Promise(()=>{}):(this.setState({data:m,error:void 0,loading:!1}),(a=(f=this.options).onSuccess)==null||a.call(f,m,e),this.runPluginHandler("onSuccess",m,e),(d=(l=this.options).onFinally)==null||d.call(l,e,m,void 0),t===this.count&&this.runPluginHandler("onFinally",e,m,void 0),m)}catch(g){if(t!==this.count)return new Promise(()=>{});throw this.setState({error:g,loading:!1}),(q=(O=this.options).onError)==null||q.call(O,g,e),this.runPluginHandler("onError",g,e),(N=(L=this.options).onFinally)==null||N.call(L,e,void 0,g),t===this.count&&this.runPluginHandler("onFinally",e,void 0,g),g}})}run(...e){this.runAsync(...e).catch(t=>{this.options.onError})}cancel(){this.count+=1,this.setState({loading:!1}),this.runPluginHandler("onCancel")}refresh(){this.run(...this.state.params||[])}refreshAsync(){return this.runAsync(...this.state.params||[])}mutate(e){const t=ge(e)?e(this.state.data):e;this.runPluginHandler("onMutate",t),this.setState({data:t})}}function me(n,e={},t=[]){const c=e,{manual:s=!1}=c,r=H(c,["manual"]),u=w({manual:s},r),o=t.map(f=>{var a;return(a=f==null?void 0:f.onInit)==null?void 0:a.call(f,u)}).filter(Boolean),i=new he(n,u,()=>{},Object.assign({},...o));return i.options=u,i.pluginImpls=t.map(f=>f(i,u)),Z(()=>{if(!s){const f=i.state.params||e.defaultParams||[];i.run(...f)}}),y(()=>{i.cancel()}),F(w({},G(i.state)),{cancel:i.cancel.bind(i),mutate:i.mutate.bind(i),refresh:i.refresh.bind(i),refreshAsync:i.refreshAsync.bind(i),run:i.run.bind(i),runAsync:i.runAsync.bind(i)})}function Ae(n,e,t){return me(n,e,[ie,re,oe,fe,ve,V,se,de])}export{be as c,Ae as u};