更新后端规则文档
This commit is contained in:
@@ -521,6 +521,22 @@ php artisan module:make-migration create_posts_table Blog
|
||||
}
|
||||
```
|
||||
|
||||
**树形响应:**
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"data": [
|
||||
{...,children: [
|
||||
{...}
|
||||
]},
|
||||
{...,children: [
|
||||
{...}
|
||||
]}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### HTTP 状态码规范
|
||||
|
||||
- `200 OK`: 请求成功
|
||||
@@ -671,7 +687,22 @@ return new class extends Migration
|
||||
|
||||
#### 菜单权限节点 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 @@ return new class extends Migration
|
||||
- 前端会将菜单数据转换为路由,所有页面路由都会挂载到 Layout 布局下
|
||||
- 不需要在前端维护嵌套的路由结构
|
||||
|
||||
**Seeder 示例:**
|
||||
** Seeder 示例:**
|
||||
|
||||
```php
|
||||
<?php
|
||||
@@ -700,16 +731,17 @@ private function createPermissions(): void
|
||||
$permissions = [
|
||||
// 顶级菜单(无 component)
|
||||
[
|
||||
'name' => '系统管理',
|
||||
'code' => 'system',
|
||||
'title' => '系统管理',
|
||||
'name' => 'system',
|
||||
'type' => 'menu',
|
||||
'parent_id' => 0,
|
||||
'route' => '/system',
|
||||
'path' => '/system',
|
||||
'component' => null, // 顶级菜单不需要 component
|
||||
'meta' => json_encode([
|
||||
'icon' => 'Setting',
|
||||
'hidden' => false,
|
||||
'hiddenBreadcrumb' => false,
|
||||
'keepAlive' => false
|
||||
]),
|
||||
'sort' => 1,
|
||||
'status' => 1,
|
||||
@@ -717,16 +749,17 @@ private function createPermissions(): void
|
||||
|
||||
// 最后一级菜单(有 component)
|
||||
[
|
||||
'name' => '用户管理',
|
||||
'code' => 'system.users',
|
||||
'title' => '用户管理',
|
||||
'name' => 'system.users',
|
||||
'type' => 'menu',
|
||||
'parent_id' => 0,
|
||||
'route' => '/system/users',
|
||||
'path' => '/system/users',
|
||||
'component' => 'system/users/index', // 最后一级菜单需要 component
|
||||
'meta' => json_encode([
|
||||
'icon' => 'User',
|
||||
'hidden' => false,
|
||||
'hiddenBreadcrumb' => false,
|
||||
'keepAlive' => true
|
||||
]),
|
||||
'sort' => 1,
|
||||
'status' => 1,
|
||||
@@ -734,16 +767,29 @@ private function createPermissions(): void
|
||||
|
||||
// 按钮权限(无 component)
|
||||
[
|
||||
'name' => '查看用户',
|
||||
'code' => 'system.users.view',
|
||||
'title' => '查看用户',
|
||||
'name' => 'system.users.view',
|
||||
'type' => 'button',
|
||||
'parent_id' => 0,
|
||||
'route' => 'admin.users.index',
|
||||
'path' => 'admin.users.index',
|
||||
'component' => null, // 非菜单类型不需要 component
|
||||
'meta' => null,
|
||||
'sort' => 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) {
|
||||
@@ -754,8 +800,10 @@ private function createPermissions(): void
|
||||
|
||||
**重要说明:**
|
||||
|
||||
- `title` 用于显示在菜单中的标题
|
||||
- `name` 是权限的唯一标识编码,用于前端路由和权限验证
|
||||
- `parent_id` 主要用于构建菜单树的层级关系(侧边栏显示)
|
||||
- 路由层面不需要维护嵌套结构,所有页面路由都在同一层级
|
||||
- `path` 用于菜单类型的路由路径,或 API 类型的接口路由名称
|
||||
- `component` 值只需要在最后一级菜单(叶子节点)中设置
|
||||
- 前端会根据 `type` 字段判断是否需要加载组件
|
||||
|
||||
|
||||
Reference in New Issue
Block a user