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
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:
@@ -124,8 +124,8 @@ export default defineConfig({
|
|||||||
* @description 配置 <head> 中额外的 script
|
* @description 配置 <head> 中额外的 script
|
||||||
*/
|
*/
|
||||||
headScripts: [
|
headScripts: [
|
||||||
// 解决首次加载时白屏的问题
|
// 同步执行,在 umi 主包解析前注入 #root 占位,避免首屏纯白
|
||||||
{ src: '/shihezi/scripts/loading.js', async: true },
|
{ src: '/shihezi/scripts/loading.js' },
|
||||||
],
|
],
|
||||||
//================ pro 插件配置 =================
|
//================ pro 插件配置 =================
|
||||||
presets: ['umi-presets-pro'],
|
presets: ['umi-presets-pro'],
|
||||||
|
|||||||
@@ -14,6 +14,10 @@
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
body,
|
||||||
|
#root {
|
||||||
|
background-color: #f0f4f8;
|
||||||
|
}
|
||||||
#root {
|
#root {
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
background-size: 100% auto;
|
background-size: 100% auto;
|
||||||
|
|||||||
42
src/app.tsx
42
src/app.tsx
@@ -10,6 +10,7 @@ import {
|
|||||||
exchangeThirdPartyCredential,
|
exchangeThirdPartyCredential,
|
||||||
isThirdPartyTransitionPage,
|
isThirdPartyTransitionPage,
|
||||||
} from './utils/thirdPartyLogin';
|
} from './utils/thirdPartyLogin';
|
||||||
|
import { shouldSkipManagementBootstrap } from './utils/routeContext';
|
||||||
import { saveGetInfoCache } from './utils/jobPortalAuth';
|
import { saveGetInfoCache } from './utils/jobPortalAuth';
|
||||||
import {
|
import {
|
||||||
getRemoteMenu,
|
getRemoteMenu,
|
||||||
@@ -73,19 +74,8 @@ export async function getInitialState(): Promise<{
|
|||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
// 如果不是登录页面,执行
|
|
||||||
const { location } = history;
|
const { location } = history;
|
||||||
// 排除登录页面、过渡页面和求职者页面(考虑基础路径 /shihezi/)
|
if (!shouldSkipManagementBootstrap(location.pathname)) {
|
||||||
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) {
|
|
||||||
const currentUser = await fetchUserInfo();
|
const currentUser = await fetchUserInfo();
|
||||||
return {
|
return {
|
||||||
fetchUserInfo,
|
fetchUserInfo,
|
||||||
@@ -135,16 +125,10 @@ export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) =
|
|||||||
onPageChange: () => {
|
onPageChange: () => {
|
||||||
const { location } = history;
|
const { location } = history;
|
||||||
// 如果没有登录,重定向到 login,但排除过渡页面和求职者页面(考虑基础路径 /shihezi/)
|
// 如果没有登录,重定向到 login,但排除过渡页面和求职者页面(考虑基础路径 /shihezi/)
|
||||||
const isTransitionPage = location.pathname === '/' ||
|
if (
|
||||||
location.pathname === '/login-tow' ||
|
!initialState?.currentUser &&
|
||||||
location.pathname === '/shihezi/' ||
|
!shouldSkipManagementBootstrap(location.pathname)
|
||||||
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) {
|
|
||||||
history.push(PageEnum.LOGIN);
|
history.push(PageEnum.LOGIN);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -205,11 +189,12 @@ export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) =
|
|||||||
|
|
||||||
export async function onRouteChange({ clientRoutes, location }: { clientRoutes: any; location: any }) {
|
export async function onRouteChange({ clientRoutes, location }: { clientRoutes: any; location: any }) {
|
||||||
const menus = getRemoteMenu();
|
const menus = getRemoteMenu();
|
||||||
// console.log('onRouteChange', clientRoutes, location, menus);
|
|
||||||
|
|
||||||
// 如果路由信息未加载,尝试重新获取路由信息
|
|
||||||
const token = getAccessToken();
|
const token = getAccessToken();
|
||||||
if (menus === null && location.pathname !== PageEnum.LOGIN && token) {
|
if (
|
||||||
|
menus === null &&
|
||||||
|
token &&
|
||||||
|
!shouldSkipManagementBootstrap(location.pathname)
|
||||||
|
) {
|
||||||
console.log('检测到路由信息未加载,正在重新获取路由信息...');
|
console.log('检测到路由信息未加载,正在重新获取路由信息...');
|
||||||
|
|
||||||
// 重新获取路由信息,而不是刷新页面
|
// 重新获取路由信息,而不是刷新页面
|
||||||
@@ -248,6 +233,11 @@ export async function render(oldRender: () => void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shouldSkipManagementBootstrap(pathname)) {
|
||||||
|
oldRender();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const token = getAccessToken();
|
const token = getAccessToken();
|
||||||
if (!token || token.length === 0) {
|
if (!token || token.length === 0) {
|
||||||
oldRender();
|
oldRender();
|
||||||
|
|||||||
24
src/loading.less
Normal file
24
src/loading.less
Normal 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
21
src/loading.tsx
Normal 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
19
src/utils/routeContext.ts
Normal 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)
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user