Commit ecef6259 authored by jim's avatar jim

Modify the document

parent 31b8213f
---
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 = <Alert message="No permission." type="error" showIcon />;
ReactDOM.render(
<Authorized authority={['user', 'admin']} noMatch={noMatch}>
<Alert message="Use Array as a parameter passed!" type="success" showIcon />
</Authorized>,
mountNode,
);
```
---
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 = <Alert message="No permission." type="error" showIcon />;
const havePermission = () => {
return false;
};
ReactDOM.render(
<Authorized authority={havePermission} noMatch={noMatch}>
<Alert
message="Use Function as a parameter passed!"
type="success"
showIcon
/>
</Authorized>,
mountNode,
);
```
--- ---
order: 0 order: 0
title: title:
zh-CN: zh-CN: 本使用
en-US: Basic en-US: Basic use
--- ---
Authorized demo used Basic use
```jsx ```jsx
import RenderAuthorized from 'ant-design-pro/lib/Authorized'; import RenderAuthorized from 'ant-design-pro/lib/Authorized';
...@@ -14,31 +14,12 @@ import { Alert } from 'antd'; ...@@ -14,31 +14,12 @@ import { Alert } from 'antd';
const Authorized = RenderAuthorized('user'); const Authorized = RenderAuthorized('user');
const noMatch = <Alert message="No permission." type="error" showIcon />; const noMatch = <Alert message="No permission." type="error" showIcon />;
const havePermission = () => {
return false;
};
const havePermissionAsync = new Promise((resolve,reject)=>{
// Call resolve on behalf of passed
setTimeout( ()=> resolve() , 1000)
});
ReactDOM.render( ReactDOM.render(
<div> <div>
<Authorized authority="admin" noMatch={noMatch}> <Authorized authority="admin" noMatch={noMatch}>
<Alert message="user Passed!" type="success" showIcon /> <Alert message="user Passed!" type="success" showIcon />
</Authorized> </Authorized>
<Authorized authority={['user','admin']} noMatch={noMatch}>
<Alert message="Use Array as a parameter passed!" type="success" showIcon />
</Authorized>
<Authorized authority={havePermission} noMatch={noMatch}>
<Alert message="Use function as a parameter passed!" type="success" showIcon />
</Authorized>
<Authorized authority={havePermissionAsync} noMatch={noMatch}>
<Alert message="Use Promise as a parameter passed!" type="success" showIcon />
</Authorized>
</div>, </div>,
mountNode mountNode,
); );
``` ```
--- ---
order: 1 order: 3
title: title:
zh-CN: 注解 zh-CN: 注解基本使用
en-US: secured en-US: Basic use secured
--- ---
secured demo used secured demo used
...@@ -12,63 +12,16 @@ import RenderAuthorized from 'ant-design-pro/lib/Authorized'; ...@@ -12,63 +12,16 @@ import RenderAuthorized from 'ant-design-pro/lib/Authorized';
import { Alert } from 'antd'; import { Alert } from 'antd';
const { Secured } = RenderAuthorized('user'); const { Secured } = RenderAuthorized('user');
const noMatch = <Alert message="No permission." type="error" showIcon />;
const havePermission = () => { @Secured('admin')
return false;
};
const havePermissionAsync = new Promise((resolve, reject) => {
// Call resolve on behalf of passed
setTimeout(() => resolve(), 1000);
});
@Secured('admin', noMatch)
class TestSecuredString extends React.Component { class TestSecuredString extends React.Component {
render() { render() {
<Alert message="user Passed!" type="success" showIcon />; <Alert message="user Passed!" type="success" showIcon />;
} }
} }
@Secured(['user', 'admin'], noMatch)
class TestSecuredArray extends React.Component {
render() {
<Alert
message="Use Array as a parameter passed!"
type="success"
showIcon
/>;
}
}
@Secured(havePermission, noMatch)
class TestSecuredFunction extends React.Component {
render() {
<Alert
message="Use function as a parameter passed!"
type="success"
showIcon
/>;
}
}
@Secured(havePermissionAsync, noMatch)
class TestSecuredPromise extends React.Component {
render() {
<Alert
message="Use Promise as a parameter passed!"
type="success"
showIcon
/>;
}
}
ReactDOM.render( ReactDOM.render(
<div> <div>
<TestSecuredString /> <TestSecuredString />
<TestSecuredArray />
<TestSecuredFunction />
<TestSecuredPromise />
</div>, </div>,
mountNode, mountNode,
); );
......
...@@ -13,7 +13,12 @@ const { Secured } = Authorized; ...@@ -13,7 +13,12 @@ const { Secured } = Authorized;
const targetTime = new Date().getTime() + 3900000; 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 }) => ({ @connect(({ monitor, loading }) => ({
monitor, monitor,
loading: loading.models.monitor, loading: loading.models.monitor,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment