Compare commits

..

No commits in common. '5f196eebaec3e1896f60dfa7dd3a76437843c331' and 'c13e06b0bfb78af9fcee9833d3d3553a5da892c3' have entirely different histories.

  1. 85
      src/permission.js

@ -1,12 +1,14 @@
import router from './router' import router from './router'
import { isRelogin } from '@/config/axios/service' import { isRelogin } from '@/config/axios/service'
import { getAccessToken } from '@/utils/auth' import { getAccessToken, removeToken } 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'
import { useDictStoreWithOut } from '@/store/modules/dict' import { useDictStoreWithOut } from '@/store/modules/dict'
import { useUserStoreWithOut } from '@/store/modules/user' import { useUserStoreWithOut } from '@/store/modules/user'
import { usePermissionStoreWithOut } from '@/store/modules/permission' import { usePermissionStoreWithOut } from '@/store/modules/permission'
import { getAppId } from '@/utils/auth'
import cache from '@/plugins/cache'
const { start, done } = useNProgress() const { start, done } = useNProgress()
@ -18,45 +20,54 @@ 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 (getAccessToken()) { if (getAppId() && to.query?.appId && getAppId() != to.query?.appId) {
if (to.path === '/login') { removeToken()
next({ path: '/' }) cache?.local?.delete('appInfo')
} else { cache?.local?.delete('roleRouters')
// 获取所有字典 cache?.local?.delete('user')
const dictStore = useDictStoreWithOut() cache?.local?.delete('App_ID')
const userStore = useUserStoreWithOut() next(`/login`)
const permissionStore = usePermissionStoreWithOut() } else {
if (!dictStore.getIsSetDict) { if (getAccessToken()) {
await dictStore.setDictMap() if (to.path === '/login') {
} next({ path: '/' })
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 {
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 {
next()
}
} }
}
} else {
if (whiteList.indexOf(to.path) !== -1) {
next()
} else { } else {
// const tenantId = getTenantId() if (whiteList.indexOf(to.path) !== -1) {
// const appId = getAppId() next()
// if (tenantId && appId) { } else {
// next(`/oa/login?tenantId=${tenantId}&appId=${appId}&redirect=${to.fullPath}`) // 否则全部重定向到登录页 // const tenantId = getTenantId()
// } else { // const appId = getAppId()
next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页 // if (tenantId && appId) {
// } // next(`/oa/login?tenantId=${tenantId}&appId=${appId}&redirect=${to.fullPath}`) // 否则全部重定向到登录页
// } else {
next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
// }
}
} }
} }
}) })

Loading…
Cancel
Save