From 085fa5b29752f399e33731e37832d4dd58ab4cc1 Mon Sep 17 00:00:00 2001 From: hwj Date: Mon, 25 May 2026 15:30:08 +0800 Subject: [PATCH] =?UTF-8?q?style=EF=BC=9A=E8=8F=9C=E5=8D=95=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=B0=83=E7=94=A8=E6=AC=A1=E6=95=B0=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/login.js | 57 +++++++++++++++++++++++++++++++++++---- src/store/modules/user.ts | 4 ++- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/api/login.js b/src/api/login.js index e519dba..8302fcd 100644 --- a/src/api/login.js +++ b/src/api/login.js @@ -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 } // 获取用户详细信息 diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 816e241..1e2430b 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -1,4 +1,4 @@ -import { login, logout, getInfo } from "@/api/login"; +import { login, logout, getInfo, clearPermissionInfoCache } from "@/api/login"; import { getToken, setToken, removeToken } from "@/utils/auth"; import defAva from "@/static/images/profile.jpg"; import { defineStore } from "pinia"; @@ -40,6 +40,7 @@ const useUserStore = defineStore("user", { .then((res: any) => { setToken(res.data.accessToken); this.token = res.data.accessToken; + clearPermissionInfoCache(); resolve(null); }) .catch((error) => { @@ -80,6 +81,7 @@ const useUserStore = defineStore("user", { return new Promise((resolve, reject) => { logout() .then(() => { + clearPermissionInfoCache(); this.token = ""; this.roles = []; this.permissions = [];