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/timezone'
|
||||||
import 'dayjs/plugin/utc'
|
import 'dayjs/plugin/utc'
|
||||||
import { cookieUtils } from './utils/request';
|
import { cookieUtils } from './utils/request';
|
||||||
|
import { useUser } from '@/store/user';
|
||||||
|
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { locale, language, timeZone } = useI18n()
|
const { locale, language, timeZone } = useI18n()
|
||||||
|
const { checkJump } = useUser();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const authToken = cookieUtils.get('authToken')
|
const authToken = cookieUtils.get('authToken')
|
||||||
if (!authToken && !window.location.hash.includes('#/login') && !window.location.hash.includes('#/conversation/')) {
|
if (!authToken && !window.location.hash.includes('#/login') && !window.location.hash.includes('#/conversation/')) {
|
||||||
window.location.href = `/#/login`;
|
window.location.href = `/#/login`;
|
||||||
|
} else {
|
||||||
|
checkJump()
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,15 @@ export interface UserState {
|
|||||||
clearUserInfo: () => void;
|
clearUserInfo: () => void;
|
||||||
logout: () => void;
|
logout: () => void;
|
||||||
getStorageType: () => void;
|
getStorageType: () => void;
|
||||||
|
checkJump: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const whitePage = [
|
||||||
|
'/conversation',
|
||||||
|
'/login',
|
||||||
|
'/invite-register'
|
||||||
|
]
|
||||||
|
|
||||||
export const useUser = create<UserState>((set, get) => ({
|
export const useUser = create<UserState>((set, get) => ({
|
||||||
user: localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user') || '{}') as User : {} as User,
|
user: localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user') || '{}') as User : {} as User,
|
||||||
loginInfo: {} as LoginInfo,
|
loginInfo: {} as LoginInfo,
|
||||||
@@ -36,8 +43,10 @@ export const useUser = create<UserState>((set, get) => ({
|
|||||||
if (!cookieUtils.get('authToken')) {
|
if (!cookieUtils.get('authToken')) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const { checkJump } = get()
|
||||||
const localUser = JSON.parse(localStorage.getItem('user') || '{}') as User;
|
const localUser = JSON.parse(localStorage.getItem('user') || '{}') as User;
|
||||||
if (localUser.id) {
|
if (localUser.id) {
|
||||||
|
checkJump()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
getUsers()
|
getUsers()
|
||||||
@@ -87,5 +96,14 @@ export const useUser = create<UserState>((set, get) => ({
|
|||||||
.catch(() => {
|
.catch(() => {
|
||||||
console.error('Failed to load storage type');
|
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