Skip to content

Commit a75d62f

Browse files
author
Halsey
committed
feat: 🚀 请求全局 loading 更改为可配置
1 parent 675aed8 commit a75d62f

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

src/api/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ class RequestHttp {
3535
*/
3636
this.service.interceptors.request.use(
3737
(config: AxiosRequestConfig) => {
38+
console.log(config);
3839
// * 将当前请求添加到 pending 中
3940
axiosCanceler.addPending(config);
40-
showFullScreenLoading();
41+
// * 如果当前请求不需要显示 loading(在headers中指定 notLoading:true)
42+
config.headers!.notLoading || showFullScreenLoading();
4143
const token: string = globalStore.token;
4244
return { ...config, headers: { "x-access-token": token } };
4345
},

src/api/modules/login.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import http from "@/api";
88
*/
99
// * 用户登录接口
1010
export const loginApi = (params: Login.ReqLoginForm) => {
11+
// return http.post<Login.ResLogin>(PORT1 + `/login`, params, { headers: { notLoading: true } });
1112
return http.post<Login.ResLogin>(PORT1 + `/login`, params);
1213
};
1314

src/api/modules/user.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const addUser = (params: { id: string }) => {
1919

2020
// * 批量添加用户
2121
export const BatchAddUser = (params: any) => {
22+
// 其实 headers 中的 Content-Type 可以不写,请求可以自动判断,这里为了演示,写了一下
2223
return http.post(PORT1 + `/user/import`, params, { headers: { "Content-Type": ContentTypeEnum.FORM_DATA } });
2324
};
2425

0 commit comments

Comments
 (0)