Merge pull request #177 from SuanmoSuanyangTechnology/develop

Develop
This commit is contained in:
yingzhao
2026-01-22 15:48:00 +08:00
committed by GitHub
2 changed files with 23 additions and 1 deletions

View File

@@ -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()
}
}, [])

View File

@@ -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<UserState>((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<UserState>((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<UserState>((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'
}
},
}))