Files
SnowCatQQ/release-tools/webui-static/assets/useRequest-B1BwPztr.js
T
2026-11-12 06:29:38 +08:00

2 lines
17 KiB
JavaScript

import{r as m}from"./react-vendor-jWT2yUdV.js";import{c as L,g as je}from"./qface-BZLvZXJ8.js";var w=function(){return w=Object.assign||function(e){for(var n,t=1,i=arguments.length;t<i;t++){n=arguments[t];for(var u in n)Object.prototype.hasOwnProperty.call(n,u)&&(e[u]=n[u])}return e},w.apply(this,arguments)};function Ee(r,e){var n={};for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&e.indexOf(t)<0&&(n[t]=r[t]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,t=Object.getOwnPropertySymbols(r);i<t.length;i++)e.indexOf(t[i])<0&&Object.prototype.propertyIsEnumerable.call(r,t[i])&&(n[t[i]]=r[t[i]]);return n}function Ne(r,e,n,t){function i(u){return u instanceof n?u:new n(function(o){o(u)})}return new(n||(n=Promise))(function(u,o){function f(l){try{a(t.next(l))}catch(s){o(s)}}function c(l){try{a(t.throw(l))}catch(s){o(s)}}function a(l){l.done?u(l.value):i(l.value).then(f,c)}a((t=t.apply(r,e||[])).next())})}function Fe(r,e){var n={label:0,sent:function(){if(u[0]&1)throw u[1];return u[1]},trys:[],ops:[]},t,i,u,o=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return o.next=f(0),o.throw=f(1),o.return=f(2),typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function f(a){return function(l){return c([a,l])}}function c(a){if(t)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(n=0)),n;)try{if(t=1,i&&(u=a[0]&2?i.return:a[0]?i.throw||((u=i.return)&&u.call(i),0):i.next)&&!(u=u.call(i,a[1])).done)return u;switch(i=0,u&&(a=[a[0]&2,u.value]),a[0]){case 0:case 1:u=a;break;case 4:return n.label++,{value:a[1],done:!1};case 5:n.label++,i=a[1],a=[0];continue;case 7:a=n.ops.pop(),n.trys.pop();continue;default:if(u=n.trys,!(u=u.length>0&&u[u.length-1])&&(a[0]===6||a[0]===2)){n=0;continue}if(a[0]===3&&(!u||a[1]>u[0]&&a[1]<u[3])){n.label=a[1];break}if(a[0]===6&&n.label<u[1]){n.label=u[1],u=a;break}if(u&&n.label<u[2]){n.label=u[2],n.ops.push(a);break}u[2]&&n.ops.pop(),n.trys.pop();continue}a=e.call(r,n)}catch(l){a=[6,l],i=0}finally{t=u=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}}function p(r,e){var n=typeof Symbol=="function"&&r[Symbol.iterator];if(!n)return r;var t=n.call(r),i,u=[],o;try{for(;(e===void 0||e-- >0)&&!(i=t.next()).done;)u.push(i.value)}catch(f){o={error:f}}finally{try{i&&!i.done&&(n=t.return)&&n.call(t)}finally{if(o)throw o.error}}return u}function y(r,e,n){if(n||arguments.length===2)for(var t=0,i=e.length,u;t<i;t++)(u||!(t in e))&&(u||(u=Array.prototype.slice.call(e,0,t)),u[t]=e[t]);return r.concat(u||Array.prototype.slice.call(e))}var We=function(r){return function(e,n){var t=m.useRef(!1);r(function(){return function(){t.current=!1}},[]),r(function(){if(!t.current)t.current=!0;else return e()},n)}},Me=function(r){return typeof r=="function"},C=function(r){var e=m.useRef(r);e.current=m.useMemo(function(){return r},[r]);var n=m.useRef(void 0);return n.current||(n.current=function(){for(var t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];return e.current.apply(this,t)}),n.current};const te=We(m.useEffect);var Pe=function(r,e){var n=e.manual,t=e.ready,i=t===void 0?!0:t,u=e.defaultParams,o=u===void 0?[]:u,f=e.refreshDeps,c=f===void 0?[]:f,a=e.refreshDepsAction,l=m.useRef(!1);return l.current=!1,te(function(){!n&&i&&(l.current=!0,r.run.apply(r,y([],p(o),!1)))},[i]),te(function(){l.current||n||(l.current=!0,a?a():r.refresh())},y([],p(c),!1)),{onBefore:function(){if(!i)return{stopNow:!0}}}};Pe.onInit=function(r){var e=r.ready,n=e===void 0?!0:e,t=r.manual;return{loading:!t&&n}};function De(r,e){if(r===e)return!0;for(var n=0;n<r.length;n++)if(!Object.is(r[n],e[n]))return!1;return!0}var _e=function(r,e){var n=m.useRef({deps:e,obj:void 0,initialized:!1}).current;return(n.initialized===!1||!De(n.deps,e))&&(n.deps=e,n.obj=r(),n.initialized=!0),n.obj};function xe(r){var e=m.useRef(r);return e.current=r,e}var ie=function(r){var e=xe(r);m.useEffect(function(){return function(){e.current()}},[])},N=new Map,Be=function(r,e,n){var t=N.get(r);t!=null&&t.timer&&clearTimeout(t.timer);var i=void 0;e>-1&&(i=setTimeout(function(){N.delete(r)},e)),N.set(r,w(w({},n),{timer:i}))},Ge=function(r){return N.get(r)},F=new Map,He=function(r){return F.get(r)},ke=function(r,e){F.set(r,e),e.then(function(n){return F.delete(r),n}).catch(function(){F.delete(r)})},E={},Ue=function(r,e){E[r]&&E[r].forEach(function(n){return n(e)})},G=function(r,e){return E[r]||(E[r]=[]),E[r].push(e),function(){var t=E[r].indexOf(e);E[r].splice(t,1)}},$e=function(r,e){var n=e.cacheKey,t=e.cacheTime,i=t===void 0?300*1e3:t,u=e.staleTime,o=u===void 0?0:u,f=e.setCache,c=e.getCache,a=m.useRef(void 0),l=m.useRef(void 0),s=function(v,d){f?f(d):Be(v,i,d),Ue(v,d.data)},h=function(v,d){return d===void 0&&(d=[]),c?c(d):Ge(v)};return _e(function(){if(n){var v=h(n);v&&Object.hasOwnProperty.call(v,"data")&&(r.state.data=v.data,r.state.params=v.params,(o===-1||Date.now()-v.time<=o)&&(r.state.loading=!1)),a.current=G(n,function(d){r.setState({data:d})})}},[]),ie(function(){var v;(v=a.current)===null||v===void 0||v.call(a)}),n?{onBefore:function(v){var d=h(n,v);return!d||!Object.hasOwnProperty.call(d,"data")?{}:o===-1||Date.now()-d.time<=o?{loading:!1,data:d==null?void 0:d.data,error:void 0,returnNow:!0}:{data:d==null?void 0:d.data,error:void 0}},onRequest:function(v,d){var b=He(n);return b&&b!==l.current?{servicePromise:b}:(b=v.apply(void 0,y([],p(d),!1)),l.current=b,ke(n,b),{servicePromise:b})},onSuccess:function(v,d){var b;n&&((b=a.current)===null||b===void 0||b.call(a),s(n,{data:v,params:d,time:Date.now()}),a.current=G(n,function(T){r.setState({data:T})}))},onMutate:function(v){var d;n&&((d=a.current)===null||d===void 0||d.call(a),s(n,{data:v,params:r.state.params,time:Date.now()}),a.current=G(n,function(b){r.setState({data:b})}))}}:{}},H,ce;function ue(){if(ce)return H;ce=1;function r(e){var n=typeof e;return e!=null&&(n=="object"||n=="function")}return H=r,H}var k,se;function ze(){if(se)return k;se=1;var r=typeof L=="object"&&L&&L.Object===Object&&L;return k=r,k}var U,le;function Ce(){if(le)return U;le=1;var r=ze(),e=typeof self=="object"&&self&&self.Object===Object&&self,n=r||e||Function("return this")();return U=n,U}var $,de;function Xe(){if(de)return $;de=1;var r=Ce(),e=function(){return r.Date.now()};return $=e,$}var z,ve;function Ve(){if(ve)return z;ve=1;var r=/\s/;function e(n){for(var t=n.length;t--&&r.test(n.charAt(t)););return t}return z=e,z}var X,me;function Je(){if(me)return X;me=1;var r=Ve(),e=/^\s+/;function n(t){return t&&t.slice(0,r(t)+1).replace(e,"")}return X=n,X}var V,he;function qe(){if(he)return V;he=1;var r=Ce(),e=r.Symbol;return V=e,V}var J,be;function Ke(){if(be)return J;be=1;var r=qe(),e=Object.prototype,n=e.hasOwnProperty,t=e.toString,i=r?r.toStringTag:void 0;function u(o){var f=n.call(o,i),c=o[i];try{o[i]=void 0;var a=!0}catch{}var l=t.call(o);return a&&(f?o[i]=c:delete o[i]),l}return J=u,J}var K,ge;function Qe(){if(ge)return K;ge=1;var r=Object.prototype,e=r.toString;function n(t){return e.call(t)}return K=n,K}var Q,pe;function Ye(){if(pe)return Q;pe=1;var r=qe(),e=Ke(),n=Qe(),t="[object Null]",i="[object Undefined]",u=r?r.toStringTag:void 0;function o(f){return f==null?f===void 0?i:t:u&&u in Object(f)?e(f):n(f)}return Q=o,Q}var Y,ye;function Ze(){if(ye)return Y;ye=1;function r(e){return e!=null&&typeof e=="object"}return Y=r,Y}var Z,we;function er(){if(we)return Z;we=1;var r=Ye(),e=Ze(),n="[object Symbol]";function t(i){return typeof i=="symbol"||e(i)&&r(i)==n}return Z=t,Z}var ee,Te;function rr(){if(Te)return ee;Te=1;var r=Je(),e=ue(),n=er(),t=NaN,i=/^[-+]0x[0-9a-f]+$/i,u=/^0b[01]+$/i,o=/^0o[0-7]+$/i,f=parseInt;function c(a){if(typeof a=="number")return a;if(n(a))return t;if(e(a)){var l=typeof a.valueOf=="function"?a.valueOf():a;a=e(l)?l+"":l}if(typeof a!="string")return a===0?a:+a;a=r(a);var s=u.test(a);return s||o.test(a)?f(a.slice(2),s?2:8):i.test(a)?t:+a}return ee=c,ee}var re,Re;function Ae(){if(Re)return re;Re=1;var r=ue(),e=Xe(),n=rr(),t="Expected a function",i=Math.max,u=Math.min;function o(f,c,a){var l,s,h,v,d,b,T=0,P=!1,S=!1,j=!0;if(typeof f!="function")throw new TypeError(t);c=n(c)||0,r(a)&&(P=!!a.leading,S="maxWait"in a,h=S?i(n(a.maxWait)||0,c):h,j="trailing"in a?!!a.trailing:j);function _(g){var O=l,A=s;return l=s=void 0,T=g,v=f.apply(A,O),v}function q(g){return T=g,d=setTimeout(R,c),P?_(g):v}function I(g){var O=g-b,A=g-T,fe=c-O;return S?u(fe,h-A):fe}function x(g){var O=g-b,A=g-T;return b===void 0||O>=c||O<0||S&&A>=h}function R(){var g=e();if(x(g))return oe(g);d=setTimeout(R,I(g))}function oe(g){return d=void 0,j&&l?_(g):(l=s=void 0,v)}function Ie(){d!==void 0&&clearTimeout(d),T=0,l=b=s=d=void 0}function Le(){return d===void 0?v:oe(e())}function B(){var g=e(),O=x(g);if(l=arguments,s=this,b=g,O){if(d===void 0)return q(b);if(S)return clearTimeout(d),d=setTimeout(R,c),_(b)}return d===void 0&&(d=setTimeout(R,c)),v}return B.cancel=Ie,B.flush=Le,B}return re=o,re}var nr=Ae();const tr=je(nr);var ir=function(r,e){var n=e.debounceWait,t=e.debounceLeading,i=e.debounceTrailing,u=e.debounceMaxWait,o=m.useRef(void 0),f=m.useMemo(function(){var c={};return t!==void 0&&(c.leading=t),i!==void 0&&(c.trailing=i),u!==void 0&&(c.maxWait=u),c},[t,i,u]);return m.useEffect(function(){if(n){var c=r.runAsync.bind(r);return o.current=tr(function(a){a()},n,f),r.runAsync=function(){for(var a=[],l=0;l<arguments.length;l++)a[l]=arguments[l];return new Promise(function(s,h){var v;(v=o.current)===null||v===void 0||v.call(o,function(){c.apply(void 0,y([],p(a),!1)).then(s).catch(h)})})},function(){var a;(a=o.current)===null||a===void 0||a.cancel(),r.runAsync=c}}},[n,f]),n?{onCancel:function(){var c;(c=o.current)===null||c===void 0||c.cancel()}}:{}},ur=function(r,e){var n=e.loadingDelay,t=e.ready,i=m.useRef(void 0);if(!n)return{};var u=function(){i.current&&clearTimeout(i.current)};return{onBefore:function(){return u(),t!==!1&&(i.current=setTimeout(function(){r.setState({loading:!0})},n)),{loading:!1}},onFinally:function(){u()},onCancel:function(){u()}}},D=!!(typeof window<"u"&&window.document&&window.document.createElement);function ae(){return D?document.visibilityState!=="hidden":!0}var W=new Set;function ar(r){return W.add(r),function(){W.has(r)&&W.delete(r)}}if(D){var or=function(){ae()&&W.forEach(function(r){return r()})};window.addEventListener("visibilitychange",or,!1)}var fr=function(r,e){var n=e.pollingInterval,t=e.pollingWhenHidden,i=t===void 0?!0:t,u=e.pollingErrorRetryCount,o=u===void 0?-1:u,f=m.useRef(void 0),c=m.useRef(void 0),a=m.useRef(0),l=function(){var s;f.current&&clearTimeout(f.current),(s=c.current)===null||s===void 0||s.call(c)};return te(function(){n||l()},[n]),n?{onBefore:function(){l()},onError:function(){a.current+=1},onSuccess:function(){a.current=0},onFinally:function(){o===-1||o!==-1&&a.current<=o?f.current=setTimeout(function(){!i&&!ae()?c.current=ar(function(){r.refresh()}):r.refresh()},n):a.current=0},onCancel:function(){l()}}:{}};function cr(r,e){var n=!1;return function(){for(var t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];n||(n=!0,r.apply(void 0,y([],p(t),!1)),setTimeout(function(){n=!1},e))}}var sr=function(){return D&&typeof navigator.onLine<"u"?navigator.onLine:!0},M=new Set;function lr(r){return M.add(r),function(){M.has(r)&&M.delete(r)}}if(D){var Se=function(){!ae()||!sr()||M.forEach(function(r){return r()})};window.addEventListener("visibilitychange",Se,!1),window.addEventListener("focus",Se,!1)}var dr=function(r,e){var n=e.refreshOnWindowFocus,t=e.focusTimespan,i=t===void 0?5e3:t,u=m.useRef(void 0),o=function(){var f;(f=u.current)===null||f===void 0||f.call(u)};return m.useEffect(function(){if(n){var f=cr(r.refresh.bind(r),i);u.current=lr(function(){f()})}return function(){o()}},[n,i]),ie(function(){o()}),{}},vr=function(r,e){var n=e.retryInterval,t=e.retryCount,i=m.useRef(void 0),u=m.useRef(0),o=m.useRef(!1);return t?{onBefore:function(){o.current||(u.current=0),o.current=!1,i.current&&clearTimeout(i.current)},onSuccess:function(){u.current=0},onError:function(){if(u.current+=1,t===-1||u.current<=t){var f=n??Math.min(1e3*Math.pow(2,u.current),3e4);i.current=setTimeout(function(){o.current=!0,r.refresh()},f)}else u.current=0},onCancel:function(){u.current=0,i.current&&clearTimeout(i.current)}}:{}},ne,Oe;function mr(){if(Oe)return ne;Oe=1;var r=Ae(),e=ue(),n="Expected a function";function t(i,u,o){var f=!0,c=!0;if(typeof i!="function")throw new TypeError(n);return e(o)&&(f="leading"in o?!!o.leading:f,c="trailing"in o?!!o.trailing:c),r(i,u,{leading:f,maxWait:u,trailing:c})}return ne=t,ne}var hr=mr();const br=je(hr);var gr=function(r,e){var n=e.throttleWait,t=e.throttleLeading,i=e.throttleTrailing,u=m.useRef(void 0),o={};return t!==void 0&&(o.leading=t),i!==void 0&&(o.trailing=i),m.useEffect(function(){if(n){var f=r.runAsync.bind(r);return u.current=br(function(c){c()},n,o),r.runAsync=function(){for(var c=[],a=0;a<arguments.length;a++)c[a]=arguments[a];return new Promise(function(l,s){var h;(h=u.current)===null||h===void 0||h.call(u,function(){f.apply(void 0,y([],p(c),!1)).then(l).catch(s)})})},function(){var c;r.runAsync=f,(c=u.current)===null||c===void 0||c.cancel()}}},[n,t,i]),n?{onCancel:function(){var f;(f=u.current)===null||f===void 0||f.cancel()}}:{}},pr=function(r){m.useEffect(function(){var e=r==null?void 0:r();if(!(e&&typeof e=="object"&&typeof e.then=="function"))return e},[])},yr=function(){var r=p(m.useState({}),2),e=r[1];return m.useCallback(function(){return e({})},[])},wr=(function(){function r(e,n,t,i){i===void 0&&(i={}),this.serviceRef=e,this.options=n,this.subscribe=t,this.initState=i,this.pluginImpls=[],this.count=0,this.state={loading:!1,params:void 0,data:void 0,error:void 0},this.state=w(w(w({},this.state),{loading:!n.manual}),i)}return r.prototype.setState=function(e){e===void 0&&(e={}),this.state=w(w({},this.state),e),this.subscribe()},r.prototype.runPluginHandler=function(e){for(var n=[],t=1;t<arguments.length;t++)n[t-1]=arguments[t];var i=this.pluginImpls.map(function(u){var o;return(o=u[e])===null||o===void 0?void 0:o.call.apply(o,y([u],p(n),!1))}).filter(Boolean);return Object.assign.apply(Object,y([{}],p(i),!1))},r.prototype.runAsync=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return Ne(this,void 0,void 0,function(){var t,i,u,o,f,c,a,l,s,h,v,d,b,T,P,S,j,_,q,I,x;return Fe(this,function(R){switch(R.label){case 0:if(this.count+=1,t=this.count,i=this.runPluginHandler("onBefore",e),u=i.stopNow,o=u===void 0?!1:u,f=i.returnNow,c=f===void 0?!1:f,a=Ee(i,["stopNow","returnNow"]),o)return[2,new Promise(function(){})];if(this.setState(w({loading:!0,params:e},a)),c)return[2,Promise.resolve(a.data)];(b=(d=this.options).onBefore)===null||b===void 0||b.call(d,e),R.label=1;case 1:return R.trys.push([1,3,,4]),l=this.runPluginHandler("onRequest",this.serviceRef.current,e).servicePromise,l||(l=(v=this.serviceRef).current.apply(v,y([],p(e),!1))),[4,l];case 2:return s=R.sent(),t!==this.count?[2,new Promise(function(){})]:(this.setState({data:s,error:void 0,loading:!1}),(P=(T=this.options).onSuccess)===null||P===void 0||P.call(T,s,e),this.runPluginHandler("onSuccess",s,e),(j=(S=this.options).onFinally)===null||j===void 0||j.call(S,e,s,void 0),t===this.count&&this.runPluginHandler("onFinally",e,s,void 0),[2,s]);case 3:if(h=R.sent(),t!==this.count)return[2,new Promise(function(){})];throw this.setState({error:h,loading:!1}),(q=(_=this.options).onError)===null||q===void 0||q.call(_,h,e),this.runPluginHandler("onError",h,e),(x=(I=this.options).onFinally)===null||x===void 0||x.call(I,e,void 0,h),t===this.count&&this.runPluginHandler("onFinally",e,void 0,h),h;case 4:return[2]}})})},r.prototype.run=function(){for(var e=this,n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];this.runAsync.apply(this,y([],p(n),!1)).catch(function(i){e.options.onError||console.error(i)})},r.prototype.cancel=function(){this.count+=1,this.setState({loading:!1}),this.runPluginHandler("onCancel")},r.prototype.refresh=function(){this.run.apply(this,y([],p(this.state.params||[]),!1))},r.prototype.refreshAsync=function(){return this.runAsync.apply(this,y([],p(this.state.params||[]),!1))},r.prototype.mutate=function(e){var n=Me(e)?e(this.state.data):e;this.runPluginHandler("onMutate",n),this.setState({data:n})},r})();function Tr(r,e,n){e===void 0&&(e={}),n===void 0&&(n=[]);var t=e.manual,i=t===void 0?!1:t,u=e.ready,o=u===void 0?!0:u,f=Ee(e,["manual","ready"]),c=w({manual:i,ready:o},f),a=xe(r),l=yr(),s=_e(function(){var h=n.map(function(v){var d;return(d=v==null?void 0:v.onInit)===null||d===void 0?void 0:d.call(v,c)}).filter(Boolean);return new wr(a,c,l,Object.assign.apply(Object,y([{}],p(h),!1)))},[]);return s.options=c,s.pluginImpls=n.map(function(h){return h(s,c)}),pr(function(){if(!i&&o){var h=s.state.params||e.defaultParams||[];s.run.apply(s,y([],p(h),!1))}}),ie(function(){s.cancel()}),{loading:s.state.loading,data:s.state.data,error:s.state.error,params:s.state.params||[],cancel:C(s.cancel.bind(s)),refresh:C(s.refresh.bind(s)),refreshAsync:C(s.refreshAsync.bind(s)),run:C(s.run.bind(s)),runAsync:C(s.runAsync.bind(s)),mutate:C(s.mutate.bind(s))}}function Or(r,e,n){return Tr(r,e,y(y([],p([]),!1),[ir,ur,fr,dr,gr,Pe,$e,vr],!1))}export{Ne as _,Or as u};