Files
chazhi_admin_parten/public/h5/assets/pages-about-vue-query.BIiY5BmP.js
2026-03-14 16:20:49 +08:00

2 lines
12 KiB
JavaScript

var zt=Object.defineProperty,Vt=Object.defineProperties;var Wt=Object.getOwnPropertyDescriptors;var it=Object.getOwnPropertySymbols;var It=Object.prototype.hasOwnProperty,Qt=Object.prototype.propertyIsEnumerable;var xt=(i,t,e)=>t in i?zt(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,M=(i,t)=>{for(var e in t||(t={}))It.call(t,e)&&xt(i,e,t[e]);if(it)for(var e of it(t))Qt.call(t,e)&&xt(i,e,t[e]);return i},Et=(i,t)=>Vt(i,Wt(t));var Ft=(i,t)=>{var e={};for(var n in i)It.call(i,n)&&t.indexOf(n)<0&&(e[n]=i[n]);if(i!=null&&it)for(var n of it(i))t.indexOf(n)<0&&Qt.call(i,n)&&(e[n]=i[n]);return e};var ut=(i,t,e)=>{if(!t.has(i))throw TypeError("Cannot "+e)};var s=(i,t,e)=>(ut(i,t,"read from private field"),e?e.call(i):t.get(i)),u=(i,t,e)=>{if(t.has(i))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(i):t.set(i,e)},l=(i,t,e,n)=>(ut(i,t,"write to private field"),n?n.call(i,e):t.set(i,e),e);var f=(i,t,e)=>(ut(i,t,"access private method"),e);var lt=(i,t,e)=>new Promise((n,h)=>{var r=d=>{try{b(e.next(d))}catch(m){h(m)}},c=d=>{try{b(e.throw(d))}catch(m){h(m)}},b=d=>d.done?n(d.value):Promise.resolve(d.value).then(r,c);b((e=e.apply(i,t)).next())});import{S as Kt,D as Tt,E as R,G as ft,H as W,I as Ht,J as Ut,K as Dt,L as $t,M as Jt,N as qt,O as kt,P as Gt,Q as Xt,i as Yt,R as Zt,T as te,U as ee,V as se,W as nt,X as ie,Y as ne,Z as re,$ as ae,a0 as Lt,a1 as Mt,a2 as oe,d as he,a3 as ue,c as Pt,w as E,a as le,j as ct,k as z,l as ce,y as de,u as dt,m as rt,p as fe,F as pe,t as be,x as ye}from"./index-B-O76M86.js";import{g as ve,f as ge}from"./foo.DJobK0_z.js";var v,a,K,y,F,P,S,x,H,j,A,T,U,I,B,D,V,$,pt,J,bt,q,yt,G,vt,X,gt,Y,mt,Z,Rt,at,Nt,Bt,me=(Bt=class extends Kt{constructor(t,e){super();u(this,D);u(this,$);u(this,J);u(this,q);u(this,G);u(this,X);u(this,Y);u(this,Z);u(this,at);u(this,v,void 0);u(this,a,void 0);u(this,K,void 0);u(this,y,void 0);u(this,F,void 0);u(this,P,void 0);u(this,S,void 0);u(this,x,void 0);u(this,H,void 0);u(this,j,void 0);u(this,A,void 0);u(this,T,void 0);u(this,U,void 0);u(this,I,void 0);u(this,B,new Set);this.options=e,l(this,v,t),l(this,x,null),l(this,S,Tt()),this.options.experimental_prefetchInRender||s(this,S).reject(new Error("experimental_prefetchInRender feature flag is not enabled")),this.bindMethods(),this.setOptions(e)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(s(this,a).addObserver(this),jt(s(this,a),this.options)?f(this,D,V).call(this):this.updateResult(),f(this,G,vt).call(this))}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return Ot(s(this,a),this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return Ot(s(this,a),this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,f(this,X,gt).call(this),f(this,Y,mt).call(this),s(this,a).removeObserver(this)}setOptions(t){const e=this.options,n=s(this,a);if(this.options=s(this,v).defaultQueryOptions(t),this.options.enabled!==void 0&&typeof this.options.enabled!="boolean"&&typeof this.options.enabled!="function"&&typeof R(this.options.enabled,s(this,a))!="boolean")throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");f(this,Z,Rt).call(this),s(this,a).setOptions(this.options),e._defaulted&&!ft(this.options,e)&&s(this,v).getQueryCache().notify({type:"observerOptionsUpdated",query:s(this,a),observer:this});const h=this.hasListeners();h&&At(s(this,a),n,this.options,e)&&f(this,D,V).call(this),this.updateResult(),h&&(s(this,a)!==n||R(this.options.enabled,s(this,a))!==R(e.enabled,s(this,a))||W(this.options.staleTime,s(this,a))!==W(e.staleTime,s(this,a)))&&f(this,$,pt).call(this);const r=f(this,J,bt).call(this);h&&(s(this,a)!==n||R(this.options.enabled,s(this,a))!==R(e.enabled,s(this,a))||r!==s(this,I))&&f(this,q,yt).call(this,r)}getOptimisticResult(t){const e=s(this,v).getQueryCache().build(s(this,v),t),n=this.createResult(e,t);return Oe(this,n)&&(l(this,y,n),l(this,P,this.options),l(this,F,s(this,a).state)),n}getCurrentResult(){return s(this,y)}trackResult(t,e){return new Proxy(t,{get:(n,h)=>(this.trackProp(h),e==null||e(h),Reflect.get(n,h))})}trackProp(t){s(this,B).add(t)}getCurrentQuery(){return s(this,a)}refetch(e={}){var t=Ft(e,[]);return this.fetch(M({},t))}fetchOptimistic(t){const e=s(this,v).defaultQueryOptions(t),n=s(this,v).getQueryCache().build(s(this,v),e);return n.fetch().then(()=>this.createResult(n,e))}fetch(t){var e;return f(this,D,V).call(this,Et(M({},t),{cancelRefetch:(e=t.cancelRefetch)!=null?e:!0})).then(()=>(this.updateResult(),s(this,y)))}createResult(t,e){var St;const n=s(this,a),h=this.options,r=s(this,y),c=s(this,F),b=s(this,P),m=t!==n?t.state:s(this,K),{state:tt}=t;let p=M({},tt),Q=!1,o;if(e._optimisticResults){const g=this.hasListeners(),et=!g&&jt(t,e),L=g&&At(t,n,e,h);(et||L)&&(p=M(M({},p),qt(tt.data,t.options))),e._optimisticResults==="isRestoring"&&(p.fetchStatus="idle")}let{error:_,errorUpdatedAt:w,status:O}=p;o=p.data;let N=!1;if(e.placeholderData!==void 0&&o===void 0&&O==="pending"){let g;r!=null&&r.isPlaceholderData&&e.placeholderData===(b==null?void 0:b.placeholderData)?(g=r.data,N=!0):g=typeof e.placeholderData=="function"?e.placeholderData((St=s(this,A))==null?void 0:St.state.data,s(this,A)):e.placeholderData,g!==void 0&&(O="success",o=kt(r==null?void 0:r.data,g,e),Q=!0)}if(e.select&&o!==void 0&&!N)if(r&&o===(c==null?void 0:c.data)&&e.select===s(this,H))o=s(this,j);else try{l(this,H,e.select),o=e.select(o),o=kt(r==null?void 0:r.data,o,e),l(this,j,o),l(this,x,null)}catch(g){l(this,x,g)}s(this,x)&&(_=s(this,x),o=s(this,j),w=Date.now(),O="error");const k=p.fetchStatus==="fetching",ot=O==="pending",ht=O==="error",_t=ot&&k,wt=o!==void 0,C={status:O,fetchStatus:p.fetchStatus,isPending:ot,isSuccess:O==="success",isError:ht,isInitialLoading:_t,isLoading:_t,data:o,dataUpdatedAt:p.dataUpdatedAt,error:_,errorUpdatedAt:w,failureCount:p.fetchFailureCount,failureReason:p.fetchFailureReason,errorUpdateCount:p.errorUpdateCount,isFetched:p.dataUpdateCount>0||p.errorUpdateCount>0,isFetchedAfterMount:p.dataUpdateCount>m.dataUpdateCount||p.errorUpdateCount>m.errorUpdateCount,isFetching:k,isRefetching:k&&!ot,isLoadingError:ht&&!wt,isPaused:p.fetchStatus==="paused",isPlaceholderData:Q,isRefetchError:ht&&wt,isStale:Ct(t,e),refetch:this.refetch,promise:s(this,S),isEnabled:R(e.enabled,t)!==!1};if(this.options.experimental_prefetchInRender){const g=st=>{C.status==="error"?st.reject(C.error):C.data!==void 0&&st.resolve(C.data)},et=()=>{const st=l(this,S,C.promise=Tt());g(st)},L=s(this,S);switch(L.status){case"pending":t.queryHash===n.queryHash&&g(L);break;case"fulfilled":(C.status==="error"||C.data!==L.value)&&et();break;case"rejected":(C.status!=="error"||C.error!==L.reason)&&et();break}}return C}updateResult(){const t=s(this,y),e=this.createResult(s(this,a),this.options);if(l(this,F,s(this,a).state),l(this,P,this.options),s(this,F).data!==void 0&&l(this,A,s(this,a)),ft(e,t))return;l(this,y,e);const n=()=>{if(!t)return!0;const{notifyOnChangeProps:h}=this.options,r=typeof h=="function"?h():h;if(r==="all"||!r&&!s(this,B).size)return!0;const c=new Set(r!=null?r:s(this,B));return this.options.throwOnError&&c.add("error"),Object.keys(s(this,y)).some(b=>{const d=b;return s(this,y)[d]!==t[d]&&c.has(d)})};f(this,at,Nt).call(this,{listeners:n()})}onQueryUpdate(){this.updateResult(),this.hasListeners()&&f(this,G,vt).call(this)}},v=new WeakMap,a=new WeakMap,K=new WeakMap,y=new WeakMap,F=new WeakMap,P=new WeakMap,S=new WeakMap,x=new WeakMap,H=new WeakMap,j=new WeakMap,A=new WeakMap,T=new WeakMap,U=new WeakMap,I=new WeakMap,B=new WeakMap,D=new WeakSet,V=function(t){f(this,Z,Rt).call(this);let e=s(this,a).fetch(this.options,t);return t!=null&&t.throwOnError||(e=e.catch(Ht)),e},$=new WeakSet,pt=function(){f(this,X,gt).call(this);const t=W(this.options.staleTime,s(this,a));if(Ut||s(this,y).isStale||!Dt(t))return;const n=$t(s(this,y).dataUpdatedAt,t)+1;l(this,T,setTimeout(()=>{s(this,y).isStale||this.updateResult()},n))},J=new WeakSet,bt=function(){var t;return(t=typeof this.options.refetchInterval=="function"?this.options.refetchInterval(s(this,a)):this.options.refetchInterval)!=null?t:!1},q=new WeakSet,yt=function(t){f(this,Y,mt).call(this),l(this,I,t),!(Ut||R(this.options.enabled,s(this,a))===!1||!Dt(s(this,I))||s(this,I)===0)&&l(this,U,setInterval(()=>{(this.options.refetchIntervalInBackground||Jt.isFocused())&&f(this,D,V).call(this)},s(this,I)))},G=new WeakSet,vt=function(){f(this,$,pt).call(this),f(this,q,yt).call(this,f(this,J,bt).call(this))},X=new WeakSet,gt=function(){s(this,T)&&(clearTimeout(s(this,T)),l(this,T,void 0))},Y=new WeakSet,mt=function(){s(this,U)&&(clearInterval(s(this,U)),l(this,U,void 0))},Z=new WeakSet,Rt=function(){const t=s(this,v).getQueryCache().build(s(this,v),this.options);if(t===s(this,a))return;const e=s(this,a);l(this,a,t),l(this,K,t.state),this.hasListeners()&&(e==null||e.removeObserver(this),t.addObserver(this))},at=new WeakSet,Nt=function(t){Gt.batch(()=>{t.listeners&&this.listeners.forEach(e=>{e(s(this,y))}),s(this,v).getQueryCache().notify({query:s(this,a),type:"observerResultsUpdated"})})},Bt);function Re(i,t){return R(t.enabled,i)!==!1&&i.state.data===void 0&&!(i.state.status==="error"&&t.retryOnMount===!1)}function jt(i,t){return Re(i,t)||i.state.data!==void 0&&Ot(i,t,t.refetchOnMount)}function Ot(i,t,e){if(R(t.enabled,i)!==!1&&W(t.staleTime,i)!=="static"){const n=typeof e=="function"?e(i):e;return n==="always"||n!==!1&&Ct(i,t)}return!1}function At(i,t,e,n){return(i!==t||R(n.enabled,i)===!1)&&(!e.suspense||i.state.status!=="error")&&Ct(i,e)}function Ct(i,t){return R(t.enabled,i)!==!1&&i.isStaleByTime(W(t.staleTime,i))}function Oe(i,t){return!ft(i.getCurrentResult(),t)}function Ce(i=""){if(!Xt())throw new Error("vue-query hooks can only be used inside setup() function or functions that support injection context.");const t=Zt(i),e=Yt(t);if(!e)throw new Error("No 'queryClient' found in Vue context, use 'VueQueryPlugin' to properly initialize the library.");return e}function _e(i,t,e){const n=Ce(),h=te(()=>{var w;const o=ae(t);typeof o.enabled=="function"&&(o.enabled=o.enabled());const _=n.defaultQueryOptions(o);return _._optimisticResults=(w=n.isRestoring)!=null&&w.value?"isRestoring":"optimistic",_}),r=new i(n,h.value),c=h.value.shallow?ee(r.getCurrentResult()):se(r.getCurrentResult());let b=()=>{};n.isRestoring&&nt(n.isRestoring,o=>{o||(b(),b=r.subscribe(_=>{Mt(c,_)}))},{immediate:!0});const d=()=>{r.setOptions(h.value),Mt(c,r.getCurrentResult())};nt(h,d),oe(()=>{b()});const m=(...o)=>(d(),c.refetch(...o)),tt=()=>new Promise((o,_)=>{let w=()=>{};const O=()=>{if(h.value.enabled!==!1){r.setOptions(h.value);const N=r.getOptimisticResult(h.value);N.isStale?(w(),r.fetchOptimistic(h.value).then(o,k=>{Lt(h.value.throwOnError,[k,r.getCurrentQuery()])?_(k):o(r.getCurrentResult())})):(w(),o(N))}};O(),w=nt(h,O)});nt(()=>c.error,o=>{if(c.isError&&!c.isFetching&&Lt(h.value.throwOnError,[o,r.getCurrentQuery()]))throw o});const p=h.value.shallow?ie(c):ne(c),Q=re(p);for(const o in c)typeof c[o]=="function"&&(Q[o]=c[o]);return Q.suspense=tt,Q.refetch=m,Q}function we(i,t){return _e(me,i)}function Se(i){return{queryFn:e=>lt(this,[e],function*({queryKey:t}){return ve(t[1])}),queryKey:["getFoo",i]}}const xe=he({__name:"vue-query",setup(i){ue(()=>lt(this,null,function*(){const r=yield ge();console.log("res: ",r)}));const{data:t,error:e,isLoading:n,refetch:h}=we(Se("菲鸽-vue-query"));return(r,c)=>{const b=de,d=ce,m=le("layout-default-uni");return ct(),Pt(m,null,{default:E(()=>[z(d,{class:"p-6 text-center"},{default:E(()=>[z(b,{type:"primary",size:"mini",class:"my-6 w-160px",onClick:dt(h)},{default:E(()=>[rt(" 发送请求 ")]),_:1},8,["onClick"]),z(d,{class:"h-16"},{default:E(()=>[dt(n)?(ct(),Pt(d,{key:0},{default:E(()=>[rt(" loading... ")]),_:1})):(ct(),fe(pe,{key:1},[z(d,{class:"text-xl"},{default:E(()=>[rt(" 请求数据如下 ")]),_:1}),z(d,{class:"text-green leading-8"},{default:E(()=>[rt(be(JSON.stringify(dt(t))),1)]),_:1})],64))]),_:1})]),_:1})]),_:1})}}}),Te=ye(xe,[["__scopeId","data-v-b4ba1da4"]]);export{Te as default};