Unverified Commit 1c45d744 authored by Zzm0809's avatar Zzm0809 Committed by GitHub

[Optimization][web] Optimize login page prompts (#3407)

parent 29cbffa2
...@@ -23,7 +23,6 @@ import { ...@@ -23,7 +23,6 @@ import {
setKeyToLocalStorage, setKeyToLocalStorage,
setLocalThemeToStorage setLocalThemeToStorage
} from '@/utils/function'; } from '@/utils/function';
import { l } from '@/utils/intl';
import { WarningMessageAsync } from '@/utils/messages'; import { WarningMessageAsync } from '@/utils/messages';
import { history } from '@@/core/history'; import { history } from '@@/core/history';
...@@ -36,9 +35,9 @@ export const gotoRedirectUrl = () => { ...@@ -36,9 +35,9 @@ export const gotoRedirectUrl = () => {
}, 10); }, 10);
}; };
export const redirectToLogin = async () => { export const redirectToLogin = (tipMsg: string) => {
//todo: 使用模态框提示, 但是目前会重复弹出,原因是接口每次都会调用,所以会出现重复弹出 //todo: 使用模态框提示, 但是目前会重复弹出,原因是接口每次都会调用,所以会出现重复弹出
await WarningMessageAsync(l('login.token.error')); WarningMessageAsync(tipMsg);
window.location.href = '/#/user/login'; window.location.href = '/#/user/login';
}; };
......
...@@ -74,7 +74,7 @@ const Login: React.FC = () => { ...@@ -74,7 +74,7 @@ const Login: React.FC = () => {
const currentTime = Date.now(); const currentTime = Date.now();
timeRemaining = expirationTime - currentTime; timeRemaining = expirationTime - currentTime;
// use setInterval to set a timer // use setInterval to set a timer
timer = setInterval(() => redirectToLogin(), timeRemaining); timer = setInterval(() => redirectToLogin(l('login.token.error')), timeRemaining);
} }
return () => { return () => {
clearTimeout(timer); clearTimeout(timer);
...@@ -141,7 +141,7 @@ const Login: React.FC = () => { ...@@ -141,7 +141,7 @@ const Login: React.FC = () => {
setLocalStorageOfToken(JSON.stringify(res)); setLocalStorageOfToken(JSON.stringify(res));
} else { } else {
// 如果没有获取到token信息,直接跳转到登录页 // 如果没有获取到token信息,直接跳转到登录页
redirectToLogin(); redirectToLogin(l('login.token.error'));
} }
}); });
} }
......
...@@ -230,12 +230,22 @@ const ResourceOverView: React.FC<connect> = (props) => { ...@@ -230,12 +230,22 @@ const ResourceOverView: React.FC<connect> = (props) => {
const handleModalSubmit = async (value: Partial<ResourceInfo>) => { const handleModalSubmit = async (value: Partial<ResourceInfo>) => {
const { id: pid } = resourceState.rightClickedNode; const { id: pid } = resourceState.rightClickedNode;
if (editModal === 'createFolder') { if (editModal === 'createFolder') {
await handleOption(API_CONSTANTS.RESOURCE_CREATE_FOLDER, l('right.menu.createFolder'), { await handleOption(
API_CONSTANTS.RESOURCE_CREATE_FOLDER,
l('right.menu.createFolder'),
{
...value, ...value,
pid pid
}, ()=> handleModalCancel()); },
() => handleModalCancel()
);
} else if (editModal === 'rename') { } else if (editModal === 'rename') {
await handleOption(API_CONSTANTS.RESOURCE_RENAME, l('right.menu.rename'), { ...value, pid },()=> handleModalCancel()); await handleOption(
API_CONSTANTS.RESOURCE_RENAME,
l('right.menu.rename'),
{ ...value, pid },
() => handleModalCancel()
);
} }
}; };
const handleUploadCancel = async () => { const handleUploadCancel = async () => {
......
...@@ -31,7 +31,9 @@ enum ErrorCode { ...@@ -31,7 +31,9 @@ enum ErrorCode {
ERROR = 1, ERROR = 1,
EXCEPTION = 5, EXCEPTION = 5,
PARAMS_ERROR = 6, PARAMS_ERROR = 6,
AUTHORIZE_ERROR = 7 AUTHORIZE_ERROR = 7,
SERVER_ERROR = 504,
UNAUTHORIZED = 401
} }
// Response data format agreed upon with the backend // Response data format agreed upon with the backend
...@@ -88,6 +90,13 @@ export const errorConfig: RequestConfig = { ...@@ -88,6 +90,13 @@ export const errorConfig: RequestConfig = {
// Error reception and handling // Error reception and handling
errorHandler: (error: any, opts: any) => { errorHandler: (error: any, opts: any) => {
if (opts?.skipErrorHandler) throw error; if (opts?.skipErrorHandler) throw error;
function processNotification(error: any, isEnableTips: string = 'false') {
if (getValueFromLocalStorage(ENABLE_MODEL_TIP) == isEnableTips) {
ErrorNotification(error.message, error.code);
}
}
//The error thrown by our errorThrower. //The error thrown by our errorThrower.
if (error.name === 'BizError') { if (error.name === 'BizError') {
const errorInfo: ResponseStructure = error.info; const errorInfo: ResponseStructure = error.info;
...@@ -97,12 +106,14 @@ export const errorConfig: RequestConfig = { ...@@ -97,12 +106,14 @@ export const errorConfig: RequestConfig = {
} else if (error.response) { } else if (error.response) {
//The request was successfully sent and the server also responded with a status code, but the status code exceeded the range of 2xx //The request was successfully sent and the server also responded with a status code, but the status code exceeded the range of 2xx
//Authentication error, redirect to login page //Authentication error, redirect to login page
if (error.response.status === 401) { if (error.response.status === ErrorCode.UNAUTHORIZED) {
redirectToLogin(); redirectToLogin(error.message);
} else if (error.response.status === ErrorCode.SERVER_ERROR) {
processNotification(error);
//Note: when the server is not available or the network is disconnected, redirect to login page
redirectToLogin(error.message);
} else { } else {
if (getValueFromLocalStorage(ENABLE_MODEL_TIP) == 'true') { processNotification(error, 'true');
ErrorNotification(error.message, error.code);
}
} }
} else if (error.request) { } else if (error.request) {
//The request has been successfully initiated, but no response has been received //The request has been successfully initiated, but no response has been received
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment