From c240079df4333b92f12f5409b4cc0c4e5646b7f0 Mon Sep 17 00:00:00 2001 From: "meilin.huang" <954537473@qq.com> Date: Sun, 2 Jul 2023 17:06:00 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=89=8D=E7=AB=AF=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mayfly_go_web/src/components/auth/auth.ts | 25 +++++ .../src/components/pagetable/PageTable.vue | 4 +- .../src/components/pagetable/index.ts | 5 + mayfly_go_web/src/directive/auth.ts | 3 +- mayfly_go_web/src/views/ops/db/DbList.vue | 49 +++++---- .../src/views/ops/machine/MachineList.vue | 103 ++++++++++++------ .../src/views/ops/mongo/MongoList.vue | 27 ++--- .../src/views/ops/redis/DataOperation.vue | 15 ++- .../src/views/ops/redis/RedisList.vue | 29 ++--- .../src/views/system/account/AccountList.vue | 73 ++++++++----- .../src/views/system/config/ConfigList.vue | 34 ++++-- .../src/views/system/role/RoleList.vue | 57 ++++++---- .../src/views/system/syslog/SyslogList.vue | 2 +- 13 files changed, 278 insertions(+), 148 deletions(-) create mode 100644 mayfly_go_web/src/components/auth/auth.ts diff --git a/mayfly_go_web/src/components/auth/auth.ts b/mayfly_go_web/src/components/auth/auth.ts new file mode 100644 index 00000000..29001b39 --- /dev/null +++ b/mayfly_go_web/src/components/auth/auth.ts @@ -0,0 +1,25 @@ +import { useUserInfo } from '@/store/userInfo'; + +/** + * 判断当前用户是否拥有指定权限 + * @param code 权限code + * @returns + */ +export function hasPerm(code: string) { + return useUserInfo().userInfo.permissions.some((v: any) => v === code); +} + +/** + * 判断用户是否拥有权限对象里对应的code + * @param perms { save: "xxx:save"} + * @returns {"xxx:save": true} key->permission code + */ +export function hasPerms(permCodes: any[]) { + const res = {}; + for (let permCode of permCodes) { + if (hasPerm(permCode)) { + res[permCode] = true; + } + } + return res; +} \ No newline at end of file diff --git a/mayfly_go_web/src/components/pagetable/PageTable.vue b/mayfly_go_web/src/components/pagetable/PageTable.vue index c92767f8..8203bf30 100644 --- a/mayfly_go_web/src/components/pagetable/PageTable.vue +++ b/mayfly_go_web/src/components/pagetable/PageTable.vue @@ -86,13 +86,13 @@ + highlight-current-row v-loading="loadingData">