Skip to content

Commit 0c852ea

Browse files
author
wyc001122
committed
feat: add access control docs
1 parent fa5df1f commit 0c852ea

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

docs/src/en/guide/in-depth/access.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ outline: deep
44

55
# Access Control
66

7-
The framework has built-in two types of access control methods:
7+
The framework has built-in three types of access control methods:
88

99
- Determining whether a menu or button can be accessed based on user roles
1010
- Determining whether a menu or button can be accessed through an API
11+
- Using a mixed mode that combines both frontend role-based and backend API-based access control
1112

1213
## Frontend Access Control
1314

@@ -151,6 +152,43 @@ const dashboardMenus = [
151152

152153
At this point, the configuration is complete. You need to ensure that after logging in, the format of the menu returned by the interface is correct; otherwise, access will not be possible.
153154

155+
156+
## Mixed Access Control
157+
158+
**Implementation Principle**: The mixed mode combines both frontend and backend access control methods, merging the route tables generated from frontend static routes and backend dynamic routes. This approach ensures both the stability of basic routes and the flexibility of permission control. The system simultaneously filters frontend routes based on roles and retrieves dynamic routes from the backend, ultimately combining these two parts to generate a complete route table.
159+
160+
**Advantage**: It offers the benefits of both frontend and backend control. Core fixed routes can be maintained in the frontend, while business-related dynamic routes are controlled by the backend, enabling a more flexible permission management solution.
161+
162+
**Application Scenario**: Suitable for application systems that have both fixed system function modules and business modules requiring flexible configuration.
163+
164+
### Steps
165+
166+
- Ensure the current mode is set to mixed access control
167+
168+
Adjust `preferences.ts` in the corresponding application directory to ensure `accessMode='mixed'`.
169+
170+
```ts
171+
import { defineOverridesPreferences } from '@vben/preferences';
172+
173+
export const overridesPreferences = defineOverridesPreferences({
174+
// overrides
175+
app: {
176+
accessMode: 'mixed',
177+
},
178+
});
179+
```
180+
181+
- Configure frontend route permissions (same as frontend access control)
182+
183+
- Ensure the roles returned by the interface match the permissions in the frontend route table (same as frontend access control)
184+
185+
- Ensure the structure of the menu data returned by the interface is correct (same as backend access control)
186+
187+
You need to ensure that user roles match the permission settings in the frontend routes, and that the menu data structure returned by the backend is also correct.
188+
189+
At this point, the mixed mode configuration is complete. The system will process both frontend static routes and backend dynamic routes, merging them to generate the final route table and menu.
190+
191+
154192
## Fine-grained Control of Buttons
155193

156194
In some cases, we need to control the display of buttons with fine granularity. We can control the display of buttons through interfaces or roles.

docs/src/guide/in-depth/access.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ outline: deep
44

55
# 权限
66

7-
框架内置了两种权限控制方式
7+
框架内置了三种权限控制方式
88

99
- 通过用户角色来判断菜单或者按钮是否可以访问
1010
- 通过接口来判断菜单或者按钮是否可以访问
11+
- 通过混合模式同时结合前端角色和后端接口控制访问
1112

1213
## 前端访问控制
1314

@@ -159,6 +160,42 @@ const dashboardMenus = [
159160

160161
到这里,就已经配置完成,你需要确保登录后,接口返回的菜单格式正确,否则无法访问。
161162

163+
164+
## 混合访问控制
165+
166+
**实现原理**: 混合模式同时结合了前端与后端的访问控制方式,将前端访问控制生成的路由表与后端访问控制生成的路由表合并成完整的路由表。这种方式结合了两种访问控制的优点,实现静态和动态路由的结合。
167+
168+
**优点**: 兼具前端和后端控制的优势,可以将核心固定路由在前端维护,而将业务相关的动态路由交由后端控制,实现更加灵活的权限管理方案。
169+
170+
**应用场景**: 适合既有固定的系统功能模块,又有需要灵活配置的业务模块的应用系统。
171+
172+
### 步骤
173+
174+
- 确保当前模式为混合访问控制模式
175+
176+
调整对应应用目录下的`preferences.ts`,确保`accessMode='mixed'`
177+
178+
```ts
179+
import { defineOverridesPreferences } from '@vben/preferences';
180+
181+
export const overridesPreferences = defineOverridesPreferences({
182+
// overrides
183+
app: {
184+
accessMode: 'mixed',
185+
},
186+
});
187+
```
188+
189+
- 配置前端路由权限(同前端访问控制)
190+
191+
- 确保接口返回的角色和前端路由表的权限匹配(同前端访问控制)
192+
193+
- 确保接口返回的菜单数据结构正确(同后端访问控制)
194+
195+
需要确保用户角色与前端路由的权限设置匹配,同时后端返回的菜单数据结构也需要正确。
196+
197+
到这里,混合模式的配置就已经完成,系统会同时处理前端静态路由和后端动态路由,合并生成最终的路由表和菜单。
198+
162199
## 按钮细粒度控制
163200

164201
在某些情况下,我们需要对按钮进行细粒度的控制,我们可以借助接口或者角色来控制按钮的显示。

0 commit comments

Comments
 (0)