Files
cmautobuy/admin/templates/task/list.html
T
chengmaandClaude Opus 5 799ee33045 feat: 搭建 Admin 项目骨架(Go + Gin + html/template)
可运行的骨架:四个页面能打开、数据库自动建表、给 Client 的三个接口
按契约响应。业务逻辑留 35 处 TODO(骨架),每处标明要点和文档章节。

结构(对应 docs/admin/02-architecture.md §2/§3)
- handler/web + handler/api 分开:页面要 CSRF、出错渲染错误页;
  接口要认证、出错返回 JSON。混在一起迟早写错
- service 不认识 *gin.Context,方便不起服务器直接单测
- 只有 repository 能写 SQL
- 模板用 {{define "目录/名字"}},一次全部 ParseFS 进来不冲突
- 模板和静态资源用 //go:embed 打进二进制

已实测(Go 1.23.0,本机验证)
- go build / go vet / gofmt 全部通过
- 单文件产物 34MB,无需 cgo
- 四个页面 + 静态资源均 200,/ 正确 302 到 /shopee
- 建表 7 张 + 索引 10 个,user_version=1,二次启动不重复建表
- claim 带 X-Client-Id 返回 204(无任务可领),
  缺 X-Client-Id 返回 400 + 契约格式的 JSON 错误体

依赖版本被 Go 1.23.0 卡死,已钉住并写进文档
- gin v1.11.0        (v1.12.0 起要求 Go >= 1.25.0)
- modernc.org/sqlite v1.38.0(v1.40.0 起要求 >= 1.24.0,v1.48.0 起 >= 1.25.0)
- excelize v2.9.1    (尚未入 go.mod,写导入功能时再加)
直接 go get 不带版本会拉到最新版并报 requires go >= 1.25.0,
所以文档里的命令一律带版本号。要升依赖就得先升 Go。

一处主动调整:迁移语句从「一个字符串装多条 SQL」改成 [][]string 逐条执行。
database/sql 的 Exec 对一次多条语句的支持因驱动而异,拆开最稳妥,
报错还能精确到第几条。

说明:Gitea 尚未配置,本次无对应工单号。
admin/testdata/ 只有 README,脱敏小样本需人工制作。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-06 16:33:45 +08:00

54 lines
1.5 KiB
HTML

{{define "task/list"}}
{{template "header" .}}
<div class="toolbar">
<form class="inline grow" method="get" action="/tasks">
<label for="q">订单号</label>
<input id="q" type="text" name="order_no" value="{{.Keyword}}" placeholder="订单号">
<button type="submit">搜索</button>
</form>
<form class="inline" method="post" action="/tasks/delete" data-confirm-delete>
<button type="submit" class="danger" data-need-checked>删除</button>
</form>
</div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th class="col-check"><input type="checkbox" data-check-all></th>
<th>订单号</th>
<th>商品标题</th>
<th>颜色</th>
<th>尺码</th>
<th>数量</th>
<th>价格上限</th>
<th>蝦皮 ID</th>
<th>分配客户端</th>
<th>状态</th>
<th>更新时间</th>
</tr>
</thead>
<tbody>
{{range .Rows}}
{{/* TODO(骨架): 行渲染。
颜色尺码显示的是 **PDD 侧**的规格(实际要买的),不是蝦皮的。
价格上限显示成 ¥42.00,底层存的是整数分。
状态不能只靠颜色区分,必须有文字。
建议提供「改派」操作——没有心跳,客户端挂了要靠人工改派。 */}}
{{else}}
<tr class="empty">
<td colspan="11">
还没有采购任务。<br>
<small>到「顺运宝数据」勾选货运单,点「创建采购任务」。</small>
</td>
</tr>
{{end}}
</tbody>
</table>
</div>
{{template "footer" .}}
{{end}}