局长信箱-互联网端管理-前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1 lines
1.6 KiB

import{Z as h,E as y}from"./index-BSiuwHTj.js";const l={set(a,e){try{window.localStorage.setItem(a,e)}catch{}},get(a){try{return window.localStorage.getItem(a)}catch{return null}},remove(a){window.localStorage.removeItem(a)}},m="token";function E(){return l.get(m)}function S(a){return l.set(m,a)}var i={VITE_BASE:"/admin",VITE_API_URL:"/admin-api"};const s="/admin-api";function b(a){return a.method="GET",f(a.url,a)}function w(a){return a.method="POST",f(a.url,a)}function _(a){return a.method="DELETE",f(a.url,a)}let n=!1;function f(a,e){const d={"Content-Type":"application/json",Authorization:E()};let t;return e!=null&&e.params&&Object.keys(e.params).length>0&&(e.method==="GET"?e.query=e.params:t=JSON.stringify(e.params)),e!=null&&e.query&&(a+=(a.indexOf("?")>-1?"":"?")+new URLSearchParams(e.query).toString()),e!=null&&e.body&&(e.body==="string"||e.body instanceof FormData?t=e.body:Object.keys(e.body).length>0&&(t=JSON.stringify(e.body))),new Promise((u,c)=>{fetch(`${s}${a}`,{method:e.method,body:t,headers:{...d,...e.headers}}).then(r=>{if(r.status!==413)return r.json()}).then(r=>{if(r.code===200)u(r.data);else{let g=r.msg;if(r.code===401){if(a==="/admin/self"){feedback.msgError("登录状态已过期"),c(r);return}n||(n=!0,h.confirm("登录状态已过期,您可以继续留在该页面,或者重新登录","温馨提示",{confirmButtonText:"重新登录",cancelButtonText:"取消",type:"warning"}).then(()=>{n=!1,location.href=i.VITE_BASE+"#/login"}).catch(()=>{n=!1})),c(r);return}y.error(g||"系统异常"),c(r)}})})}export{E as a,l as c,_ as d,b as g,w as p,S as s};