[improvement](semantic-fe) Added parameter compatibility for network requests in different modes

This commit is contained in:
tristanliu
2023-06-21 11:10:07 +08:00
parent 693fc03c6f
commit 9c9d7382fe
12 changed files with 42 additions and 42 deletions

View File

@@ -9,7 +9,7 @@ export type LoginParamsType = {
};
export async function queryToken(code: string) {
return request(`${process.env.API_BASE_URL}user/ioaLoginCallback`, {
return request(`/davinciapi/login/tmeloginCallback`, {
params: { code },
});
}

View File

@@ -20,6 +20,7 @@ const authHeaderInterceptor = (url: string, options: RequestOptionsInit) => {
const token = query[TOKEN_KEY] || localStorage.getItem(TOKEN_KEY);
if (token) {
headers.Authorization = `Bearer ${token}`;
headers.auth = `Bearer ${token}`;
localStorage.setItem(TOKEN_KEY, token);
}
@@ -31,25 +32,19 @@ const authHeaderInterceptor = (url: string, options: RequestOptionsInit) => {
};
const responseInterceptor = async (response: Response) => {
const data: Result<any> = await response?.clone()?.json?.();
if (Number(data.code) === 403) {
history.push('/login');
return response;
}
const redirect = response.headers.get('redirect'); // 若HEADER中含有REDIRECT说明后端想重定向
if (redirect === 'REDIRECT') {
localStorage.removeItem(TOKEN_KEY);
let win: any = window;
while (win !== win.top) {
win = win.top;
}
if (!/fromExternal=true/.test(win.location.search)) {
localStorage.setItem(FROM_URL_KEY, win.location.href);
}
const win: any = window;
// 将后端重定向的地址取出来,使用win.location.href去实现重定向的要求
const contextpath = response.headers.get('contextpath');
win.location.href = contextpath;
} else {
const data: Result<any> = await response?.clone()?.json?.();
if (Number(data.code) === 403) {
history.push('/login');
return response;
}
}
return response;