Browse Source

Modify the document

pull/654/head
jim 9 years ago
parent
commit
ecef62591f
  1. 23
      src/components/Authorized/demo/AuthorizedArray.md
  2. 31
      src/components/Authorized/demo/AuthorizedFunction.md
  3. 27
      src/components/Authorized/demo/basic.md
  4. 55
      src/components/Authorized/demo/secured.md
  5. 7
      src/routes/Dashboard/Monitor.js

23
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 = <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,
);
```

31
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 = <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,
);
```

27
src/components/Authorized/demo/basic.md

@ -1,11 +1,11 @@
--- ---
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';
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,
); );
``` ```

55
src/components/Authorized/demo/secured.md

@ -1,8 +1,8 @@
--- ---
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';
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,
); );

7
src/routes/Dashboard/Monitor.js

@ -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,

Loading…
Cancel
Save