-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff420f6
commit df1b135
Showing
9 changed files
with
316 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# 权限管理 | ||
|
||
## 一、简介 | ||
在项目中经常有的场景是不同的用户的权限不同,通常有如下场景: | ||
- 不同的用户在页面中可以看到的元素和操作不同 | ||
- 不同的用户对页面的访问权限不同 | ||
|
||
```bash | ||
针对这些场景,我们为中台场景下常用的权限控制提供了一种更加简单、易用、通用的解决方案。实现了一个基于 umi 插件的权限管 | ||
理方案 - @uiw-admin/authorized。通过定义权限,使用权限,完成 React 组件内的执行权限控制,渲染权限控制。搭配 | ||
@uiw-admin/basic-layouts 插件一起使用,还可以进一步完成对路由权限的控制。 | ||
``` | ||
|
||
## 二、路由和菜单 | ||
当项目需要根据权限判断组件是否展示 使用组件时,请在 .kktprc.ts文件中配置全局变量(define)中AUTH=true | ||
```diff | ||
import config from "@uiw-admin/config" | ||
export default config({ | ||
define:{ | ||
+ AUTH:true, | ||
// ... | ||
} | ||
// ... | ||
}) | ||
``` | ||
如果是路由权限判断,请在route.json中添加对应菜单的权限``isAuth`` | ||
```json | ||
[ | ||
{ | ||
"path": "/new", | ||
"name": "新页面", | ||
"element": "@page/NewPage", | ||
"icon": "home", | ||
"isAuth":true | ||
}, | ||
] | ||
``` | ||
|
||
然后在BasicLayout.tsx,使用 ``AuthPage``组件 | ||
```jsx | ||
import AuthPage from "@uiw-admin/authorized" | ||
import BasicLayout from '@uiw-admin/BasicLayout' | ||
export default ()=>{ | ||
return ( | ||
<AuthPage authority={true} redirectPath="/login"> | ||
<BasicLayout /> | ||
</AuthPage> | ||
) | ||
} | ||
``` | ||
|
||
## 三、页面中控件权限控制 | ||
```jsx | ||
import React from "react" | ||
import { AuthBtn } from "@uiw-admin/authorized" | ||
|
||
const Demos = ()=>{ | ||
return ( | ||
<div> | ||
<AuthBtn path="/dom/save" > | ||
子集渲染1 | ||
</AuthBtn> | ||
<AuthBtn path="/dom/edit" disabled > | ||
<button>子集渲染2</button> | ||
</AuthBtn> | ||
<AuthBtn path="/dom/edit1" disabled > | ||
<button>子集渲染3</button> | ||
</AuthBtn> | ||
<AuthBtn path="/dom/edit1" > | ||
<button>子集渲染4</button> | ||
</AuthBtn> | ||
</div> | ||
) | ||
} | ||
export default Demos | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Preview from '../../components/Preview'; | ||
|
||
const Page = () => <Preview path={() => import('./README.md')} />; | ||
|
||
export default Page; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.