修改系统异常提醒

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,13 +168,8 @@ input:-webkit-autofill:active {
.ant-layout-content.ant-pro-basicLayout-content.ant-pro-basicLayout-has-header { .ant-layout-content.ant-pro-basicLayout-content.ant-pro-basicLayout-has-header {
margin-bottom: 0 !important; margin-bottom: 0 !important;
} min-height: calc(100vh - 72px);
min-height: calc(100vh - var(--vh-offset, 0px) - 72px);
@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 { .Resizer {

View File

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

View File

@ -1,6 +1,7 @@
import { extend } from 'umi-request'; import { extend } from 'umi-request';
import { message } from 'antd'; import { message } from 'antd';
import config from './config'; import config from './config';
import { history } from 'umi';
message.config({ message.config({
duration: 1.5, duration: 1.5,
@ -12,10 +13,17 @@ const errorHandler = function (error: any) {
const msg = error.data const msg = error.data
? error.data.message || error.data ? error.data.message || error.data
: error.response.statusText; : error.response.statusText;
if (error.response.status !== 401 && error.response.status !== 502) { const responseStatus = error.response.status;
message.error(msg); 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 { } else {
console.log(error.response); message.error(msg);
} }
} else { } else {
console.log(error.message); console.log(error.message);