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 { 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()
@ -30,6 +31,9 @@ router.beforeEach(async (to, from, next) => {
} else {
if (getAccessToken()) {
if (to.path === '/login') {
if (to.query?.tenantId && to.query?.appId) {
setApp(to.query.tenantId, to.query.appId)
}
next({ path: '/' })
} 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) => {
useTitle(to?.meta?.title)
done() // 结束Progress

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

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

Loading…
Cancel
Save