From 18daf33f9d264c65ce85858006c6aacf47721cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=9D=E5=85=88=E7=91=9E?= <1490493387@qq.com> Date: Mon, 11 Sep 2023 18:20:03 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20:recycle:=20userStore=20=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E9=87=8D=E6=9E=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: ef31b8420a48a91dd2449d62fb615941d528bf24 --- src/api/user/types.ts | 7 +-- src/directive/permission/index.ts | 4 +- src/layout/components/NavBar/NavRight.vue | 2 +- src/permission.ts | 4 +- src/store/modules/permission.ts | 2 +- src/store/modules/user.ts | 47 +++++++------------ src/views/dashboard/index.vue | 4 +- .../permission/components/SwitchRoles.vue | 6 +-- 8 files changed, 32 insertions(+), 44 deletions(-) diff --git a/src/api/user/types.ts b/src/api/user/types.ts index 057be5f3..ba38dabf 100644 --- a/src/api/user/types.ts +++ b/src/api/user/types.ts @@ -2,9 +2,10 @@ * 登录用户信息 */ export interface UserInfo { - userId: number; - nickname: string; - avatar: string; + userId?: number; + username?: string; + nickname?: string; + avatar?: string; roles: string[]; perms: string[]; } diff --git a/src/directive/permission/index.ts b/src/directive/permission/index.ts index 11d32068..2bd2c705 100644 --- a/src/directive/permission/index.ts +++ b/src/directive/permission/index.ts @@ -7,7 +7,7 @@ import { Directive, DirectiveBinding } from "vue"; export const hasPerm: Directive = { mounted(el: HTMLElement, binding: DirectiveBinding) { // 「超级管理员」拥有所有的按钮权限 - const { roles, perms } = useUserStoreHook(); + const { roles, perms } = useUserStoreHook().user; if (roles.includes("ROOT")) { return true; } @@ -40,7 +40,7 @@ export const hasRole: Directive = { if (value) { const requiredRoles = value; // DOM绑定需要的角色编码 - const { roles } = useUserStoreHook(); + const { roles } = useUserStoreHook().user; const hasRole = roles.some((perm) => { return requiredRoles.includes(perm); }); diff --git a/src/layout/components/NavBar/NavRight.vue b/src/layout/components/NavBar/NavRight.vue index 8cc4ef5e..63cb1aa8 100644 --- a/src/layout/components/NavBar/NavRight.vue +++ b/src/layout/components/NavBar/NavRight.vue @@ -16,7 +16,7 @@
- +