diff --git a/admin-web/config/router.config.js b/admin-web/config/router.config.js index 429db6aa5..64a10f6c5 100644 --- a/admin-web/config/router.config.js +++ b/admin-web/config/router.config.js @@ -21,6 +21,15 @@ export default [ Routes: ['src/pages/Authorized'], authority: ['admin', 'user'], routes: [ + // redirect + { path: '/', redirect: '/home' }, + // home + { + path: '/home', + name: 'home', + icon: 'user', + component: './Home/Home', + }, // admin { path: '/admin', @@ -34,8 +43,6 @@ export default [ }, ], }, - // dashboard - { path: '/', redirect: '/dashboard/analysis' }, { path: '/dashboard', name: 'dashboard', diff --git a/admin-web/src/components/AuthorityControl/demo/demo.md b/admin-web/src/components/AuthorityControl/demo/demo.md new file mode 100644 index 000000000..bf77f3462 --- /dev/null +++ b/admin-web/src/components/AuthorityControl/demo/demo.md @@ -0,0 +1,15 @@ + +--- + +使用 demo + + +authKey: 代表key的权限 + +--- + +```jsx harmony + + + +``` diff --git a/admin-web/src/components/AuthorityControl/index.d.ts b/admin-web/src/components/AuthorityControl/index.d.ts new file mode 100644 index 000000000..b54342194 --- /dev/null +++ b/admin-web/src/components/AuthorityControl/index.d.ts @@ -0,0 +1,7 @@ +import * as React from 'react'; + +export interface AuthorityControlProps { + authKey: string; +} + +export default class LoginItem extends React.Component {} diff --git a/admin-web/src/components/AuthorityControl/index.js b/admin-web/src/components/AuthorityControl/index.js new file mode 100644 index 000000000..3f5a404c2 --- /dev/null +++ b/admin-web/src/components/AuthorityControl/index.js @@ -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 ( + + {context => { + const { authList } = context; + return
{authList[authKey] ? children : '无权限'}
; + }} +
+ ); + } +} + +export default AuthorityControl; diff --git a/admin-web/src/layouts/GlobalAuthorityContext.js b/admin-web/src/layouts/GlobalAuthorityContext.js new file mode 100644 index 000000000..e0ee5ec51 --- /dev/null +++ b/admin-web/src/layouts/GlobalAuthorityContext.js @@ -0,0 +1,9 @@ +import React from 'react'; + +// 创建全局的权限控制 context,方便在所有页面使用 +const GlobalAuthorityContext = React.createContext({ + theme: 'dark', + toggle: () => {}, +}); + +export default GlobalAuthorityContext; diff --git a/admin-web/src/pages/Home/Home.js b/admin-web/src/pages/Home/Home.js new file mode 100644 index 000000000..f334d7ebb --- /dev/null +++ b/admin-web/src/pages/Home/Home.js @@ -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 ( + + + + +

home...

+
+ ); + } +}