From ecef62591f1d65d10d6baea1023ae265dc767b45 Mon Sep 17 00:00:00 2001 From: jim Date: Wed, 10 Jan 2018 18:00:13 +0800 Subject: [PATCH] Modify the document --- .../Authorized/demo/AuthorizedArray.md | 23 ++++++++ .../Authorized/demo/AuthorizedFunction.md | 31 +++++++++++ src/components/Authorized/demo/basic.md | 27 ++------- src/components/Authorized/demo/secured.md | 55 ++----------------- src/routes/Dashboard/Monitor.js | 7 ++- 5 files changed, 68 insertions(+), 75 deletions(-) create mode 100644 src/components/Authorized/demo/AuthorizedArray.md create mode 100644 src/components/Authorized/demo/AuthorizedFunction.md diff --git a/src/components/Authorized/demo/AuthorizedArray.md b/src/components/Authorized/demo/AuthorizedArray.md new file mode 100644 index 00000000..46eaf761 --- /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 00000000..8ad8b91e --- /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 48f88d0b..a5f12f29 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 de943c0b..1e9537af 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 7450fd9e..02b1ff87 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, -- GitLab