签入版本
This commit is contained in:
@@ -7,11 +7,12 @@
|
||||
## 第 1 步:建表
|
||||
|
||||
```sql
|
||||
CREATE TABLE think_example (
|
||||
CREATE TABLE laravel_example (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
name VARCHAR(200) NOT NULL COMMENT '案例名称',
|
||||
type TINYINT(1) DEFAULT 0 COMMENT '案例类型',
|
||||
status TINYINT(1) DEFAULT 0 COMMENT '案例状态',
|
||||
code VARCHAR(50) DEFAULT '' COMMENT '案例编码',
|
||||
type TINYINT(1) DEFAULT 1 COMMENT '案例类型',
|
||||
status TINYINT(1) DEFAULT 1 COMMENT '案例状态',
|
||||
sort INT DEFAULT 0 COMMENT '排序',
|
||||
avatar VARCHAR(500) DEFAULT '' COMMENT '头像',
|
||||
is_delete TINYINT(1) DEFAULT 0,
|
||||
@@ -22,10 +23,12 @@ CREATE TABLE think_example (
|
||||
);
|
||||
```
|
||||
|
||||
(含公共字段说明见 [3.2 数据库建表](/zh/guide/database.html)。)
|
||||
|
||||
## 第 2 步:代码生成器操作
|
||||
|
||||
1. 进入「工具管理 → 代码生成」
|
||||
2. 找到 `think_example` 表
|
||||
1. 进入「开发工具 → 代码生成」
|
||||
2. 找到 `laravel_example` 表
|
||||
3. 配置:
|
||||
- 模块名:`example`
|
||||
- 功能名:`案例演示`
|
||||
@@ -34,41 +37,54 @@ CREATE TABLE think_example (
|
||||
4. 点击「预览」查看生成代码
|
||||
5. 点击「生成」创建文件
|
||||
|
||||
或使用 CLI:
|
||||
|
||||
```bash
|
||||
php artisan generate:code "laravel_example|案例演示"
|
||||
```
|
||||
|
||||
## 第 3 步:生成的文件
|
||||
|
||||
```text
|
||||
app/controller/ExampleController.php # 控制器
|
||||
app/logic/ExampleLogic.php # 业务逻辑
|
||||
app/model/Example.php # 数据模型
|
||||
app/validate/ExampleValidate.php # 验证器
|
||||
ui/src/api/tool/example.ts # 前端 API
|
||||
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 # 查询表单配置
|
||||
app/Http/Controllers/Api/ExampleController.php # 控制器
|
||||
app/Services/ExampleService.php # 业务服务
|
||||
app/Models/Example.php # 数据模型
|
||||
app/Http/Requests/ExampleRequest.php # FormRequest
|
||||
ui/src/api/tool/example.ts # 前端 API
|
||||
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 # 查询表单配置
|
||||
```
|
||||
|
||||
:::tip 本项目内置示例
|
||||
项目初始化数据中已内置完整的 `example` 模块(后端代码 + 菜单权限 + 字典),可直接对照生成结果与 `app/Services/ExampleService.php` 等源码。
|
||||
:::
|
||||
|
||||
## 第 4 步:后续操作
|
||||
|
||||
生成完成后,以下内容已自动创建:
|
||||
|
||||
| 项目 | 状态 | 说明 |
|
||||
|------|------|------|
|
||||
| 路由 | ✅ 自动注册 | `route/app.php` 中已插入 CRUD 路由组 |
|
||||
| 菜单 | ✅ 自动创建 | 主菜单和权限节点已创建 |
|
||||
| 字典 | ✅ 自动创建 | 带选项的字段已创建字典和字典项 |
|
||||
| 路由 | ✅ 自动注册 | `routes/api.php` 中已插入 9 条 CRUD 路由 |
|
||||
| 菜单 | ✅ 自动创建 | 主菜单(type=0)和权限节点(type=1)已创建 |
|
||||
| 字典 | ✅ 自动创建 | 带选项的字段已创建字典和字典项(幂等) |
|
||||
|
||||
通常还需要手动调整:
|
||||
|
||||
1. 根据业务需求调整 Logic 属性配置(如 `pageLikeFields`、`pageEqFields`)
|
||||
1. 根据业务需求调整 Service 属性配置(如 `pageLikeFields`、`pageEqFields`)
|
||||
2. 补充自定义钩子(如 `beforeDelete`、`afterDetail` 等)
|
||||
3. 在菜单管理中调整菜单排序和图标
|
||||
4. 为测试角色分配新菜单权限(**不分配则前端看不到菜单**)
|
||||
|
||||
:::tip 生成后调整
|
||||
生成的代码是基础骨架,通常需要:
|
||||
- 调整 Logic 的查询条件配置
|
||||
- 添加删除前校验(beforeDelete)
|
||||
- 补充详情后的关联数据(afterDetail)
|
||||
- 配置文件字段和富文本字段
|
||||
:::
|
||||
|
||||
- 调整 Service 的查询条件配置
|
||||
- 添加删除前校验(`beforeDelete`)
|
||||
- 补充详情后的关联数据(`afterDetail`)
|
||||
- 配置文件字段(`fileFields` + `use HasFileProcessing`)和富文本字段
|
||||
- 核对 FormRequest 规则与业务约束是否一致
|
||||
:::
|
||||
|
||||
Reference in New Issue
Block a user