useAsync.df7387ce.js 843 B

1
  1. import{u as z}from"./useNav.5e73c372.js";import{r as g,W as E,u as H,an as N}from"./index.4d061c66.js";function S(){const{logout:u}=z();function i({code:c,message:s,handler:o,errorHandler:a}){const e=Number(c);e===0?o():e>=100&&e<=140?u():a?a():N.error(s)}return i}function A({initalData:u,initalPagination:i,isList:c=!1,prop:s="data",success:o}={}){let a;const e=g(u),l=g(!1),d=g(!1),r=E(i||{}),P=S(),m=t=>e.value=t,f=t=>d.value=t;function h(){const{pageSize:t,currentPage:n}=r;return{size:t,page:n}}function v(t){return f(!0),a=()=>v(t),t.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:a,setData:m,loading:d,isError:l,setloading:f,pagination:r,getPaginationParams:h}}export{A as a,S as u};