更新后端规则文档
This commit is contained in:
+60
-12
@@ -521,6 +521,22 @@ ### 统一响应格式
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**树形响应:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 200,
|
||||||
|
"message": "success",
|
||||||
|
"data": [
|
||||||
|
{...,children: [
|
||||||
|
{...}
|
||||||
|
]},
|
||||||
|
{...,children: [
|
||||||
|
{...}
|
||||||
|
]}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### HTTP 状态码规范
|
### HTTP 状态码规范
|
||||||
|
|
||||||
- `200 OK`: 请求成功
|
- `200 OK`: 请求成功
|
||||||
@@ -671,7 +687,22 @@ #### 业务模块数据填充
|
|||||||
|
|
||||||
#### 菜单权限节点 Seed 规范
|
#### 菜单权限节点 Seed 规范
|
||||||
|
|
||||||
在 Seeder 文件中创建菜单权限节点时,需要遵循以下规范:
|
在 Seeder 文件中创建菜单权限节点时,需要遵循以下规范。
|
||||||
|
|
||||||
|
**数据库字段说明 (auth_permissions 表):**
|
||||||
|
|
||||||
|
| 字段 | 类型 | 说明 |
|
||||||
|
|------|------|------|
|
||||||
|
| id | number | 权限ID |
|
||||||
|
| title | string | 权限标题(用于菜单显示) |
|
||||||
|
| name | string | 权限编码(唯一标识) |
|
||||||
|
| type | string | 权限类型:menu(菜单)、api(接口)、button(按钮)、url(链接) |
|
||||||
|
| parent_id | number | 父级ID,顶级菜单为 0 |
|
||||||
|
| path | string | 路由路径(如 `/system/users`) |
|
||||||
|
| component | string | 前端组件路径(如 `system/users/index`) |
|
||||||
|
| meta | json | 元数据(包含 icon、hidden、keepAlive 等) |
|
||||||
|
| sort | number | 排序 |
|
||||||
|
| status | number | 状态:1启用 0禁用 |
|
||||||
|
|
||||||
**菜单结构规范:**
|
**菜单结构规范:**
|
||||||
|
|
||||||
@@ -690,7 +721,7 @@ #### 菜单权限节点 Seed 规范
|
|||||||
- 前端会将菜单数据转换为路由,所有页面路由都会挂载到 Layout 布局下
|
- 前端会将菜单数据转换为路由,所有页面路由都会挂载到 Layout 布局下
|
||||||
- 不需要在前端维护嵌套的路由结构
|
- 不需要在前端维护嵌套的路由结构
|
||||||
|
|
||||||
**Seeder 示例:**
|
** Seeder 示例:**
|
||||||
|
|
||||||
```php
|
```php
|
||||||
<?php
|
<?php
|
||||||
@@ -700,16 +731,17 @@ #### 菜单权限节点 Seed 规范
|
|||||||
$permissions = [
|
$permissions = [
|
||||||
// 顶级菜单(无 component)
|
// 顶级菜单(无 component)
|
||||||
[
|
[
|
||||||
'name' => '系统管理',
|
'title' => '系统管理',
|
||||||
'code' => 'system',
|
'name' => 'system',
|
||||||
'type' => 'menu',
|
'type' => 'menu',
|
||||||
'parent_id' => 0,
|
'parent_id' => 0,
|
||||||
'route' => '/system',
|
'path' => '/system',
|
||||||
'component' => null, // 顶级菜单不需要 component
|
'component' => null, // 顶级菜单不需要 component
|
||||||
'meta' => json_encode([
|
'meta' => json_encode([
|
||||||
'icon' => 'Setting',
|
'icon' => 'Setting',
|
||||||
'hidden' => false,
|
'hidden' => false,
|
||||||
'hiddenBreadcrumb' => false,
|
'hiddenBreadcrumb' => false,
|
||||||
|
'keepAlive' => false
|
||||||
]),
|
]),
|
||||||
'sort' => 1,
|
'sort' => 1,
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
@@ -717,16 +749,17 @@ #### 菜单权限节点 Seed 规范
|
|||||||
|
|
||||||
// 最后一级菜单(有 component)
|
// 最后一级菜单(有 component)
|
||||||
[
|
[
|
||||||
'name' => '用户管理',
|
'title' => '用户管理',
|
||||||
'code' => 'system.users',
|
'name' => 'system.users',
|
||||||
'type' => 'menu',
|
'type' => 'menu',
|
||||||
'parent_id' => 0,
|
'parent_id' => 0,
|
||||||
'route' => '/system/users',
|
'path' => '/system/users',
|
||||||
'component' => 'system/users/index', // 最后一级菜单需要 component
|
'component' => 'system/users/index', // 最后一级菜单需要 component
|
||||||
'meta' => json_encode([
|
'meta' => json_encode([
|
||||||
'icon' => 'User',
|
'icon' => 'User',
|
||||||
'hidden' => false,
|
'hidden' => false,
|
||||||
'hiddenBreadcrumb' => false,
|
'hiddenBreadcrumb' => false,
|
||||||
|
'keepAlive' => true
|
||||||
]),
|
]),
|
||||||
'sort' => 1,
|
'sort' => 1,
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
@@ -734,16 +767,29 @@ #### 菜单权限节点 Seed 规范
|
|||||||
|
|
||||||
// 按钮权限(无 component)
|
// 按钮权限(无 component)
|
||||||
[
|
[
|
||||||
'name' => '查看用户',
|
'title' => '查看用户',
|
||||||
'code' => 'system.users.view',
|
'name' => 'system.users.view',
|
||||||
'type' => 'button',
|
'type' => 'button',
|
||||||
'parent_id' => 0,
|
'parent_id' => 0,
|
||||||
'route' => 'admin.users.index',
|
'path' => 'admin.users.index',
|
||||||
'component' => null, // 非菜单类型不需要 component
|
'component' => null, // 非菜单类型不需要 component
|
||||||
'meta' => null,
|
'meta' => null,
|
||||||
'sort' => 1,
|
'sort' => 1,
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
],
|
],
|
||||||
|
|
||||||
|
// API 权限
|
||||||
|
[
|
||||||
|
'title' => '获取用户列表',
|
||||||
|
'name' => 'system.users.list',
|
||||||
|
'type' => 'api',
|
||||||
|
'parent_id' => 0,
|
||||||
|
'path' => 'admin.users.index',
|
||||||
|
'component' => null,
|
||||||
|
'meta' => null,
|
||||||
|
'sort' => 1,
|
||||||
|
'status' => 1,
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($permissions as $permission) {
|
foreach ($permissions as $permission) {
|
||||||
@@ -754,8 +800,10 @@ #### 菜单权限节点 Seed 规范
|
|||||||
|
|
||||||
**重要说明:**
|
**重要说明:**
|
||||||
|
|
||||||
|
- `title` 用于显示在菜单中的标题
|
||||||
|
- `name` 是权限的唯一标识编码,用于前端路由和权限验证
|
||||||
- `parent_id` 主要用于构建菜单树的层级关系(侧边栏显示)
|
- `parent_id` 主要用于构建菜单树的层级关系(侧边栏显示)
|
||||||
- 路由层面不需要维护嵌套结构,所有页面路由都在同一层级
|
- `path` 用于菜单类型的路由路径,或 API 类型的接口路由名称
|
||||||
- `component` 值只需要在最后一级菜单(叶子节点)中设置
|
- `component` 值只需要在最后一级菜单(叶子节点)中设置
|
||||||
- 前端会根据 `type` 字段判断是否需要加载组件
|
- 前端会根据 `type` 字段判断是否需要加载组件
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user