chore: 构建目录
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
export default {
|
||||
"000": "操作太频繁,请勿重复请求",
|
||||
401: "当前操作没有权限,请退出重试",
|
||||
403: "当前操作没有权限,请退出重试",
|
||||
404: "资源不存在",
|
||||
417: "未绑定登录账号,请使用密码登录后绑定",
|
||||
423: "演示环境不能操作,如需了解联系",
|
||||
426: "用户名不存在或密码错误",
|
||||
428: "验证码错误,请重新输入",
|
||||
429: "请求过频繁",
|
||||
479: "演示环境,没有权限操作",
|
||||
default: "系统未知错误,请反馈给管理员",
|
||||
};
|
||||
@@ -1,34 +0,0 @@
|
||||
const config = {
|
||||
/**
|
||||
* api请求基础路径
|
||||
*/
|
||||
base_url: {
|
||||
// 开发环境接口前缀
|
||||
dev: import.meta.env.VITE_APP_BASEAPI,
|
||||
// 打包生产环境接口前缀
|
||||
pro: window.location.protocol + "//" + window.location.hostname + ":19001",
|
||||
},
|
||||
|
||||
/**
|
||||
* 接口请求前缀
|
||||
*/
|
||||
pre_interface: import.meta.env.VITE_APP_BASEAPI,
|
||||
|
||||
/**
|
||||
* 接口成功返回状态码
|
||||
*/
|
||||
result_code: "0000",
|
||||
|
||||
/**
|
||||
* 接口请求超时时间
|
||||
*/
|
||||
request_timeout: 60000,
|
||||
|
||||
/**
|
||||
* 默认接口请求类型
|
||||
* 可选值:application/x-www-form-urlencoded multipart/form-data
|
||||
*/
|
||||
default_headers: "application/json",
|
||||
};
|
||||
|
||||
export { config };
|
||||
@@ -1,89 +0,0 @@
|
||||
import axios from "axios";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { config } from "@/config/axios/config";
|
||||
import { Session } from "@/utils/storage";
|
||||
import useAuths from "@/hooks/useAuths";
|
||||
|
||||
const { getToken } = useAuths();
|
||||
|
||||
const { request_timeout } = config;
|
||||
export const PATH_URL = import.meta.env.VITE_APP_BASEAPI;
|
||||
|
||||
// 配置新建一个 axios 实例
|
||||
const service = axios.create({
|
||||
baseURL: PATH_URL, // api 的 base_url
|
||||
timeout: request_timeout, // 请求超时时间
|
||||
headers: { "Content-Type": "application/json" },
|
||||
hideerror: false, //是否在底层显示错误信息
|
||||
});
|
||||
|
||||
// 添加请求拦截器
|
||||
service.interceptors.request.use(
|
||||
(config) => {
|
||||
// 在发送请求之前做些什么 token
|
||||
const token = getToken();
|
||||
if (token) {
|
||||
config.headers["Authorization"] = `Bearer ${token}`;
|
||||
}
|
||||
if (Session.get("tenantId")) {
|
||||
config.headers["TenantId"] = Session.get("tenantId");
|
||||
}
|
||||
return config;
|
||||
},
|
||||
(error) => {
|
||||
// 对请求错误做些什么
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
// 添加响应拦截器
|
||||
service.interceptors.response.use(
|
||||
(response) => {
|
||||
return Promise.resolve(response);
|
||||
},
|
||||
(error) => {
|
||||
// 对响应错误做点什么
|
||||
if (error.message.indexOf("timeout") != -1) {
|
||||
ElMessage({
|
||||
type: "danger",
|
||||
message: "网络超时",
|
||||
});
|
||||
} else if (error.message == "Network Error") {
|
||||
ElMessage({
|
||||
type: "danger",
|
||||
message: "网络连接错误",
|
||||
});
|
||||
} else {
|
||||
const res = error.response || {};
|
||||
const status = Number(res.status) || 200;
|
||||
const message = res.data.error.message;
|
||||
if (status === 401) {
|
||||
ElMessage({
|
||||
type: "danger",
|
||||
message,
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (status !== 200) {
|
||||
if (status >= 500) {
|
||||
ElMessage({
|
||||
type: "danger",
|
||||
message: "网络开小差了,请稍后再试",
|
||||
});
|
||||
return Promise.reject(new Error(message));
|
||||
}
|
||||
// 避开找不到后端接口的提醒
|
||||
if (status !== 404) {
|
||||
ElMessage({
|
||||
type: "danger",
|
||||
message,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return Promise.reject(new Error(error));
|
||||
}
|
||||
);
|
||||
|
||||
// 导出 axios 实例
|
||||
export default service;
|
||||
Reference in New Issue
Block a user