Files
fe_service_ebtp_frontend/src/pages/401.tsx

68 lines
2.0 KiB
TypeScript
Raw Normal View History

import { logoutTokenApi } from '@/services/login';
import { getURLInformation, isNotEmpty } from '@/utils/CommonUtils';
import { getSessionRoleData } from '@/utils/session';
import { Button, Result, Typography } from 'antd';
import React, { useEffect, useState } from 'react';
import { history } from 'umi';
2022-03-10 14:24:13 +08:00
const messageMap = {
2022-03-10 14:24:13 +08:00
401: '您的用户信息有误,请联系管理员',
402: '您的用户角色信息缺失,请联系管理员',
403: '您的用户角色信息异常,请重新登录',
2022-03-10 14:24:13 +08:00
90401: '您的登录已超时,请重新登录',
404: '系统错误,请联系管理员',
2022-12-28 17:29:12 +08:00
405: '您的用户无权限访问'
2022-03-10 14:24:13 +08:00
};
const RequestTimeoutPage: React.FC<{}> = () => {
const code: any = getURLInformation('code') == null ? '404' : getURLInformation('code');
const { Text } = Typography;
const [time, setTime] = useState<number>(10);
const roleData = getSessionRoleData();
2023-02-21 11:08:04 +08:00
// const token = sessionStorage.getItem('Authorization');
useEffect(() => {
let timeInteval: any
if (code == 402 && isNotEmpty(roleData)) {
timeInteval = setInterval(() => { // 倒计时
setTime(n => {
if (n == 1) {
clearInterval(timeInteval)
redirect();
}
return n - 1;
})
}, 1000);
} else {
clearInterval(timeInteval);
}
return () => {
clearInterval(timeInteval);
}
}, []);
const redirect = () => {
if (isNotEmpty(roleData)) {
history.replace({
pathname: '/Dashboard',
})
}
}
const redirectLogin = () => {
2023-02-21 11:08:04 +08:00
logoutTokenApi().then(res => {
history.replace({
pathname: '/userformal/login',
})
})
}
2022-03-10 14:24:13 +08:00
return (
<Result
title={messageMap[code]}
extra={isNotEmpty(roleData) && code == 402 ? <Text type="secondary" strong>{time}</Text> : code == 403 ? <Button type="primary" onClick={() => redirectLogin()}></Button> : null}
2022-03-10 14:24:13 +08:00
/>
);
};
export default RequestTimeoutPage;