- 增加权限控制 组件

This commit is contained in:
sin 2019-02-28 13:36:32 +08:00
parent c198f93819
commit 6c94fc1fe2
3 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,15 @@
---
使用 demo
authKey: 代表key的权限
---
```jsx harmony
<AuthorityControl authKey="home.button">
<Button type="primary">按钮 控制</Button>
</AuthorityControl>
```

View File

@ -0,0 +1,7 @@
import * as React from 'react';
export interface AuthorityControlProps {
authKey: string;
}
export default class LoginItem extends React.Component<AuthorityControlProps, any> {}

View File

@ -0,0 +1,19 @@
import React, { PureComponent } from 'react';
import GlobalAuthority from '../../layouts/GlobalAuthority';
// 用于控制权限
class AuthorityControl extends PureComponent {
render() {
const { authKey, children } = this.props;
return (
<GlobalAuthority.Consumer>
{context => {
const { authList } = context;
return <div>{authList[authKey] ? children : '无权限'}</div>;
}}
</GlobalAuthority.Consumer>
);
}
}
export default AuthorityControl;