11
Some checks failed
Node CI / build (14.x, macOS-latest) (push) Has been cancelled
Node CI / build (14.x, ubuntu-latest) (push) Has been cancelled
Node CI / build (14.x, windows-latest) (push) Has been cancelled
Node CI / build (16.x, macOS-latest) (push) Has been cancelled
Node CI / build (16.x, ubuntu-latest) (push) Has been cancelled
Node CI / build (16.x, windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
coverage CI / build (push) Has been cancelled
Node pnpm CI / build (16.x, macOS-latest) (push) Has been cancelled
Node pnpm CI / build (16.x, ubuntu-latest) (push) Has been cancelled
Node pnpm CI / build (16.x, windows-latest) (push) Has been cancelled

This commit is contained in:
francis-fh
2026-06-05 13:58:56 +08:00
parent e467fcc2cf
commit fdd80c6cd1
6 changed files with 86 additions and 28 deletions

View File

@@ -124,8 +124,8 @@ export default defineConfig({
* @description 配置 <head> 中额外的 script
*/
headScripts: [
// 解决首次加载时白屏的问题
{ src: '/shihezi/scripts/loading.js', async: true },
// 同步执行,在 umi 主包解析前注入 #root 占位,避免首屏纯白
{ src: '/shihezi/scripts/loading.js' },
],
//================ pro 插件配置 =================
presets: ['umi-presets-pro'],

View File

@@ -14,6 +14,10 @@
margin: 0;
padding: 0;
}
body,
#root {
background-color: #f0f4f8;
}
#root {
background-repeat: no-repeat;
background-size: 100% auto;

View File

@@ -10,6 +10,7 @@ import {
exchangeThirdPartyCredential,
isThirdPartyTransitionPage,
} from './utils/thirdPartyLogin';
import { shouldSkipManagementBootstrap } from './utils/routeContext';
import { saveGetInfoCache } from './utils/jobPortalAuth';
import {
getRemoteMenu,
@@ -73,19 +74,8 @@ export async function getInitialState(): Promise<{
}
return undefined;
};
// 如果不是登录页面,执行
const { location } = history;
// 排除登录页面、过渡页面和求职者页面(考虑基础路径 /shihezi/
const isTransitionPage = location.pathname === '/' ||
location.pathname === '/login-tow' ||
location.pathname === '/shihezi/' ||
location.pathname === '/shihezi/login-tow';
// 排除求职者相关页面
const isJobPortalPage = location.pathname.startsWith('/job-portal') ||
location.pathname.startsWith('/shihezi/job-portal');
if (location.pathname !== PageEnum.LOGIN && !isTransitionPage && !isJobPortalPage) {
if (!shouldSkipManagementBootstrap(location.pathname)) {
const currentUser = await fetchUserInfo();
return {
fetchUserInfo,
@@ -135,16 +125,10 @@ export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) =
onPageChange: () => {
const { location } = history;
// 如果没有登录,重定向到 login但排除过渡页面和求职者页面考虑基础路径 /shihezi/
const isTransitionPage = location.pathname === '/' ||
location.pathname === '/login-tow' ||
location.pathname === '/shihezi/' ||
location.pathname === '/shihezi/login-tow';
// 排除求职者相关页面
const isJobPortalPage = location.pathname.startsWith('/job-portal') ||
location.pathname.startsWith('/shihezi/job-portal');
if (!initialState?.currentUser && location.pathname !== PageEnum.LOGIN && !isTransitionPage && !isJobPortalPage) {
if (
!initialState?.currentUser &&
!shouldSkipManagementBootstrap(location.pathname)
) {
history.push(PageEnum.LOGIN);
}
},
@@ -205,11 +189,12 @@ export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) =
export async function onRouteChange({ clientRoutes, location }: { clientRoutes: any; location: any }) {
const menus = getRemoteMenu();
// console.log('onRouteChange', clientRoutes, location, menus);
// 如果路由信息未加载,尝试重新获取路由信息
const token = getAccessToken();
if (menus === null && location.pathname !== PageEnum.LOGIN && token) {
if (
menus === null &&
token &&
!shouldSkipManagementBootstrap(location.pathname)
) {
console.log('检测到路由信息未加载,正在重新获取路由信息...');
// 重新获取路由信息,而不是刷新页面
@@ -248,6 +233,11 @@ export async function render(oldRender: () => void) {
}
}
if (shouldSkipManagementBootstrap(pathname)) {
oldRender();
return;
}
const token = getAccessToken();
if (!token || token.length === 0) {
oldRender();

24
src/loading.less Normal file
View File

@@ -0,0 +1,24 @@
.job-portal-route-loading {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
background: #f0f4f8;
.ant-spin .ant-spin-dot-item {
background-color: #1890ff;
}
&__title {
margin: 20px 0 0;
font-size: 16px;
color: #1a1a1a;
}
&__hint {
margin: 8px 0 0;
font-size: 14px;
color: #8c8c8c;
}
}

21
src/loading.tsx Normal file
View File

@@ -0,0 +1,21 @@
import { PageLoading } from '@ant-design/pro-components';
import { Spin } from 'antd';
import { isJobPortalPage } from '@/utils/routeContext';
import './loading.less';
/** 路由 chunk 加载时的占位Umi 约定入口) */
export default function RouteLoading() {
const pathname = typeof window !== 'undefined' ? window.location.pathname : '';
if (isJobPortalPage(pathname)) {
return (
<div className="job-portal-route-loading">
<Spin size="large" />
<p className="job-portal-route-loading__title"></p>
<p className="job-portal-route-loading__hint"></p>
</div>
);
}
return <PageLoading />;
}

19
src/utils/routeContext.ts Normal file
View File

@@ -0,0 +1,19 @@
import { PageEnum } from '@/enums/pagesEnums';
import { isThirdPartyTransitionPage } from '@/utils/thirdPartyLogin';
/** 求职者门户路由(含 base /shihezi/ */
export function isJobPortalPage(pathname: string): boolean {
return (
pathname.startsWith('/job-portal') || pathname.startsWith('/shihezi/job-portal')
);
}
/** 无需在应用启动前拉取管理端菜单/用户信息的路径 */
export function shouldSkipManagementBootstrap(pathname: string): boolean {
return (
pathname === PageEnum.LOGIN ||
pathname === '/shihezi/user/login' ||
isThirdPartyTransitionPage(pathname) ||
isJobPortalPage(pathname)
);
}