3.7 KiB
3.7 KiB
3.10 完整代码清单
:::tip 概述 本节汇总 example(案例演示)模块涉及的所有文件,方便开发时快速定位。 :::
后端文件清单
| 文件路径 | 说明 | 核心内容 |
|---|---|---|
app/Models/Example.php |
数据模型 | $table='example' + HasAuditColumns / SoftDeletesByFlag Trait |
app/Http/Requests/ExampleRequest.php |
表单请求验证 | name 必填等格式规则 + 中文错误消息 |
app/Services/ExampleService.php |
业务服务 | 属性配置(查询/唯一/字典)+ 4 个 Trait + import/export |
app/Http/Controllers/Api/ExampleController.php |
控制器 | 9 个接口(page/list/detail/add/update/delete/batchDelete/export/import) |
routes/api.php |
路由 | example 模块 9 条路由(认证中间件组内) |
前端文件清单(本仓库 ui/ 目录)
| 文件路径 | 说明 |
|---|---|
ui/src/api/tool/example.ts |
API 接口模块(9 个函数) |
ui/src/views/tool/example/index.vue |
列表页 |
ui/src/views/tool/example/edit.vue |
新增/编辑弹窗 |
ui/src/views/tool/example/detail.vue |
详情弹窗 |
ui/src/views/tool/example/columns.ts |
表格列配置 |
ui/src/views/tool/example/querySchemas.ts |
查询条件配置 |
数据库
| 对象 | 说明 |
|---|---|
laravel_example 表 |
案例演示数据表(模型 $table='example',前缀由 DB_PREFIX 拼接) |
权限节点
| 权限码 | 说明 |
|---|---|
sys:example:page |
案例演示分页列表 |
sys:example:list |
案例演示列表 |
sys:example:detail |
案例演示详情 |
sys:example:add |
添加案例演示 |
sys:example:update |
修改案例演示 |
sys:example:delete |
删除案例演示 |
sys:example:batchDelete |
批量删除案例演示 |
sys:example:import |
导入案例演示 |
sys:example:export |
导出案例演示 |
字典数据
| 字典编码 | 说明 | 字典项 |
|---|---|---|
example_type |
案例类型 | 按实际配置(1-4) |
example_status |
案例状态 | 1=在用, 2=停用 |
对应 Service 配置:
protected array $serializeMaps = [
'status' => 'example_status', // 读取时补 statusText
];
涉及的基类与 Trait
| 文件 | 作用 |
|---|---|
app/Http/Controllers/Controller.php |
控制器基类(_page 等快捷方法 + 响应封装) |
app/Http/Requests/BaseRequest.php |
请求基类(统一失败响应) |
app/Services/BaseService.php |
服务基类(全部声明式属性 + 占位方法) |
app/Services/Concerns/HasCrudOperations.php |
CRUD 主流程 + 钩子 + 事务 |
app/Services/Concerns/HasQueryScopes.php |
查询构建 + 排序白名单 |
app/Services/Concerns/HasSerializeMaps.php |
字典翻译 |
app/Services/Concerns/HasUniqueCheck.php |
唯一性校验 |
app/Services/Concerns/HasConfigValueProcessing.php |
配置项 value 按类型处理(文件迁移 / valueList) |
app/Models/Concerns/SoftDeletesByFlag.php |
软删除 |
app/Models/Concerns/HasAuditColumns.php |
审计字段 |
app/Attributes/Permission.php / OperationLog.php |
权限 / 日志注解 |
代码生成器替代方案
example 模块本身就是代码生成器的参考模板。如果需要生成类似模块:
- 建好数据库表(见 3.2 数据库建表)
- 访问「开发工具 → 代码生成」页面(父菜单 id=189),或执行
php artisan generate:code {表名} - 选择表,配置菜单挂载点与应用名
- 自动创建 Model / FormRequest / Service / Controller / 路由 / 菜单权限 / 前端文件
详见 第 10 章 代码生成器。