This commit is contained in:
qsh
2025-05-19 11:41:27 +08:00
parent 6726bd7756
commit dc3292982a
5 changed files with 59 additions and 22 deletions

View File

@@ -7,7 +7,8 @@ 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 { getTenantId, getAppId } from '@/utils/auth'
import { useAppStoreWithOut } from '@/store/modules/app'
import { getTenantId, getAppId, setTenantId, setAppId } from '@/utils/auth'
import cache from '@/plugins/cache'
const { start, done } = useNProgress()
@@ -39,13 +40,20 @@ router.beforeEach(async (to, from, next) => {
} else {
if (getAccessToken()) {
if (to.path === '/login') {
next({ path: '/' })
if (to.query?.tenantId && to.query?.appId) {
setApp(to.query.tenantId, to.query.appId)
setTimeout(() => {
next({ path: '/' })
}, 1500)
} else {
next({ path: '/' })
}
} else {
// 获取所有字典
const dictStore = useDictStoreWithOut()
const userStore = useUserStoreWithOut()
const permissionStore = usePermissionStoreWithOut()
if (!dictStore.getIsSetDict && to.path != '/nm-detail') {
if (!dictStore.getIsSetDict) {
await dictStore.setDictMap()
}
if (!userStore.getIsSetUser) {
@@ -72,15 +80,23 @@ router.beforeEach(async (to, from, next) => {
const tenantId = getTenantId()
const appId = getAppId()
if (tenantId && appId) {
next(`/crm/login?tenantId=${tenantId}&appId=${appId}&redirect=${to.fullPath}`) // 否则全部重定向到登录页
next(`/oa/login?tenantId=${tenantId}&appId=${appId}&redirect=${to.fullPath}`) // 否则全部重定向到登录页
} else {
next(`/crm/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
next(`/oa/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
}
}
}
}
})
function setApp(tenantId, appId) {
setTenantId(tenantId)
setAppId(appId)
const appStore = useAppStoreWithOut()
appStore.setAppInfo(appId)
}
router.afterEach((to) => {
useTitle(to?.meta?.title)
done() // 结束Progress