diff --git a/src/components/Authorized/demo/AuthorizedArray.md b/src/components/Authorized/demo/AuthorizedArray.md new file mode 100644 index 0000000000000000000000000000000000000000..46eaf761ca62cb9fe8cb4a3daa78739213a5fa09 --- /dev/null +++ b/src/components/Authorized/demo/AuthorizedArray.md @@ -0,0 +1,23 @@ +--- +order: 1 +title: + zh-CN: 使用数组作为参数 + en-US: Use Array as a parameter +--- + +Use Array as a parameter + +```jsx +import RenderAuthorized from 'ant-design-pro/lib/Authorized'; +import { Alert } from 'antd'; + +const Authorized = RenderAuthorized('user'); +const noMatch = ; + +ReactDOM.render( + + + , + mountNode, +); +``` diff --git a/src/components/Authorized/demo/AuthorizedFunction.md b/src/components/Authorized/demo/AuthorizedFunction.md new file mode 100644 index 0000000000000000000000000000000000000000..8ad8b91e1bd656f5372e06ddadecb9d6e3eb1fb5 --- /dev/null +++ b/src/components/Authorized/demo/AuthorizedFunction.md @@ -0,0 +1,31 @@ +--- +order: 2 +title: + zh-CN: 使用方法作为参数 + en-US: Use function as a parameter +--- + +Use Function as a parameter + +```jsx +import RenderAuthorized from 'ant-design-pro/lib/Authorized'; +import { Alert } from 'antd'; + +const Authorized = RenderAuthorized('user'); +const noMatch = ; + +const havePermission = () => { + return false; +}; + +ReactDOM.render( + + + , + mountNode, +); +``` diff --git a/src/components/Authorized/demo/basic.md b/src/components/Authorized/demo/basic.md index 48f88d0bbb700043e1d4c92b4d85a61bff35b869..a5f12f29e23c4a10ca1163efa6635aafafa5ffbd 100644 --- a/src/components/Authorized/demo/basic.md +++ b/src/components/Authorized/demo/basic.md @@ -1,11 +1,11 @@ --- order: 0 title: - zh-CN: 基础 - en-US: Basic + zh-CN: 基本使用 + en-US: Basic use --- -Authorized demo used +Basic use ```jsx import RenderAuthorized from 'ant-design-pro/lib/Authorized'; @@ -14,31 +14,12 @@ import { Alert } from 'antd'; const Authorized = RenderAuthorized('user'); const noMatch = ; - -const havePermission = () => { - return false; -}; - -const havePermissionAsync = new Promise((resolve,reject)=>{ - // Call resolve on behalf of passed - setTimeout( ()=> resolve() , 1000) -}); - ReactDOM.render(
- - - - - - - - -
, - mountNode + mountNode, ); ``` diff --git a/src/components/Authorized/demo/secured.md b/src/components/Authorized/demo/secured.md index de943c0b4d7070e152d7071707ed8ec0023b132f..1e9537af19d3613b9ea6684f8933afa283ba1415 100644 --- a/src/components/Authorized/demo/secured.md +++ b/src/components/Authorized/demo/secured.md @@ -1,8 +1,8 @@ --- -order: 1 +order: 3 title: - zh-CN: 注解 - en-US: secured + zh-CN: 注解基本使用 + en-US: Basic use secured --- secured demo used @@ -12,63 +12,16 @@ import RenderAuthorized from 'ant-design-pro/lib/Authorized'; import { Alert } from 'antd'; const { Secured } = RenderAuthorized('user'); -const noMatch = ; -const havePermission = () => { - return false; -}; - -const havePermissionAsync = new Promise((resolve, reject) => { - // Call resolve on behalf of passed - setTimeout(() => resolve(), 1000); -}); - -@Secured('admin', noMatch) +@Secured('admin') class TestSecuredString extends React.Component { render() { ; } } - -@Secured(['user', 'admin'], noMatch) -class TestSecuredArray extends React.Component { - render() { - ; - } -} - -@Secured(havePermission, noMatch) -class TestSecuredFunction extends React.Component { - render() { - ; - } -} - -@Secured(havePermissionAsync, noMatch) -class TestSecuredPromise extends React.Component { - render() { - ; - } -} - ReactDOM.render(
- - -
, mountNode, ); diff --git a/src/routes/Dashboard/Monitor.js b/src/routes/Dashboard/Monitor.js index 7450fd9e5bfc3158d37f7f0c0fdae2ca4a331019..02b1ff877a61a1b0a5a0eb5d421b373d2d65d8b5 100644 --- a/src/routes/Dashboard/Monitor.js +++ b/src/routes/Dashboard/Monitor.js @@ -13,7 +13,12 @@ const { Secured } = Authorized; const targetTime = new Date().getTime() + 3900000; -@Secured('admin') +// use permission as a parameter +const havePermissionAsync = new Promise((resolve) => { + // Call resolve on behalf of passed + setTimeout(() => resolve(), 1000); +}); +@Secured(havePermissionAsync) @connect(({ monitor, loading }) => ({ monitor, loading: loading.models.monitor,