|
|
@@ -8,6 +8,9 @@ import { usePageLoading } from '@/hooks/web/usePageLoading'
|
|
|
import { useDictStoreWithOut } from '@/store/modules/dict'
|
|
|
import { useUserStoreWithOut } from '@/store/modules/user'
|
|
|
import { usePermissionStoreWithOut } from '@/store/modules/permission'
|
|
|
+import * as LoginApi from '@/api/login'
|
|
|
+import * as authUtil from '@/utils/auth'
|
|
|
+import { deleteUserCache } from '@/hooks/web/useCache'
|
|
|
|
|
|
const { start, done } = useNProgress()
|
|
|
|
|
|
@@ -62,6 +65,17 @@ router.beforeEach(async (to, from, next) => {
|
|
|
loadStart()
|
|
|
if (getAccessToken()) {
|
|
|
if (to.path === '/login') {
|
|
|
+ next({ path: '/' })
|
|
|
+ } else if (to.fullPath.includes('portalLogin')) {
|
|
|
+ const userStore = useUserStoreWithOut()
|
|
|
+ await userStore.loginOut()
|
|
|
+ // await getTenantId()
|
|
|
+ const res = await LoginApi.portalLogin({
|
|
|
+ username: to.query.username
|
|
|
+ })
|
|
|
+
|
|
|
+ authUtil.setToken(res)
|
|
|
+
|
|
|
next({ path: '/' })
|
|
|
} else {
|
|
|
const dictStore = useDictStoreWithOut()
|
|
|
@@ -92,8 +106,28 @@ router.beforeEach(async (to, from, next) => {
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- if (whiteList.indexOf(to.path) !== -1) {
|
|
|
- next()
|
|
|
+ authUtil.removeToken()
|
|
|
+ deleteUserCache()
|
|
|
+ useUserStoreWithOut().resetState()
|
|
|
+ if (to.query.username) {
|
|
|
+ // await getTenantId()
|
|
|
+ const res = await LoginApi.portalLogin({
|
|
|
+ username: to.query.username
|
|
|
+ })
|
|
|
+
|
|
|
+ authUtil.setToken(res)
|
|
|
+
|
|
|
+ next({ path: '/index' })
|
|
|
+ } else if (whiteList.indexOf(to.path) !== -1) {
|
|
|
+ const code = to.query.code
|
|
|
+ if (code) {
|
|
|
+ // await getTenantId()
|
|
|
+ const res = await LoginApi.socialLogin('20', typeof code === 'string' ? code : '', '22')
|
|
|
+ authUtil.setToken(res)
|
|
|
+ next({ path: 'index' })
|
|
|
+ } else {
|
|
|
+ next() // 正常导航
|
|
|
+ }
|
|
|
} else {
|
|
|
next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
|
|
|
}
|