From d710c9d27ed0098edd0662799d312f4a64389326 Mon Sep 17 00:00:00 2001 From: zws <447643445@qq.com> Date: Tue, 21 Jan 2025 09:23:37 +0800 Subject: [PATCH 1/2] =?UTF-8?q?perf:=20=E6=B7=BB=E5=8A=A0=E6=9D=83?= =?UTF-8?q?=E9=99=90Set=20=20=E6=9B=BF=E6=8D=A2=E6=A3=80=E6=9F=A5=E6=9D=83?= =?UTF-8?q?=E9=99=90=E6=95=B0=E7=BB=84=20=E6=8F=90=E9=AB=98=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E6=9D=83=E9=99=90=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/directives/permission/hasPermi.ts | 19 +++++++------------ src/store/modules/user.ts | 3 +++ src/utils/permission.ts | 19 ++++--------------- 3 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/directives/permission/hasPermi.ts b/src/directives/permission/hasPermi.ts index 02e2fbc7..a7dc35ee 100644 --- a/src/directives/permission/hasPermi.ts +++ b/src/directives/permission/hasPermi.ts @@ -1,5 +1,5 @@ -import type { App } from 'vue' -import { CACHE_KEY, useCache } from '@/hooks/web/useCache' +import type {App} from 'vue' +import {useUserStore} from "@/store/modules/user"; const { t } = useI18n() // 国际化 @@ -18,14 +18,9 @@ export function hasPermi(app: App) { } }) } - +const userStore = useUserStore(); +const all_permission = '*:*:*' export const hasPermission = (permission: string[]) => { - const { wsCache } = useCache() - const all_permission = '*:*:*' - const userInfo = wsCache.get(CACHE_KEY.USER) - const permissions = userInfo?.permissions || [] - - return permissions.some((p: string) => { - return all_permission === p || permission.includes(p) - }) -} \ No newline at end of file + return userStore.permissionsSet.has(all_permission) || + permission.some(permission => userStore.permissionsSet.has(permission)) +} diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index b3861809..55feb096 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -16,6 +16,7 @@ interface UserVO { interface UserInfoVO { // USER 缓存 permissions: string[] + permissionsSet: Set roles: string[] isSetUser: boolean user: UserVO @@ -24,6 +25,7 @@ interface UserInfoVO { export const useUserStore = defineStore('admin-user', { state: (): UserInfoVO => ({ permissions: [], + permissionsSet: new Set(), roles: [], isSetUser: false, user: { @@ -58,6 +60,7 @@ export const useUserStore = defineStore('admin-user', { userInfo = await getInfo() } this.permissions = userInfo.permissions + this.permissionsSet = new Set(userInfo.permissions) this.roles = userInfo.roles this.user = userInfo.user this.isSetUser = true diff --git a/src/utils/permission.ts b/src/utils/permission.ts index 3bf67b61..41381738 100644 --- a/src/utils/permission.ts +++ b/src/utils/permission.ts @@ -1,4 +1,6 @@ import { CACHE_KEY, useCache } from '@/hooks/web/useCache' +import {hasPermission} from "@/directives/permission/hasPermi"; + const { t } = useI18n() // 国际化 @@ -7,21 +9,8 @@ const { t } = useI18n() // 国际化 * @param {Array} value 校验值 * @returns {Boolean} */ -export function checkPermi(value: string[]) { - if (value && value instanceof Array && value.length > 0) { - const { wsCache } = useCache() - const permissionDatas = value - const all_permission = '*:*:*' - const userInfo = wsCache.get(CACHE_KEY.USER) - const permissions = userInfo?.permissions || [] - const hasPermission = permissions.some((permission: string) => { - return all_permission === permission || permissionDatas.includes(permission) - }) - return !!hasPermission - } else { - console.error(t('permission.hasPermission')) - return false - } +export function checkPermi(permission: string[]) { + return hasPermission(permission) } /** From c9c03bed13a79cfe2b448ea5735cb218d278ac9e Mon Sep 17 00:00:00 2001 From: zws <447643445@qq.com> Date: Tue, 21 Jan 2025 09:24:12 +0800 Subject: [PATCH 2/2] =?UTF-8?q?perf:=20=E6=A8=A1=E5=9E=8B=E5=88=97?= =?UTF-8?q?=E8=A1=A8=20=E6=9D=83=E9=99=90=E6=A3=80=E6=9F=A5=E7=94=A8comput?= =?UTF-8?q?ed=20=E6=9B=BF=E4=BB=A3vue=E6=8C=87=E4=BB=A4=20=E5=87=8F?= =?UTF-8?q?=E5=B0=91=E6=A3=80=E6=9F=A5=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bpm/model/CategoryDraggableModel.vue | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/views/bpm/model/CategoryDraggableModel.vue b/src/views/bpm/model/CategoryDraggableModel.vue index 9c5b9b13..43aa5193 100644 --- a/src/views/bpm/model/CategoryDraggableModel.vue +++ b/src/views/bpm/model/CategoryDraggableModel.vue @@ -158,7 +158,7 @@ link type="primary" @click="openModelForm('update', scope.row.id)" - v-hasPermi="['bpm:model:update']" + v-if="hasPermiUpdate" :disabled="!isManagerUser(scope.row)" > 修改 @@ -167,7 +167,7 @@ link type="primary" @click="openModelForm('copy', scope.row.id)" - v-hasPermi="['bpm:model:update']" + v-if="hasPermiUpdate" :disabled="!isManagerUser(scope.row)" > 复制 @@ -177,7 +177,7 @@ class="!ml-5px" type="primary" @click="handleDeploy(scope.row)" - v-hasPermi="['bpm:model:deploy']" + v-if="hasPermiDeploy" :disabled="!isManagerUser(scope.row)" > 发布 @@ -185,20 +185,20 @@ 更多