Skip to content

Commit

Permalink
fix: 修复init接口返回401时页面未跳转到登录页的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
luofann committed Aug 21, 2023
1 parent 942d10e commit 961949f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions frontend/pc/src/utils/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ instance.interceptors.request.use(
instance.interceptors.response.use(
(response) => {
if (response.config.url === 'init/') {
if (response.status === 401) {
const { login_url } = response.data;
const url = `${login_url.split('c_url=')[0]}c_url=${encodeURIComponent(location.href)}`;
response.data.login_url = url;
window.open(url, '_self');
return;
}
if ('IS_ITSM_ADMIN' in response.data.data) {
const { DEFAULT_PROJECT, IS_ITSM_ADMIN, all_access, chname, username } = response.data.data;
window.DEFAULT_PROJECT = DEFAULT_PROJECT;
Expand All @@ -92,12 +99,6 @@ instance.interceptors.response.use(
window.username = username;
return response;
}
if (response.status === 401) {
const { login_url } = response.data;
const url = `${login_url.split('c_url=')[0]}c_url=${encodeURIComponent(location.href)}`;
response.data.login_url = url;
window.open(url, '_self');
}
}
// status >= 200 && status <= 505
if (response.status !== 499 && 'result' in response.data && !response.data.result && 'message' in response.data) {
Expand Down

0 comments on commit 961949f

Please sign in to comment.