diff --git a/src/components/Authorized/CheckPermissions.js b/src/components/Authorized/CheckPermissions.js index d51e98333014d1705fab88d2ee13ae0c1d1948dc..8a6c9780a89a387e65f8231a7a9ea669527991f6 100644 --- a/src/components/Authorized/CheckPermissions.js +++ b/src/components/Authorized/CheckPermissions.js @@ -52,6 +52,10 @@ const checkPermissions = (authority, currentAuthority, target, Exception) => { if (bool) { return target; } + // 函数执行后返回值是 Promise + if (isPromise(bool)) { + return ; + } return Exception; } catch (error) { throw error; diff --git a/src/components/Authorized/index.md b/src/components/Authorized/index.md index 51588bb5a5e22ff49bb048f128773bf67146277f..f3b2f80af5ffa27ecb310b6932dc7dfa7c7945c8 100644 --- a/src/components/Authorized/index.md +++ b/src/components/Authorized/index.md @@ -25,14 +25,14 @@ order: 15 | 参数 | 说明 | 类型 | 默认值 | |----------|------------------------------------------|-------------|-------| | children | 正常渲染的元素,权限判断通过时展示 | ReactNode | - | -| authority | 准入权限/权限判断 | `string | array | Promise | (currentAuthority) => boolean` | - | +| authority | 准入权限/权限判断 | `string | array | Promise | (currentAuthority) => boolean | Promise` | - | | noMatch | 权限异常渲染元素,权限判断不通过时展示 | ReactNode | - | ### Authorized.AuthorizedRoute | 参数 | 说明 | 类型 | 默认值 | |----------|------------------------------------------|-------------|-------| -| authority | 准入权限/权限判断 | `string | array | Promise | (currentAuthority) => boolean` | - | +| authority | 准入权限/权限判断 | `string | array | Promise | (currentAuthority) => boolean | Promise` | - | | redirectPath | 权限异常时重定向的页面路由 | string | - | 其余参数与 `Route` 相同。 @@ -43,16 +43,16 @@ order: 15 | 参数 | 说明 | 类型 | 默认值 | |----------|------------------------------------------|-------------|-------| -| authority | 准入权限/权限判断 | `string | Promise | (currentAuthority) => boolean` | - | +| authority | 准入权限/权限判断 | `string | Promise | (currentAuthority) => boolean | Promise` | - | | error | 权限异常时渲染元素 | ReactNode | | ### Authorized.check -函数形式的 Authorized,用于某些不能被 HOC 包裹的组件。 `Authorized.check(authority, target, Exception)` +函数形式的 Authorized,用于某些不能被 HOC 包裹的组件。 `Authorized.check(authority, target, Exception)` 注意:传入一个 Promise 时,无论正确还是错误返回的都是一个 ReactClass。 | 参数 | 说明 | 类型 | 默认值 | |----------|------------------------------------------|-------------|-------| -| authority | 准入权限/权限判断 | `string | Promise | (currentAuthority) => boolean` | - | +| authority | 准入权限/权限判断 | `string | Promise | (currentAuthority) => boolean | Promise` | - | | target | 权限判断通过时渲染的元素 | ReactNode | - | | Exception | 权限异常时渲染元素 | ReactNode | - |