-
Notifications
You must be signed in to change notification settings - Fork 18
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
93b8372
commit cd547df
Showing
37 changed files
with
5,407 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ name: Build & Deploy | |
on: | ||
push: | ||
branches: | ||
- dev | ||
- dev2 | ||
|
||
env: | ||
SKIP_PREFLIGHT_CHECK: true | ||
|
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,15 @@ | ||
import { defineConfig } from 'dumi'; | ||
|
||
export default defineConfig({ | ||
outputPath: 'dist', | ||
themeConfig: { | ||
name: 'antdp', | ||
logo:'/logo.svg', | ||
editLink:true, | ||
socialLinks: { | ||
github: 'https://github.com/antdpro/antdp', | ||
}, | ||
footer: 'Copyright © 2023 antdp. All rights reserved.' , | ||
nav:[{title:'实例预览',link:'https://stackblitz.com/github/antdpro/antdp/tree/master/examples/antdp-base?embed=1&hideNavigation=0&hidedevtools=0'},{title:'教程',link:'/guide/quick-start'},{title:'组件',link:'/component/user-login'}] | ||
}, | ||
}); |
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,13 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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 @@ | ||
node_modules | ||
/dist | ||
.dumi/tmp | ||
.dumi/tmp-production | ||
.DS_Store |
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,3 @@ | ||
.dumi/tmp | ||
.dumi/tmp-production | ||
*.yaml |
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,14 @@ | ||
module.exports = { | ||
printWidth: 80, | ||
proseWrap: 'never', | ||
singleQuote: true, | ||
trailingComma: 'all', | ||
overrides: [ | ||
{ | ||
files: '*.md', | ||
options: { | ||
proseWrap: 'preserve', | ||
}, | ||
}, | ||
], | ||
}; |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,20 @@ | ||
# | ||
|
||
A static site base on [dumi](https://d.umijs.org). | ||
|
||
## Development | ||
|
||
```bash | ||
# install dependencies | ||
$ yarn install | ||
|
||
# start dev server | ||
$ yarn start | ||
|
||
# build docs | ||
$ yarn run build | ||
``` | ||
|
||
## LICENSE | ||
|
||
MIT |
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,181 @@ | ||
--- | ||
nav: 组件 | ||
group: 依赖 | ||
order: 6 | ||
--- | ||
|
||
## @antdp/authorized | ||
|
||
[![npm](https://img.shields.io/npm/v/@antdp/authorized.svg?maxAge=3600)](https://www.npmjs.com/package/@antdp/authorized) | ||
[![npm download](https://img.shields.io/npm/dm/@antdp/authorized.svg?style=flat)](https://www.npmjs.com/package/@antdp/authorized) | ||
|
||
权限判断组件或方法,通过判断是否进入主界面还是登录界面。 | ||
|
||
## 下载依赖 | ||
|
||
```bash | ||
$ npm i @antdp/authorized # yarn add @antdp/authorized | ||
``` | ||
|
||
## 启用方式 | ||
|
||
配置开启。同时需要 config/config.ts 提供权限配置。 | ||
|
||
```diff | ||
import config from '@antdp/config'; | ||
import proxy from './proxy'; | ||
import router from './router.json'; | ||
export default config(router, { | ||
proxy, | ||
define: { | ||
+ ANTD_AUTH_CONF: { | ||
+ auth_menu: 'authMenu', | ||
+ auth_btn: 'authBtn', | ||
+ auth_check_url: true, | ||
} | ||
}); | ||
``` | ||
|
||
### `ANTD_AUTH_CONF` 权限配置参数 | ||
|
||
| 参数 | 说明 | 类型 | 默认值 | | ||
| -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ---------- | | ||
| auth_menu | 储存菜单路由权限---本地 keys | `string` | `authMenu` | | ||
| auth_btn | 储存按钮路径权限---本地 keys | `string` | `authBtn` | | ||
| auth_check_url | 判断路径是否有权限的字段 默认值`menuUrl`,如果字段设置为`undefined`则`auth_menu`和`auth_btn`储存形式为 `["/web"]`,反之储存形式为`[{menuUrl:"/web"}]` | `string` | `menuUrl` | | ||
|
||
## 路由菜单权限 | ||
|
||
这是你的路由菜单(config/router.json) | ||
|
||
```json | ||
[ | ||
{ | ||
"path": "/login", | ||
"component": "@/layouts/UserLayout" | ||
}, | ||
{ | ||
"path": "/", | ||
"component": "@/layouts/BasicLayout", | ||
"routes": [ | ||
{ | ||
"path": "/", | ||
"redirectTo": "/welcome" | ||
}, | ||
{ | ||
"path": "/welcome", | ||
"name": "首页", | ||
"icon": "welcome", | ||
"locale": "welcome", | ||
"component": "@/pages/Home/index" | ||
}, | ||
{ | ||
"path": "/404", | ||
"name": "404", | ||
"hideInMenu": true, | ||
"icon": "file-protect", | ||
"component": "@/pages/404" | ||
}, | ||
{ | ||
"path": "/403", | ||
"name": "403", | ||
"hideInMenu": true, | ||
"icon": "file-protect", | ||
"component": "@/pages/403" | ||
} | ||
] | ||
} | ||
] | ||
``` | ||
|
||
登陆后后端返回的菜单列表可能如下 | ||
|
||
```js | ||
const menus = ['/', '/welcome', '/404', '/403']; | ||
``` | ||
|
||
### 路由匹配过程 | ||
|
||
- 1.当你登陆成功后,你需将其保存于你的 sessionStorage 中,储存的字段为你`ANTD_AUTH_CONF`中配的`auth_menu`字段,并在登陆后存储在`sessionStorage`中,如`sessionStorage.setItem('authMenu', JSON.stringify([]))` | ||
- 2.当你跳转至页面时,会根据 sessionStorage 中`authMenu`进行权限匹配,如果没有权限则会跳往 404 或 403 页面 | ||
|
||
<strong>请保证 403 和 404 页面存在</strong> | ||
|
||
## 页面权限重定向 | ||
|
||
如果你想根据 `token`判断是否重定向回登陆页,可在 layouts/BasicLayout.ts 中添加`Authorized` | ||
|
||
```ts | pure | ||
import Authorized from '@antdp/authorized'; | ||
import BasicLayouts from '@antdp/basic-layouts'; | ||
|
||
const Layout = () => { | ||
const token = ''; | ||
return ( | ||
<Authorized authority={!!token} redirectPath="/login"> | ||
<BasicLayouts projectName="Ant Design" /> | ||
</Authorized> | ||
); | ||
}; | ||
|
||
export default Layout; | ||
``` | ||
|
||
## 按钮权限 | ||
|
||
很多大型项目中,也会对按钮权限进行管理,请提前配置好`ANTD_AUTH_CONF`中配的`auth_btn`字段,并在登陆后存储在`sessionStorage`中,如`sessionStorage.setItem("authBtn",JSON.stringify(['/api/select']))` | ||
|
||
```tsx | pure | ||
// 为了渲染设置的本地权限数 | ||
import { AuthorizedBtn } from '@antdp/authorized'; | ||
const Demo = () => { | ||
return ( | ||
<AuthorizedBtn path="/api/select"> | ||
<button>按钮</button> | ||
</AuthorizedBtn> | ||
); | ||
}; | ||
export default Demo; | ||
``` | ||
|
||
### AuthorizedBtn 参数 | ||
|
||
| 参数 | 说明 | 类型 | 默认值 | | ||
| -------- | -------- | ----------------- | ------ | | ||
| path | 权限路径 | `string` | - | | ||
| children | 展示内容 | `React.ReactNode` | - | | ||
|
||
## 使用 AuthorizedConfigProvider 设置按钮权限配置 | ||
|
||
使用 `AuthorizedConfigProvider`可以自己进行重新设置组件包裹内的所有按钮的权限参数,不使用默认配置的按钮权限配置 | ||
|
||
```tsx | pure | ||
import { AuthorizedBtn, AuthorizedConfigProvider } from '@antdp/authorized'; | ||
const Page = () => { | ||
useEffect(() => { | ||
sessionStorage.setItem('btn', JSON.stringify([{ menuUrl: '/api/select' }])); | ||
}, []); | ||
return ( | ||
<AuthorizedConfigProvider isCheckAuth={true} auth_btn="btn"> | ||
<AuthorizedBtn path="/api/select"> | ||
<button>查询</button> | ||
</AuthorizedBtn> | ||
</AuthorizedConfigProvider> | ||
); | ||
}; | ||
export default Page; | ||
``` | ||
|
||
### AuthorizedConfigProvider 参数 | ||
|
||
| 参数 | 说明 | 类型 | 默认值 | | ||
| -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ---------- | | ||
| auth_menu | 储存菜单路由权限---本地 keys | `string` | `authMenu` | | ||
| auth_btn | 储存按钮路径权限---本地 keys | `string` | `authBtn` | | ||
| auth_check_url | 判断路径是否有权限的字段 默认值`menuUrl`,如果字段设置为`undefined`则`auth_menu`和`auth_btn`储存形式为 `["/web"]`,反之储存形式为`[{menuUrl:"/web"}]` | `string` | `menuUrl` | | ||
| isCheckAuth | 是否检查权限 | `boolean` | `false` | | ||
| children | 子内容 | `string` | - | | ||
|
||
## License | ||
|
||
Licensed under the MIT License. |
Oops, something went wrong.