Files
2026-10-20 21:19:44 +08:00

76 lines
2.7 KiB
Markdown
Raw Permalink 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.
# 6.7 文章管理
:::tip 概述
文章模块(goframe_article,租户级表)是文件/富文本字段的代表模块:cover 单图、images 多图、content 富文本([IMG_URL] 持久化契约),配合分类关联与状态/点击量/排序。
:::
## 接口清单
```text
七件套 + PUT /api/article/status(sys:article:status)
sys:article:{page|list|detail|add|update|delete|batchDelete|status}
```
## 表特征列
```text
category_id 所属分类(逻辑外键 → goframe_category)
cover 封面单图(FileFields)
images 多图(MultiFileFields,逗号分隔)
content 富文本(ContentFields,[IMG_URL] 占位符契约)
status 0-正常 1-下架(注释枚举)
click 点击量
sort 排序
```
## 声明式文件/富文本处理(spec 模式)
```go
// articleSpec 关键声明(模式示意)
var articleSpec = ModuleSpec[...]{ ...,
FileFields: []string{"cover"}, // 单图
MultiFileFields: []string{"images"}, // 逗号多图
ContentFields: []string{"content"}, // 富文本
FileSaveDir: "article", // 转正目录
}
```
基座自动完成:
```text
写侧(saveTransform):
cover/images:temp 路径 → SaveFromTemp 转正到 article/{日期}/
content:LocalizeContentFields —— 本站 /temp/ 引用转正、
本站正式引用剥离域名 → "[IMG_URL]/相对路径"
外站 URL 不处理(防 SSRF)
读侧(readTransform):
cover/images:GetFileUrl 补域名(domainUrl 或 /upload/)
content:ExpandContentFields —— "[IMG_URL]" 还原为访问基址
```
详见 [7.3 富文本处理](../tools/rich-text) 与 [7.1 文件上传全流程](../tools/upload)。
## 分类关联
```text
article.category_id → category.id(树形模块,见 6.10 分类管理)
列表可按分类筛选(EqFields);分类删除有引用守卫意识(避免文章悬挂)
```
## 状态与展示
```text
status 0-正常 1-下架:前端列表按状态过滤展示
SerializeMaps: status → article_status(字典驱动 {field}Text)
click 点击量:详情阅读累加(业务自定义)
sort 排序:OrderBy "sort asc" 或前端排序白名单
```
## 管理建议
+ 富文本图片会被自动本地化(temp → 正式目录)——编辑器直传的图片安全落库
+ 外站图片链接保持原样不抓取(设计边界:防 SSRF)
+ content 字段含 [IMG_URL] 占位符是库内格式契约——content 不供第三方系统直接消费,读取必须走 Detail/List(基座自动还原)
+ cover/images 字段入库为相对 uploadDir 路径,展示层经 GetFileUrl(基座已处理,勿手拼)