修改系统异常提醒

This commit is contained in:
hanhh 2021-09-13 00:12:44 +08:00
parent ecee9e2acd
commit 2d7e525024
3 changed files with 39 additions and 32 deletions

View File

@ -168,14 +168,9 @@ input:-webkit-autofill:active {
.ant-layout-content.ant-pro-basicLayout-content.ant-pro-basicLayout-has-header {
margin-bottom: 0 !important;
}
@media (min-width: 768px) {
.ant-layout-content.ant-pro-basicLayout-content.ant-pro-basicLayout-has-header {
min-height: calc(100vh - 72px);
min-height: calc(100vh - var(--vh-offset, 0px) - 72px);
}
}
.Resizer {
background: #fff;

View File

@ -15,11 +15,13 @@ import './index.less';
import vhCheck from 'vh-check';
import { version, changeLog } from '../version';
import { useCtx, useTheme } from '@/utils/hooks';
import { message } from 'antd';
export default function (props: any) {
const ctx = useCtx();
const theme = useTheme();
const [user, setUser] = useState<any>();
const [loading, setLoading] = useState<boolean>(true);
const logout = () => {
request.post(`${config.apiPrefix}logout`).then(() => {
@ -28,30 +30,25 @@ export default function (props: any) {
});
};
const getUser = () => {
request
.get(`${config.apiPrefix}user`)
.then((data) => {
if (data.data.username) {
setUser(data.data);
const getUser = (needLoading = true) => {
needLoading && setLoading(true);
request.get(`${config.apiPrefix}user`).then(({ code, data }) => {
if (code === 200 && data.username) {
setUser(data);
localStorage.setItem('isLogin', 'true');
if (props.location.pathname === '/') {
history.push('/crontab');
}
} else {
message.error(data);
}
})
.catch((e) => {
if (e.response && e.response.status === 401) {
localStorage.removeItem(config.authKey);
history.push('/login');
}
needLoading && setLoading(false);
});
};
useEffect(() => {
if (!user) {
getUser();
}
}, [props.location.pathname]);
const reloadUser = () => {
getUser(false);
};
useEffect(() => {
const isAuth = localStorage.getItem(config.authKey);
@ -64,6 +61,12 @@ export default function (props: any) {
document.title = '控制面板';
}, []);
useEffect(() => {
if (!user) {
getUser();
}
}, [props.location.pathname]);
useEffect(() => {
const _theme = localStorage.getItem('qinglong_dark_theme') || 'auto';
setFetchMethod(window.fetch);
@ -89,6 +92,7 @@ export default function (props: any) {
return (
<ProLayout
selectedKeys={[props.location.pathname]}
loading={loading}
title={
<>
@ -136,7 +140,7 @@ export default function (props: any) {
...ctx,
...theme,
user,
reloadUser: getUser,
reloadUser,
});
})}
</ProLayout>

View File

@ -1,6 +1,7 @@
import { extend } from 'umi-request';
import { message } from 'antd';
import config from './config';
import { history } from 'umi';
message.config({
duration: 1.5,
@ -12,10 +13,17 @@ const errorHandler = function (error: any) {
const msg = error.data
? error.data.message || error.data
: error.response.statusText;
if (error.response.status !== 401 && error.response.status !== 502) {
message.error(msg);
const responseStatus = error.response.status;
if (responseStatus === 502) {
message.error('服务异常请手动执行ql check检查服务状态');
} else if (responseStatus === 401) {
if (history.location.pathname !== '/login') {
message.error('登录已过期,请重新登录');
localStorage.removeItem(config.authKey);
history.push('/login');
}
} else {
console.log(error.response);
message.error(msg);
}
} else {
console.log(error.message);