From cfd8cd57cfc2a6629e168d646d1b9cdbbb998ac1 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 17 Feb 2022 14:33:52 +0800 Subject: [PATCH] =?UTF-8?q?v3.8.0=20=E6=96=B0=E5=A2=9E=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E7=AE=80=E5=8C=96=E6=9D=83=E9=99=90=E9=AA=8C?= =?UTF-8?q?=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-ui-admin/src/plugins/auth.js | 60 +++++++++++++++++++++++++++++ yudao-ui-admin/src/plugins/index.js | 3 ++ 2 files changed, 63 insertions(+) create mode 100644 yudao-ui-admin/src/plugins/auth.js diff --git a/yudao-ui-admin/src/plugins/auth.js b/yudao-ui-admin/src/plugins/auth.js new file mode 100644 index 000000000..6c6bc2428 --- /dev/null +++ b/yudao-ui-admin/src/plugins/auth.js @@ -0,0 +1,60 @@ +import store from '@/store' + +function authPermission(permission) { + const all_permission = "*:*:*"; + const permissions = store.getters && store.getters.permissions + if (permission && permission.length > 0) { + return permissions.some(v => { + return all_permission === v || v === permission + }) + } else { + return false + } +} + +function authRole(role) { + const super_admin = "admin"; + const roles = store.getters && store.getters.roles + if (role && role.length > 0) { + return roles.some(v => { + return super_admin === v || v === role + }) + } else { + return false + } +} + +export default { + // 验证用户是否具备某权限 + hasPermi(permission) { + return authPermission(permission); + }, + // 验证用户是否含有指定权限,只需包含其中一个 + hasPermiOr(permissions) { + return permissions.some(item => { + return authPermission(item) + }) + }, + // 验证用户是否含有指定权限,必须全部拥有 + hasPermiAnd(permissions) { + return permissions.every(item => { + return authPermission(item) + }) + }, + // 验证用户是否具备某角色 + hasRole(role) { + return authRole(role); + }, + // 验证用户是否含有指定角色,只需包含其中一个 + hasRoleOr(roles) { + return roles.some(item => { + return authRole(item) + }) + }, + // 验证用户是否含有指定角色,必须全部拥有 + hasRoleAnd(roles) { + return roles.every(item => { + return authRole(item) + }) + } +} diff --git a/yudao-ui-admin/src/plugins/index.js b/yudao-ui-admin/src/plugins/index.js index f4698301a..d1cb4dbb4 100644 --- a/yudao-ui-admin/src/plugins/index.js +++ b/yudao-ui-admin/src/plugins/index.js @@ -1,9 +1,12 @@ +import auth from './auth' import cache from './cache' import modal from './modal' import download from './download' export default { install(Vue) { + // 认证对象 + Vue.prototype.$auth = auth // 缓存对象 Vue.prototype.$cache = cache // 模态框对象