Commit 76a5f87c0ce871cca48b9e4c32331353a796e7d2

Authored by 无木
1 parent 49e72a8e

fix: `hasPermission` not work in `ROLE` Mode

CHANGELOG.zh_CN.md
1 ### ✨ Features 1 ### ✨ Features
2 2
3 - **Axios** 新增`withToken`配置,用于控制请求是否携带 token 3 - **Axios** 新增`withToken`配置,用于控制请求是否携带 token
  4 +- **BasicUpload** 新增在预览 `Modal` 中删除文件时触发`preview-delete` 事件
4 5
5 ### 🐛 Bug Fixes 6 ### 🐛 Bug Fixes
6 7
@@ -14,6 +15,8 @@ @@ -14,6 +15,8 @@
14 - **LockScreen** 修复锁屏功能可以通过刷新页面或复制 URL 打开新的浏览器标签来跳过锁定状态的问题 15 - **LockScreen** 修复锁屏功能可以通过刷新页面或复制 URL 打开新的浏览器标签来跳过锁定状态的问题
15 - 修复多个窗口同时打开页面时,`Token` 不会同步的问题 16 - 修复多个窗口同时打开页面时,`Token` 不会同步的问题
16 - **Menu** 修复路由映射模式下,单级菜单刷新不会激活 17 - **Menu** 修复路由映射模式下,单级菜单刷新不会激活
  18 +- 修复`ROLE`权限模式下`hasPermission`不工作的问题
  19 +- **Table** 修复启用`clickToRowSelect`时,点击行不会触发`selection-change`事件的问题
17 20
18 ## 2.5.2(2021-06-27) 21 ## 2.5.2(2021-06-27)
19 22
src/hooks/web/usePermission.ts
@@ -57,13 +57,14 @@ export function usePermission() { @@ -57,13 +57,14 @@ export function usePermission() {
57 * Determine whether there is permission 57 * Determine whether there is permission
58 */ 58 */
59 function hasPermission(value?: RoleEnum | RoleEnum[] | string | string[], def = true): boolean { 59 function hasPermission(value?: RoleEnum | RoleEnum[] | string | string[], def = true): boolean {
  60 + // Visible by default
  61 + if (!value) {
  62 + return def;
  63 + }
  64 +
60 const permMode = projectSetting.permissionMode; 65 const permMode = projectSetting.permissionMode;
61 66
62 - if (PermissionModeEnum.ROUTE_MAPPING === permMode) {  
63 - // Visible by default  
64 - if (!value) {  
65 - return def;  
66 - } 67 + if ([PermissionModeEnum.ROUTE_MAPPING, PermissionModeEnum.ROLE].includes(permMode)) {
67 if (!isArray(value)) { 68 if (!isArray(value)) {
68 return userStore.getRoleList?.includes(value as RoleEnum); 69 return userStore.getRoleList?.includes(value as RoleEnum);
69 } 70 }
@@ -71,10 +72,6 @@ export function usePermission() { @@ -71,10 +72,6 @@ export function usePermission() {
71 } 72 }
72 73
73 if (PermissionModeEnum.BACK === permMode) { 74 if (PermissionModeEnum.BACK === permMode) {
74 - // Visible by default  
75 - if (!value) {  
76 - return def;  
77 - }  
78 const allCodeList = permissionStore.getPermCodeList as string[]; 75 const allCodeList = permissionStore.getPermCodeList as string[];
79 if (!isArray(value)) { 76 if (!isArray(value)) {
80 return allCodeList.includes(value); 77 return allCodeList.includes(value);