chore: first login to default page by localhost

This commit is contained in:
jialin
2025-02-25 15:04:05 +08:00
parent 0f7d04e0b9
commit e1959f74aa
3 changed files with 21 additions and 3 deletions
+19 -1
View File
@@ -6,10 +6,28 @@ import {
queryVersionInfo,
updateCheck
} from '@/services/profile/apis';
import { isOnline } from '@/utils';
import {
IS_FIRST_LOGIN,
readState,
writeState
} from '@/utils/localstore/index';
import { RequestConfig, history } from '@umijs/max';
const loginPath = '/login';
// only for the first login and access from http://localhost
const checkDefaultPage = async (userInfo: any) => {
const isFirstLogin = await readState(IS_FIRST_LOGIN);
if (isFirstLogin === null && isOnline()) {
writeState(IS_FIRST_LOGIN, true);
if (userInfo && userInfo?.is_admin) {
history.push('/models/list');
}
}
};
// runtime configuration
export async function getInitialState(): Promise<{
fetchUserInfo: () => Promise<Global.UserInfo>;
@@ -62,7 +80,7 @@ export async function getInitialState(): Promise<{
if (![loginPath].includes(location.pathname)) {
const userInfo = await fetchUserInfo();
checkDefaultPage(userInfo);
return {
fetchUserInfo,
currentUser: userInfo