Merge pull request #176 from SuanmoSuanyangTechnology/feature/ui_zy
fix(web): no workspace_id user jump url update
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}, [])
|
||||
|
||||
|
||||
@@ -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'
|
||||
}
|
||||
},
|
||||
}))
|
||||
Reference in New Issue
Block a user