|
|
|
|
@ -1,5 +1,32 @@
|
|
|
|
|
import request from '@/utils/request'
|
|
|
|
|
|
|
|
|
|
const permissionInfoCache = new Map()
|
|
|
|
|
const permissionInfoPending = new Map()
|
|
|
|
|
|
|
|
|
|
function normalizePermissionParams(params = {}) {
|
|
|
|
|
return {
|
|
|
|
|
clientType: 2,
|
|
|
|
|
...params
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createPermissionCacheKey(params = {}) {
|
|
|
|
|
const normalizedParams = normalizePermissionParams(params)
|
|
|
|
|
return JSON.stringify(
|
|
|
|
|
Object.keys(normalizedParams)
|
|
|
|
|
.sort()
|
|
|
|
|
.reduce((result, key) => {
|
|
|
|
|
result[key] = normalizedParams[key]
|
|
|
|
|
return result
|
|
|
|
|
}, {})
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function clearPermissionInfoCache() {
|
|
|
|
|
permissionInfoCache.clear()
|
|
|
|
|
permissionInfoPending.clear()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 登录方法
|
|
|
|
|
export function login(username, password, code, uuid, tenantName, captchaVerification,rememberMe) {
|
|
|
|
|
const data = {
|
|
|
|
|
@ -34,14 +61,34 @@ export function register(data) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getPermissionInfo(params = {}) {
|
|
|
|
|
return request({
|
|
|
|
|
const normalizedParams = normalizePermissionParams(params)
|
|
|
|
|
const cacheKey = createPermissionCacheKey(normalizedParams)
|
|
|
|
|
|
|
|
|
|
if (permissionInfoCache.has(cacheKey)) {
|
|
|
|
|
return Promise.resolve(permissionInfoCache.get(cacheKey))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (permissionInfoPending.has(cacheKey)) {
|
|
|
|
|
return permissionInfoPending.get(cacheKey)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const requestPromise = request({
|
|
|
|
|
url: '/admin-api/system/auth/get-permission-info',
|
|
|
|
|
method: 'get',
|
|
|
|
|
params: {
|
|
|
|
|
clientType: 2,
|
|
|
|
|
...params
|
|
|
|
|
}
|
|
|
|
|
params: normalizedParams
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const wrappedPromise = requestPromise
|
|
|
|
|
.then((res) => {
|
|
|
|
|
permissionInfoCache.set(cacheKey, res)
|
|
|
|
|
return res
|
|
|
|
|
})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
permissionInfoPending.delete(cacheKey)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
permissionInfoPending.set(cacheKey, wrappedPromise)
|
|
|
|
|
return wrappedPromise
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取用户详细信息
|
|
|
|
|
|