sc
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import router from './router'
|
import router from './router'
|
||||||
import { isRelogin } from '@/config/axios/service'
|
import { isRelogin } from '@/config/axios/service'
|
||||||
import { getAccessToken, removeToken } from '@/utils/auth'
|
import { getAccessToken } from '@/utils/auth'
|
||||||
import { useTitle } from '@/hooks/web/useTitle'
|
import { useTitle } from '@/hooks/web/useTitle'
|
||||||
import { useNProgress } from '@/hooks/web/useNProgress'
|
import { useNProgress } from '@/hooks/web/useNProgress'
|
||||||
import { usePageLoading } from '@/hooks/web/usePageLoading'
|
import { usePageLoading } from '@/hooks/web/usePageLoading'
|
||||||
@@ -9,7 +9,6 @@ import { useUserStoreWithOut } from '@/store/modules/user'
|
|||||||
import { usePermissionStoreWithOut } from '@/store/modules/permission'
|
import { usePermissionStoreWithOut } from '@/store/modules/permission'
|
||||||
import { useAppStoreWithOut } from '@/store/modules/app'
|
import { useAppStoreWithOut } from '@/store/modules/app'
|
||||||
import { getTenantId, getAppId, setTenantId, setAppId } from '@/utils/auth'
|
import { getTenantId, getAppId, setTenantId, setAppId } from '@/utils/auth'
|
||||||
import cache from '@/plugins/cache'
|
|
||||||
|
|
||||||
const { start, done } = useNProgress()
|
const { start, done } = useNProgress()
|
||||||
|
|
||||||
@@ -21,58 +20,49 @@ const whiteList = ['/login', '/social-login', '/auth-redirect', '/bind', '/regis
|
|||||||
router.beforeEach(async (to, from, next) => {
|
router.beforeEach(async (to, from, next) => {
|
||||||
start()
|
start()
|
||||||
loadStart()
|
loadStart()
|
||||||
if (getAppId() && to.query?.appId && getAppId() != to.query?.appId) {
|
if (getAccessToken()) {
|
||||||
removeToken()
|
if (to.path === '/login') {
|
||||||
cache?.local?.delete('appInfo')
|
if (to.query?.tenantId && to.query?.appId) {
|
||||||
cache?.local?.delete('roleRouters')
|
setApp(to.query.tenantId, to.query.appId)
|
||||||
cache?.local?.delete('user')
|
await waitTime(1500)
|
||||||
cache?.local?.delete('App_ID')
|
|
||||||
next(`/login?tenantId=${to.query?.tenantId}&appId=${to.query?.appId}`)
|
|
||||||
} else {
|
|
||||||
if (getAccessToken()) {
|
|
||||||
if (to.path === '/login') {
|
|
||||||
if (to.query?.tenantId && to.query?.appId) {
|
|
||||||
setApp(to.query.tenantId, to.query.appId)
|
|
||||||
await waitTime(1500)
|
|
||||||
} else {
|
|
||||||
next({ path: '/' })
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// 获取所有字典
|
next({ path: '/' })
|
||||||
const dictStore = useDictStoreWithOut()
|
|
||||||
const userStore = useUserStoreWithOut()
|
|
||||||
const permissionStore = usePermissionStoreWithOut()
|
|
||||||
if (!dictStore.getIsSetDict) {
|
|
||||||
await dictStore.setDictMap()
|
|
||||||
}
|
|
||||||
if (!userStore.getIsSetUser) {
|
|
||||||
isRelogin.show = true
|
|
||||||
await userStore.setUserInfoAction()
|
|
||||||
isRelogin.show = false
|
|
||||||
// 后端过滤菜单
|
|
||||||
await permissionStore.generateRoutes()
|
|
||||||
permissionStore.getAddRouters.forEach((route) => {
|
|
||||||
router.addRoute(route) // 动态添加可访问路由表
|
|
||||||
})
|
|
||||||
const redirectPath = from.query.redirect || to.path
|
|
||||||
const redirect = decodeURIComponent(redirectPath)
|
|
||||||
const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect }
|
|
||||||
next(nextData)
|
|
||||||
} else {
|
|
||||||
next()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (whiteList.indexOf(to.path) !== -1) {
|
// 获取所有字典
|
||||||
next()
|
const dictStore = useDictStoreWithOut()
|
||||||
|
const userStore = useUserStoreWithOut()
|
||||||
|
const permissionStore = usePermissionStoreWithOut()
|
||||||
|
if (!dictStore.getIsSetDict) {
|
||||||
|
await dictStore.setDictMap()
|
||||||
|
}
|
||||||
|
if (!userStore.getIsSetUser) {
|
||||||
|
isRelogin.show = true
|
||||||
|
await userStore.setUserInfoAction()
|
||||||
|
isRelogin.show = false
|
||||||
|
// 后端过滤菜单
|
||||||
|
await permissionStore.generateRoutes()
|
||||||
|
permissionStore.getAddRouters.forEach((route) => {
|
||||||
|
router.addRoute(route) // 动态添加可访问路由表
|
||||||
|
})
|
||||||
|
const redirectPath = from.query.redirect || to.path
|
||||||
|
const redirect = decodeURIComponent(redirectPath)
|
||||||
|
const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect }
|
||||||
|
next(nextData)
|
||||||
} else {
|
} else {
|
||||||
const tenantId = getTenantId()
|
next()
|
||||||
const appId = getAppId()
|
}
|
||||||
if (tenantId && appId) {
|
}
|
||||||
next(`/oa/login?tenantId=${tenantId}&appId=${appId}&redirect=${to.fullPath}`) // 否则全部重定向到登录页
|
} else {
|
||||||
} else {
|
if (whiteList.indexOf(to.path) !== -1) {
|
||||||
next(`/oa/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
|
next()
|
||||||
}
|
} else {
|
||||||
|
const tenantId = getTenantId()
|
||||||
|
const appId = getAppId()
|
||||||
|
if (tenantId && appId) {
|
||||||
|
next(`/oa/login?tenantId=${tenantId}&appId=${appId}&redirect=${to.fullPath}`) // 否则全部重定向到登录页
|
||||||
|
} else {
|
||||||
|
next(`/oa/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ export const useUserStore = defineStore('admin-user', {
|
|||||||
async loginOut() {
|
async loginOut() {
|
||||||
await loginOut()
|
await loginOut()
|
||||||
removeToken()
|
removeToken()
|
||||||
cache.local.clear()
|
// cache.local.clear()
|
||||||
this.resetState()
|
this.resetState()
|
||||||
},
|
},
|
||||||
resetState() {
|
resetState() {
|
||||||
|
|||||||
Reference in New Issue
Block a user