111
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:
@@ -19,8 +19,10 @@ import {
|
||||
import { history, useLocation, useModel } from '@umijs/max';
|
||||
import {
|
||||
ensureJobPortalLogin,
|
||||
getGetInfoCache,
|
||||
isJobPortalLoggedIn,
|
||||
PORTAL_LOGIN_URL,
|
||||
prefetchJobPortalUserInfo,
|
||||
} from '@/utils/jobPortalAuth';
|
||||
import { getJobRecommend } from '@/services/common/jobTitle';
|
||||
import { getMessageTotal } from '@/services/jobportal/user';
|
||||
@@ -56,12 +58,18 @@ const JobPortalHeader: React.FC<JobPortalHeaderProps> = ({
|
||||
const { initialState } = useModel('@@initialState');
|
||||
const currentUser = initialState?.currentUser;
|
||||
|
||||
// 获取用户名,优先使用 initialState,其次使用 localStorage 中的 userInfo
|
||||
// 获取用户名,优先 initialState,其次 getInfo 缓存,最后 appUser 缓存
|
||||
const getUserName = (): string => {
|
||||
if (currentUser?.nickName) {
|
||||
return currentUser.nickName;
|
||||
}
|
||||
// 尝试从 localStorage 获取用户信息
|
||||
const getInfoUser = getGetInfoCache()?.user;
|
||||
if (getInfoUser?.nickName) {
|
||||
return String(getInfoUser.nickName);
|
||||
}
|
||||
if (getInfoUser?.userName) {
|
||||
return String(getInfoUser.userName);
|
||||
}
|
||||
try {
|
||||
const cachedUserInfo = localStorage.getItem('userInfo');
|
||||
if (cachedUserInfo) {
|
||||
@@ -79,6 +87,13 @@ const JobPortalHeader: React.FC<JobPortalHeaderProps> = ({
|
||||
const userName = getUserName();
|
||||
const loggedIn = isJobPortalLoggedIn();
|
||||
|
||||
// SSO 仅有 token、本地尚无 userInfo 时预拉求职者资料
|
||||
useEffect(() => {
|
||||
if (loggedIn) {
|
||||
prefetchJobPortalUserInfo();
|
||||
}
|
||||
}, [loggedIn]);
|
||||
|
||||
// 判断激活导航(简化为 startsWith 匹配)
|
||||
const isHome = /^\/job-portal(\/(list|detail))?$/.test(location.pathname);
|
||||
const isResume = location.pathname.startsWith('/job-portal/resume');
|
||||
|
||||
Reference in New Issue
Block a user