feat: 🚀 token无感刷新

This commit is contained in:
2025-03-29 16:12:35 +08:00
parent e0f8d6c574
commit 2d7470c133
20 changed files with 32 additions and 27 deletions

View File

@@ -6,7 +6,7 @@ import { showFullScreenLoading, tryHideFullScreenLoading } from "@/config/servic
import { ElMessage } from "element-plus";
import { ResultData } from "@/api/interface";
import { ResultEnum } from "@/enums/httpEnum";
import { checkStatus } from "./helper/checkStatus";
// import { checkStatus } from "./helper/checkStatus";
import { useUserStore } from "@/stores/modules/user";
import router from "@/routers";
//获取导出表格name
@@ -54,7 +54,7 @@ class RequestHttp {
// 当前请求不需要显示 loading在 api 服务中通过指定的第三个参数: { noLoading: true } 来控制
config.noLoading || showFullScreenLoading();
if (config.headers && typeof config.headers.set === "function") {
config.headers.set("Authorization", "Bearer" + " " + userStore.token);
config.headers.set("Authorization", userStore.token);
}
return config;
},
@@ -74,7 +74,7 @@ class RequestHttp {
//获取导出表格名称
getDispositionName(response);
// 获取响应头中的 Authorization 信息
const authorization = response.headers["Authorization"];
const authorization = response.headers["authorization"];
if (authorization) {
// 可以在这里更新用户的 token 信息
const userStore = useUserStore();
@@ -103,7 +103,7 @@ class RequestHttp {
// 根据服务器响应的错误状态码,做不同的处理
if (response) {
console.log("error-走到了这里", response.status);
checkStatus(response.status, response.data);
// checkStatus(response.status, response.data);
}
// 服务器结果都没有返回(可能服务器错误可能客户端断网),断网处理:可以跳转到断网页面
if (!window.navigator.onLine) router.replace("/500");

View File

@@ -36,3 +36,7 @@ export const getProductListSortApi = (params: any) => {
const { id, sort } = params;
return http.post<any>(`${PRODUCT}/sort/${id}`, { sort });
};
// getProductCategoryListApi
export const getProductCategoryListApi = () => {
return http.get<any>(`/product/categorys`);
};