Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
f5b105973d
@ -21,6 +21,15 @@ export default [
|
|||||||
Routes: ['src/pages/Authorized'],
|
Routes: ['src/pages/Authorized'],
|
||||||
authority: ['admin', 'user'],
|
authority: ['admin', 'user'],
|
||||||
routes: [
|
routes: [
|
||||||
|
// redirect
|
||||||
|
{ path: '/', redirect: '/home' },
|
||||||
|
// home
|
||||||
|
{
|
||||||
|
path: '/home',
|
||||||
|
name: 'home',
|
||||||
|
icon: 'user',
|
||||||
|
component: './Home/Home',
|
||||||
|
},
|
||||||
// admin
|
// admin
|
||||||
{
|
{
|
||||||
path: '/admin',
|
path: '/admin',
|
||||||
@ -34,8 +43,6 @@ export default [
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
// dashboard
|
|
||||||
{ path: '/', redirect: '/dashboard/analysis' },
|
|
||||||
{
|
{
|
||||||
path: '/dashboard',
|
path: '/dashboard',
|
||||||
name: 'dashboard',
|
name: 'dashboard',
|
||||||
|
15
admin-web/src/components/AuthorityControl/demo/demo.md
Normal file
15
admin-web/src/components/AuthorityControl/demo/demo.md
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
使用 demo
|
||||||
|
|
||||||
|
|
||||||
|
authKey: 代表key的权限
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
```jsx harmony
|
||||||
|
<AuthorityControl authKey="home.button">
|
||||||
|
<Button type="primary">按钮 控制</Button>
|
||||||
|
</AuthorityControl>
|
||||||
|
```
|
7
admin-web/src/components/AuthorityControl/index.d.ts
vendored
Normal file
7
admin-web/src/components/AuthorityControl/index.d.ts
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
export interface AuthorityControlProps {
|
||||||
|
authKey: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class LoginItem extends React.Component<AuthorityControlProps, any> {}
|
19
admin-web/src/components/AuthorityControl/index.js
Normal file
19
admin-web/src/components/AuthorityControl/index.js
Normal 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;
|
9
admin-web/src/layouts/GlobalAuthorityContext.js
Normal file
9
admin-web/src/layouts/GlobalAuthorityContext.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
// 创建全局的权限控制 context,方便在所有页面使用
|
||||||
|
const GlobalAuthorityContext = React.createContext({
|
||||||
|
theme: 'dark',
|
||||||
|
toggle: () => {},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default GlobalAuthorityContext;
|
28
admin-web/src/pages/Home/Home.js
Normal file
28
admin-web/src/pages/Home/Home.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import React, { Component } from 'react';
|
||||||
|
import { Button } from 'antd';
|
||||||
|
import AuthorityControl from '../../components/AuthorityControl';
|
||||||
|
import GlobalAuthority from '../../layouts/GlobalAuthorityContext';
|
||||||
|
|
||||||
|
export default class Home extends Component {
|
||||||
|
state = {};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
// 定义认证的属性 TODO
|
||||||
|
const GlobalAuthorityProps = {
|
||||||
|
user: 'admin',
|
||||||
|
login: 'success',
|
||||||
|
authList: {
|
||||||
|
'auth.button': true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<GlobalAuthority.Provider value={GlobalAuthorityProps}>
|
||||||
|
<AuthorityControl authKey="home.button">
|
||||||
|
<Button type="primary">按钮 控制</Button>
|
||||||
|
</AuthorityControl>
|
||||||
|
<h1>home...</h1>
|
||||||
|
</GlobalAuthority.Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user