import{s as e}from"./index-Mgun2LFs.js";import{t}from"./axios-BvjS45eU.js";var n=t.create({baseURL:`/api/v1`,timeout:15e3,headers:{"Content-Type":`application/json`,Accept:`application/json`}});n.interceptors.request.use(e=>{let t=localStorage.getItem(`token`);return t&&(e.headers.Authorization=`Bearer ${t}`),e},e=>Promise.reject(e)),n.interceptors.response.use(t=>{let n=t.data;return n.code===0?n:n.code>=40100&&n.code<=40199?(localStorage.removeItem(`token`),localStorage.removeItem(`userInfo`),e.error(`登录已过期，请重新登录`),window.location.href=`/login`,Promise.reject(Error(n.message||`未授权`))):(e.error(n.message||`请求失败`),Promise.reject(Error(n.message||`请求失败`)))},t=>{if(t.response){let n=t.response.status;if(n===401)return localStorage.removeItem(`token`),localStorage.removeItem(`userInfo`),e.error(`登录已过期，请重新登录`),window.location.href=`/login`,Promise.reject(t);if(n===403)return e.error(`无权限访问`),Promise.reject(t);if(n===404)return e.error(`请求的资源不存在`),Promise.reject(t);if(n>=500)return e.error(`服务器内部错误，请稍后重试`),Promise.reject(t)}return t.code===`ECONNABORTED`||t.message.includes(`timeout`)?(e.error(`请求超时，请检查网络连接`),Promise.reject(t)):(e.error(t.message||`网络错误`),Promise.reject(t))});export{n as t};