diff --git a/web/src/App.tsx b/web/src/App.tsx index 1abbc2cc..032338a3 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -28,15 +28,19 @@ import 'dayjs/locale/zh-cn' import 'dayjs/plugin/timezone' import 'dayjs/plugin/utc' import { cookieUtils } from './utils/request'; +import { useUser } from '@/store/user'; function App() { const { t } = useTranslation(); const { locale, language, timeZone } = useI18n() + const { checkJump } = useUser(); useEffect(() => { const authToken = cookieUtils.get('authToken') if (!authToken && !window.location.hash.includes('#/login') && !window.location.hash.includes('#/conversation/')) { window.location.href = `/#/login`; + } else { + checkJump() } }, []) diff --git a/web/src/store/user.ts b/web/src/store/user.ts index 28809e79..75d10812 100644 --- a/web/src/store/user.ts +++ b/web/src/store/user.ts @@ -21,8 +21,15 @@ export interface UserState { clearUserInfo: () => void; logout: () => void; getStorageType: () => void; + checkJump: () => void; } +export const whitePage = [ + '/conversation', + '/login', + '/invite-register' +] + export const useUser = create((set, get) => ({ user: localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user') || '{}') as User : {} as User, loginInfo: {} as LoginInfo, @@ -36,8 +43,10 @@ export const useUser = create((set, get) => ({ if (!cookieUtils.get('authToken')) { return } + const { checkJump } = get() const localUser = JSON.parse(localStorage.getItem('user') || '{}') as User; if (localUser.id) { + checkJump() return } getUsers() @@ -87,5 +96,14 @@ export const useUser = create((set, get) => ({ .catch(() => { console.error('Failed to load storage type'); }) - } + }, + checkJump: () => { + const localUser = JSON.parse(localStorage.getItem('user') || '{}') as User; + const hash = window.location.hash; + + if (localUser.id && (!localUser.current_workspace_id || localUser.current_workspace_id === '') && !whitePage.find(vo => hash.includes(vo))) { + console.log('whitePage', whitePage.find(vo => hash.includes(vo))) + window.location.href = '/#/index' + } + }, })) \ No newline at end of file