dev-cl^2
qsh 1 month ago
parent 8f20e04701
commit 3e8a9220f6
  1. 14
      src/permission.js
  2. 2
      src/store/modules/dict.ts
  3. 24
      src/utils/auth.ts

@ -7,7 +7,8 @@ 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 { getTenantId, getAppId } from '@/utils/auth' import { useAppStoreWithOut } from '@/store/modules/app'
import { getTenantId, getAppId, setTenantId, setAppId } from '@/utils/auth'
import cache from '@/plugins/cache' import cache from '@/plugins/cache'
const { start, done } = useNProgress() const { start, done } = useNProgress()
@ -30,6 +31,9 @@ router.beforeEach(async (to, from, next) => {
} else { } else {
if (getAccessToken()) { if (getAccessToken()) {
if (to.path === '/login') { if (to.path === '/login') {
if (to.query?.tenantId && to.query?.appId) {
setApp(to.query.tenantId, to.query.appId)
}
next({ path: '/' }) next({ path: '/' })
} else { } else {
// 获取所有字典 // 获取所有字典
@ -72,6 +76,14 @@ router.beforeEach(async (to, from, next) => {
} }
}) })
function setApp(tenantId, appId) {
setTenantId(tenantId)
setAppId(appId)
const appStore = useAppStoreWithOut()
appStore.setAppInfo(appId)
}
router.afterEach((to) => { router.afterEach((to) => {
useTitle(to?.meta?.title) useTitle(to?.meta?.title)
done() // 结束Progress done() // 结束Progress

@ -45,7 +45,7 @@ export const useDictStore = defineStore('dict', {
this.dictMap = dictMap this.dictMap = dictMap
this.isSetDict = true this.isSetDict = true
} else { } else {
const res = await listSimpleDictData() const res = (await listSimpleDictData()) || []
// 设置数据 // 设置数据
const dictDataMap = new Map<string, any>() const dictDataMap = new Map<string, any>()
res.forEach((dictData: DictDataVO) => { res.forEach((dictData: DictDataVO) => {

@ -9,26 +9,34 @@ const RefreshTokenKey = 'REFRESH_TOKEN'
// 获取token // 获取token
export const getAccessToken = () => { export const getAccessToken = () => {
// 此处与TokenKey相同,此写法解决初始化时Cookies中不存在TokenKey报错 // 此处与TokenKey相同,此写法解决初始化时Cookies中不存在TokenKey报错
return cache.local.get(AccessTokenKey) return localStorage.getItem(AccessTokenKey)
? cache.local.get(AccessTokenKey) ? localStorage.getItem(AccessTokenKey)
: cache.local.get('ACCESS_TOKEN') : localStorage.getItem('ACCESS_TOKEN')
// return cache.local.get(AccessTokenKey)
// ? cache.local.get(AccessTokenKey)
// : cache.local.get('ACCESS_TOKEN')
} }
// 刷新token // 刷新token
export const getRefreshToken = () => { export const getRefreshToken = () => {
return cache.local.get(RefreshTokenKey) return localStorage.getItem(RefreshTokenKey)
// return cache.local.get(RefreshTokenKey)
} }
// 设置token // 设置token
export const setToken = (token: TokenType) => { export const setToken = (token: TokenType) => {
cache.local.set(RefreshTokenKey, token.refreshToken) localStorage.setItem(AccessTokenKey, token.accessToken)
cache.local.set(AccessTokenKey, token.accessToken) localStorage.setItem(RefreshTokenKey, token.refreshToken)
// cache.local.set(RefreshTokenKey, token.refreshToken)
// cache.local.set(AccessTokenKey, token.accessToken)
} }
// 删除token // 删除token
export const removeToken = () => { export const removeToken = () => {
cache.local.delete(AccessTokenKey) localStorage.removeItem(AccessTokenKey)
cache.local.delete(RefreshTokenKey) localStorage.removeItem(RefreshTokenKey)
// cache.local.delete(AccessTokenKey)
// cache.local.delete(RefreshTokenKey)
} }
/** 格式化token(jwt格式) */ /** 格式化token(jwt格式) */

Loading…
Cancel
Save