增加初始化过程

This commit is contained in:
hanhh
2021-10-03 20:58:55 +08:00
parent bd1ca7e975
commit 14b20873c7
18 changed files with 714 additions and 223 deletions
+6
View File
@@ -18,6 +18,12 @@ export default {
hideInMenu: true,
component: '@/pages/login/index',
},
{
name: '初始化',
path: '/initialization',
hideInMenu: true,
component: '@/pages/initialization/index',
},
{
path: '/crontab',
name: '定时任务',
+4
View File
@@ -247,4 +247,8 @@
::placeholder {
opacity: 0.5 !important;
}
.ant-select-selection-placeholder {
opacity: 0.5 !important;
}
}
+32 -8
View File
@@ -22,6 +22,7 @@ export default function (props: any) {
const theme = useTheme();
const [user, setUser] = useState<any>();
const [loading, setLoading] = useState<boolean>(true);
const [systemInfo, setSystemInfo] = useState<{ isInitialized: boolean }>();
const logout = () => {
request.post(`${config.apiPrefix}logout`).then(() => {
@@ -30,6 +31,22 @@ export default function (props: any) {
});
};
const getSystemInfo = () => {
request.get(`${config.apiPrefix}system`).then(({ code, data }) => {
if (code === 200) {
setSystemInfo(data);
if (!data.isInitialized) {
history.push('/initialization');
setLoading(false);
} else {
getUser();
}
} else {
message.error(data);
}
});
};
const getUser = (needLoading = true) => {
needLoading && setLoading(true);
request.get(`${config.apiPrefix}user`).then(({ code, data }) => {
@@ -63,19 +80,21 @@ export default function (props: any) {
};
useEffect(() => {
const isAuth = localStorage.getItem(config.authKey);
if (!isAuth) {
history.push('/login');
}
vhCheck();
}, []);
useEffect(() => {
if (!user) {
if (systemInfo && systemInfo.isInitialized && !user) {
getUser();
}
}, [props.location.pathname]);
useEffect(() => {
if (!systemInfo) {
getSystemInfo();
}
}, [systemInfo]);
useEffect(() => {
setTheme();
}, [theme.theme]);
@@ -92,8 +111,13 @@ export default function (props: any) {
}
}, []);
if (props.location.pathname === '/login') {
return props.children;
if (['/login', '/initialization'].includes(props.location.pathname)) {
document.title = `${
(config.documentTitleMap as any)[props.location.pathname]
} - 控制面板`;
if (systemInfo) {
return props.children;
}
}
const isFirefox = navigator.userAgent.includes('Firefox');
@@ -148,7 +172,7 @@ export default function (props: any) {
];
}}
pageTitleRender={(props, pageName, info) => {
if (info) {
if (info && typeof info.pageName === 'string') {
return `${info.pageName} - 控制面板`;
}
return '控制面板';