useAsync.24db85a6.js 844 B

1
  1. import{a as z}from"./useNav.afbe69e0.js";import{p as g,a3 as E,f as H,aL as N}from"./index.4d3e3847.js";function S(){const{logout:u}=z();function i({code:c,message:s,handler:o,errorHandler:t}){const e=Number(c);e===0?o():e>=100&&e<=140?u():t?t():N.error(s)}return i}function A({initalData:u,initalPagination:i,isList:c=!1,prop:s="data",success:o}={}){let t;const e=g(u),l=g(!1),d=g(!1),r=E(i||{}),P=S(),m=a=>e.value=a,f=a=>d.value=a;function h(){const{pageSize:a,currentPage:n}=r;return{size:a,page:n}}function v(a){return f(!0),t=()=>v(a),a.then(n=>{f(!1);const{code:p,message:y}=n;String(p)!=="0"&&(l.value=!0),P({code:p,message:y,handler:()=>{m(c?n[s].list:n[s]),l.value=!1,r&&(r.total=e.count),o&&o(H(e))}})})}return{run:v,data:e,retry:t,setData:m,loading:d,isError:l,setloading:f,pagination:r,getPaginationParams:h}}export{A as a,S as u};