|
@@ -1,7 +1,7 @@
|
|
import router from './router'
|
|
import router from './router'
|
|
import { useNProgress } from '@/hooks/web/useNProgress'
|
|
import { useNProgress } from '@/hooks/web/useNProgress'
|
|
import { useTitle } from '@/hooks/web/useTitle'
|
|
import { useTitle } from '@/hooks/web/useTitle'
|
|
-import { getToken, getEnterpriseToken, removeToken } from '@/utils/auth'
|
|
|
|
|
|
+import { getToken } from '@/utils/auth'
|
|
import { useDictStore } from '@/store/dict'
|
|
import { useDictStore } from '@/store/dict'
|
|
import { useUserStore } from '@/store/user'
|
|
import { useUserStore } from '@/store/user'
|
|
|
|
|
|
@@ -9,34 +9,38 @@ const { start, done } = useNProgress()
|
|
// loginType:1.enterprise: 企业路由
|
|
// loginType:1.enterprise: 企业路由
|
|
// 2.personal: 个人路由
|
|
// 2.personal: 个人路由
|
|
// 3.common: 没有限制访问权限
|
|
// 3.common: 没有限制访问权限
|
|
-// 3.personalCommon: 无需登录也能访问的页面,但登录企业不能访问
|
|
|
|
|
|
+// 3.personalCommon: 无需登录也能访问的页面
|
|
// 路由守卫
|
|
// 路由守卫
|
|
router.beforeEach(async (to, from, next) => {
|
|
router.beforeEach(async (to, from, next) => {
|
|
start()
|
|
start()
|
|
// loadStart()
|
|
// loadStart()
|
|
|
|
+ if (to.path === '/enterpriseVerification') {
|
|
|
|
+ // 校验企业必填信息
|
|
|
|
+ useUserStore().checkEnterpriseBaseInfo()
|
|
|
|
+ next()
|
|
|
|
+ }
|
|
if (getToken()) {
|
|
if (getToken()) {
|
|
- if (to.path === '/enterpriseVerification') useUserStore().checkEnterpriseBaseInfo() // 校验企业必填信息
|
|
|
|
if (to.path === '/login') {
|
|
if (to.path === '/login') {
|
|
- if (getEnterpriseToken()) next({ path: '/enterprise' }) // 已登录企业
|
|
|
|
- else next({ path: '/recruitHome' }) // 已登录个人账号
|
|
|
|
|
|
+ next({ path: '/recruitHome' })
|
|
} else {
|
|
} else {
|
|
// 获取字典信息
|
|
// 获取字典信息
|
|
const dictStore = useDictStore()
|
|
const dictStore = useDictStore()
|
|
dictStore.getDictTypeData()
|
|
dictStore.getDictTypeData()
|
|
-
|
|
|
|
- const type = localStorage.getItem('loginType')
|
|
|
|
- // 判断企业路由和个人路由,防止互串
|
|
|
|
- if (!type) { removeToken(); next(`/login?redirect=${to.fullPath}`) }
|
|
|
|
- else if (to.meta?.loginType === 'common') next()
|
|
|
|
- else if (type === 'enterprise' && to.meta?.loginType === 'personalCommon') next({ path: `/${type}` }) // 企业端不能访问任何个人端路由
|
|
|
|
- else if (type === 'personal' && to.meta?.loginType === 'personalCommon') next()
|
|
|
|
- else if (to.meta?.loginType === type) next()
|
|
|
|
- else next({ path: `/${type}` })
|
|
|
|
- // next()
|
|
|
|
|
|
+ next()
|
|
|
|
+ // const type = localStorage.getItem('loginType')
|
|
|
|
+ // // 判断企业路由和个人路由,防止互串
|
|
|
|
+ // if (!type) { removeToken(); next(`/login?redirect=${to.fullPath}`) }
|
|
|
|
+ // else if (to.meta?.loginType === 'common' || to.meta?.loginType === 'personalCommon') next()
|
|
|
|
+ // // else if (type === 'enterprise' && to.meta?.loginType === 'personalCommon') next({ path: `/${type}` }) // 企业端不能访问任何个人端路由
|
|
|
|
+ // // else if (type === 'personal' && to.meta?.loginType === 'personalCommon') next()
|
|
|
|
+ // else if (to.meta?.loginType === type) next()
|
|
|
|
+ // else next({ path: `/${type}` })
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
if (to.meta?.loginType === 'personalCommon' || to.meta?.loginType === 'common') { // 路由不重定向
|
|
if (to.meta?.loginType === 'personalCommon' || to.meta?.loginType === 'common') { // 路由不重定向
|
|
next()
|
|
next()
|
|
|
|
+ } else if (to.meta?.loginType === 'enterprise') { // 没有企业token->去个人首页
|
|
|
|
+ next({ path: '/recruitHome' })
|
|
} else {
|
|
} else {
|
|
next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
|
|
next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
|
|
}
|
|
}
|