Skip to content

Commit

Permalink
fix: hasPermission not work in ROLE Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mynetfan committed Jun 30, 2021
1 parent 49e72a8 commit 76a5f87
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.zh_CN.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### ✨ Features

- **Axios** 新增`withToken`配置,用于控制请求是否携带 token
- **BasicUpload** 新增在预览 `Modal` 中删除文件时触发`preview-delete` 事件

### 🐛 Bug Fixes

Expand All @@ -14,6 +15,8 @@
- **LockScreen** 修复锁屏功能可以通过刷新页面或复制 URL 打开新的浏览器标签来跳过锁定状态的问题
- 修复多个窗口同时打开页面时,`Token` 不会同步的问题
- **Menu** 修复路由映射模式下,单级菜单刷新不会激活
- 修复`ROLE`权限模式下`hasPermission`不工作的问题
- **Table** 修复启用`clickToRowSelect`时,点击行不会触发`selection-change`事件的问题

## 2.5.2(2021-06-27)

Expand Down
15 changes: 6 additions & 9 deletions src/hooks/web/usePermission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,21 @@ export function usePermission() {
* Determine whether there is permission
*/
function hasPermission(value?: RoleEnum | RoleEnum[] | string | string[], def = true): boolean {
// Visible by default
if (!value) {
return def;
}

const permMode = projectSetting.permissionMode;

if (PermissionModeEnum.ROUTE_MAPPING === permMode) {
// Visible by default
if (!value) {
return def;
}
if ([PermissionModeEnum.ROUTE_MAPPING, PermissionModeEnum.ROLE].includes(permMode)) {
if (!isArray(value)) {
return userStore.getRoleList?.includes(value as RoleEnum);
}
return (intersection(value, userStore.getRoleList) as RoleEnum[]).length > 0;
}

if (PermissionModeEnum.BACK === permMode) {
// Visible by default
if (!value) {
return def;
}
const allCodeList = permissionStore.getPermCodeList as string[];
if (!isArray(value)) {
return allCodeList.includes(value);
Expand Down

0 comments on commit 76a5f87

Please sign in to comment.