Files
easygoadmin-wiki/EasyGoAdmin_Gin_EleVue/zh/generator/templates.md
T
2026-10-25 17:24:27 +08:00

54 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 10.5 模板体系
:::tip 概述
模板在 `templates/`:后端四件套 tpl + 前端两套(ui 标准 / ui2 树形)。替换模板即改变全项目生成风格;模板只做排版,业务推断在引擎。
:::
## 模板清单
```text
templates/
├── dto.tpl 契约层(Item/PageReq/各请求响应 + 标签)
├── repository.tpl 数据访问(XxxRepo 三段式)
├── service.tpl 业务(三段式 + ModuleSpec 声明 + 标准方法 + 手写位)
├── handler.tpl 接口(CXxx 委托方法集)
├── ui/ 标准页面模板
│ ├── api.ts.tpl 前端 API 模块
│ ├── columns.ts.tpl 列配置
│ ├── querySchemas.ts.tpl 查询项配置
│ ├── index.vue.tpl 列表页
│ └── edit.vue.tpl 编辑弹窗
└── ui2/ 树形表模板(index/edit/detail/api)
```
## ui 与 ui2 的选择
| 表特征 | 模板 | 额外产物 |
|---|---|---|
| 普通表 | ui | columns.ts、querySchemas.ts |
| 树形表(parent_id 自关联) | ui2 | detail.vue(树形详情) |
引擎按表结构自动选型,无需人工指定。
## 定制模板
- **改产物风格**:编辑对应 tpl(Go template 语法 + 模板变量)
- **加字段**:引擎模型有该字段才能在模板引用——先看渲染报错定位变量
- **试错循环**:`make gen-preview` 即时验证,不落盘
## 定制注意
| 注意 | 说明 |
|---|---|
| 团队一致性 | 模板改动影响全项目生成物,需团队共识 |
| 升级成本 | 模板偏离基线越远,后续同步官方模板越难 |
| 先手工后模板 | 确定稳定的手工写法后再固化进模板 |
## 与第 3 章的关系
后端四个 tpl 与 [第 3 章 模块开发实战](/zh/guide/overview.html) 的手工规约完全一致——模板就是"照抄 example 写法"的程序化。
## 下一步
→ [10.6 配置与覆盖策略](/zh/generator/config.html)