From 5fdac9902dd6e23e5a247429d36a6da98915160d Mon Sep 17 00:00:00 2001 From: lianjianwei2024 <168657369+lianjianwei2024@users.noreply.github.com> Date: Sat, 31 Oct 2026 09:17:28 +0800 Subject: [PATCH] =?UTF-8?q?feat(suffix):=20=E6=94=AF=E6=8C=81=E6=A0=B9?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E9=87=8D=E5=91=BD=E5=90=8D=E3=80=81=E5=88=97?= =?UTF-8?q?=E5=AE=BD=E4=BF=9D=E5=AD=98=E3=80=81=E9=94=9A=E5=AE=9A=E5=80=BC?= =?UTF-8?q?=E4=B8=8E=E6=96=87=E4=BB=B6=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AGENTS.md | 23 + backend/internal/httpapi/operations.go | 6 +- backend/internal/httpapi/readiness.go | 2 +- backend/internal/httpapi/suffixes.go | 215 +++++-- backend/internal/httpapi/suffixes_test.go | 122 +++- .../000018_suffix_col_widths.down.sql | 1 + .../000018_suffix_col_widths.up.sql | 9 + .../000019_rename_suffix_root.down.sql | 2 + .../000019_rename_suffix_root.up.sql | 2 + .../000020_suffix_anchor_value.down.sql | 1 + .../000020_suffix_anchor_value.up.sql | 2 + .../000021_suffix_file_publish.down.sql | 1 + .../000021_suffix_file_publish.up.sql | 2 + frontend/src/style.css | 6 +- frontend/src/suffix-admin.ts | 15 +- frontend/src/views/Overview.vue | 2 +- frontend/src/views/SuffixPanel.test.ts | 152 ++++- frontend/src/views/SuffixPanel.vue | 575 ++++++++++-------- 18 files changed, 824 insertions(+), 314 deletions(-) create mode 100644 AGENTS.md create mode 100644 backend/migrations/000018_suffix_col_widths.down.sql create mode 100644 backend/migrations/000018_suffix_col_widths.up.sql create mode 100644 backend/migrations/000019_rename_suffix_root.down.sql create mode 100644 backend/migrations/000019_rename_suffix_root.up.sql create mode 100644 backend/migrations/000020_suffix_anchor_value.down.sql create mode 100644 backend/migrations/000020_suffix_anchor_value.up.sql create mode 100644 backend/migrations/000021_suffix_file_publish.down.sql create mode 100644 backend/migrations/000021_suffix_file_publish.up.sql diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..fb22a98 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,23 @@ +# 项目协作约定(长期记忆) + +- 本项目是新开发软件,尚未交付真实用户:**不需要考虑旧数据 / 旧接口 / 旧存储路径的向后兼容**,直接切换到目标设计即可(例:附件存储目录从 suffix-templates 切到 attachments 时无需保留回退逻辑)。 +- 每次动手改代码前,先与用户核对任务清单,确认后再开工(用户定的铁律)。 +- 填 cos4 后缀管理数据时:**每一层先出草稿**(完整目录树 + 锚定行 + 每目录字段表「列名→填入值」),用户确认后才执行。 +- **重复明细条目只填一行代表**(如 AttrInfoItem/AddiInfoItem 在 XML 里重复多次,数据里填一条即可),但必须**记住 XML 的数据层级结构**(元素嵌套关系)。 +- **层级不同就各建目录,字段相同就克隆字段配置**(同一元素在多处出现,如 SummaryOfCost 挂在 建设项目/建筑安装工程费/单项工程 下,各自建目录,锚定行同名,字段列复制)。 +- **自嵌套元素**(如 AddiInfoItem 套 AddiInfoItem,标准中「支持树形结构」的明细元素):目录下建**同名子目录、克隆同样字段**,树里表达一层嵌套即可,租户端按真实数据递归展开。 +- **枚举字段的值设置列(2026-10-31 用户定稿:横向含义列)**:枚举属性表达为**每个含义一列**——列名=含义词,勾选值设置(is_value=true),格子存 `{"a":"字段名","v":"代码"}`(锚点=该枚举的属性英文名,值=该含义在此格式下的代码);属性本体列另建、普通列(格子=属性英文名),名用短名或标准中文解释。N 个含义 = N 个含义列 + 1 个本体列(N+1 处字段名)。值设置含义列组整体排在**锚定行右边、其他字段列左边**;同目录多枚举按组连排(各组含义列→各本体列→普通字段列)。不同地区代码不同时,各后缀行填各自代码。工料机汇总已全量改造:Kind(9 含义列:人工费~其他 + 本体「类型」)、ExtKind(3:普通工料/人工降效/机具降效 + 本体「扩展属性」)、Provider(3:乙供/甲供/甲招乙供 + 本体「供料方式」)。Class 工料机归属、PriceSource 价格来源是自由文本,保持普通列。 +- **列名取名规则(全列统一)**:列名一律取 2025 标准属性表该属性的「中文解释」原词(如 Kind→汇总类型、LockKind→锁定类别),不自造、不用英文名当列名;值设置列与普通列同规。格子值:值设置列存 `{"a":含义串,"v":代码串}`;普通列存两家实际导出的属性英文名。**值设置列判定**:标准里属性为 Integer 且注释给出「1=xx;2=xx」枚举 → 值设置列;自由文本(如 Class 工料机归属、PriceSource 价格来源)→ 普通列。OCR 丢中文名时用 2018 版全文交叉补(Volume=册),仍缺的语境推定并标「待核」。 +- **填数据不走脚本**:直接在管理台界面上操作(浏览器自动化),目录 → 字段(列)→ 字段名称(单元格值)按此顺序填。 + +## cos4 后缀管理数据规律(2026-10-30 与用户共同确立) + +- **蓝本**:以广联达、易达两家实际导出的 cos4 文件为唯一蓝本(样例:`后台需要导入的项目/广联达导出最新架子.COS4`、`1易达导出骨架.cos4`;cos4=ZIP,内含 Project.xml + 若干单位工程 xml)。 +- **目录=XML元素**:后台「按信息价目录」树的每个目录对应 cos4 里的一个 XML 元素;目录的**锚定行**填该元素的英文名(如 建设项目→ConstructionProject);目录中文名取自 DBJ/T 15-145-2025 第 6 章对应表(参考资料在 AdminCost/参考资料/规范与COS4/)。 +- **列=元素属性**:目录里的列 = 该元素的属性;列名用 2025 标准属性表的「中文解释」;单元格值 = **两家实际导出的属性英文名**,并以**两家字段的并集**为准——不是标准全集,也不是单家。 +- **以实际为准 + 提醒**:填入值一律以两家实际导出为准,不按标准拼写改(例:两家都把 BuildUnit 拼成 `BulidUnit`,按错的填);与标准不一致(拼写差异、某家缺失、标准有但两家都没导出)时必须向用户提醒。已知差异:建设单位/法定代表人两家都拼错(BulidUnit/BulidAuthorizer);`BulidAuthorizer` 仅易达导出;标准表 6.2.1 的 4 个价格指数字段(ProjectIndex/LabourPriceIndex/MaterialPriceIndex/MachinePriceIndex)两家均未导出,故不建列。 +- **进度**:建设项目(ConstructionProject)已补全 22 列 + cos4 行 22 格(2026-10-30)。cos 行(老格式)留空,后续单独讨论。 +- **操作注意**:用 curl 调后端 API 填中文时,必须把 JSON 写进 UTF-8 文件用 `--data-binary @file` 发送;中文放命令行参数会被 Windows 代码页转成乱码(EFBFBD)。 +- **同名属性按锚定行分别查原表(2026-10-31 用户铁律)**:同一英文属性(如 Kind/Specialty/CalculationKind/EfficiencyKind/IncFeeKind)在不同锚定行(元素)下的中文解释与枚举值**可能完全不同**,填值设置前必须逐表核对原出处(md 表 → 2018 版交叉 → 原 PDF)。已实证差异:Specialty 专业类别在 WorkElement=12 项 / UnitWorks=21 项 / **Norm=19 项**(含 城市轨道交通(建筑)=8、城市轨道交通(安装)=16、建筑与装饰修缮=12、安装修缮=13、传统建筑(古建筑)=15、地下管廊建筑=17、地下管廊安装=18、古驿道=21,2=仿古建筑 OCR 缺按 2018 补);EfficiencyKind 降效类型 2025=3 项(1需计算降效费用的基础定额/2不需计算…/3降效费用定额,**与 2018 的 4 项不同**);IncFeeKind 2025=3 项(1需计算子目增加费的基础定额/2不需计算…/3子目增加费定额);Volume=册。汇总类型 Kind/章节类型 ChapterKind/锁定类别/取费类型/费用归属/单价计算方式/合价计算方式/子目类型 各锚定行同义。 +- **列名核对工具**:审计脚本做法——从 2025 版 md 解析每元素属性表(注意 OCR 陷阱:属性名常在「序号」列且序号列可能为空、长属性名折行连写(TechnicalAndEcono-+micIndex)、中文解释词序颠倒),与库内 列名/格子值 按锚定行逐一比对;解析器分隔行守卫不能误杀空序号行。 +- **枚举映射核实来源**:2025 版 OCR 的枚举注缺失时,用同目录 2018 版全文(DBJT15-145-2018_全文含表格.md)交叉核对(文本干净)。已核实:降效类型 EfficiencyKind(1降效基础定额/2非降效定额/3按市场价计算降效费用定额/4按定额价计算降效费用定额)、子目增加费类型 IncFeeKind(1子目增加费基础定额/2非子目增加费定额/3子目增加费用计算定额)、快速计算的 Kind=汇总类型(1汇总条目/2不汇总条目)、Volume=册(册号,无分册填0)。唯一残留待核:Norm 的 Chapter 列中文名两版文字均缺失,按语境暂记「章(待核)」(2025 原始 PDF 4793785.pdf 本地不存在,需要时向用户索取)。 diff --git a/backend/internal/httpapi/operations.go b/backend/internal/httpapi/operations.go index 8008322..ae403b1 100644 --- a/backend/internal/httpapi/operations.go +++ b/backend/internal/httpapi/operations.go @@ -175,8 +175,10 @@ func (o *Operations) Middleware() gin.HandlerFunc { return } } - // Uploads have their own 64 MiB streaming bound; other JSON routes get a 64 KiB ceiling. - if !(path == "/api/v1/products/:id/releases" && c.Request.Method == "POST") { + // Uploads have their own streaming bounds (releases 64 MiB; suffix templates + // bound in their handler); other JSON routes get a 64 KiB ceiling. + if !(path == "/api/v1/products/:id/releases" && c.Request.Method == "POST") && + !(path == "/api/v1/suffix-admin/suffixes/:id/files" && c.Request.Method == "POST") { if c.Request.ContentLength > 64<<10 { apiError(c, 413, "body_too_large", "Request body too large") c.Abort() diff --git a/backend/internal/httpapi/readiness.go b/backend/internal/httpapi/readiness.go index a640cf4..cfd6d55 100644 --- a/backend/internal/httpapi/readiness.go +++ b/backend/internal/httpapi/readiness.go @@ -9,7 +9,7 @@ import ( "github.com/gin-gonic/gin" ) -const RequiredSchemaVersion = 17 +const RequiredSchemaVersion = 21 func RegisterReadiness(r *gin.Engine, db *sql.DB) { r.GET("/api/v1/health/ready", func(c *gin.Context) { diff --git a/backend/internal/httpapi/suffixes.go b/backend/internal/httpapi/suffixes.go index fbd4fa8..81ca4de 100644 --- a/backend/internal/httpapi/suffixes.go +++ b/backend/internal/httpapi/suffixes.go @@ -7,6 +7,7 @@ import ( "encoding/hex" "errors" "fmt" + "net/http" "os" "path/filepath" "regexp" @@ -42,6 +43,8 @@ func registerSuffixRoutes(secured *gin.RouterGroup, a *BusinessAPI) { s.PATCH("/columns/:id", a.updateSuffixColumn) s.DELETE("/columns/:id", a.deleteSuffixColumn) s.PUT("/cells", a.saveSuffixCell) + s.GET("/col-widths", a.suffixColWidths) + s.PUT("/col-widths", a.saveSuffixColWidth) s.GET("/overview", a.suffixOverview) s.POST("/groups", a.createSuffixGroup) s.PUT("/groups/:id", a.renameSuffixGroup) @@ -54,6 +57,7 @@ func registerSuffixRoutes(secured *gin.RouterGroup, a *BusinessAPI) { s.POST("/suffixes/:id/files", a.uploadSuffixFile) s.DELETE("/files/:id", a.deleteSuffixFile) s.GET("/files/:id/download", a.downloadSuffixFile) + s.POST("/files/:id/publish", a.publishSuffixFile) } func suffixTrimName(raw string, max int) (string, bool) { @@ -61,8 +65,6 @@ func suffixTrimName(raw string, max int) (string, bool) { return name, name != "" && utf8.RuneCountInString(name) <= max } -const suffixRootNameValue = "按信息价的目录" - // ---- 目录树 ---- type suffixDirRow struct { @@ -101,9 +103,6 @@ func (a *BusinessAPI) suffixTree(c *gin.Context) { dirs[p].Children++ } } - if len(dirs) > 0 { - dirs[0].Name = suffixRootNameValue - } c.JSON(200, gin.H{"data": gin.H{"dirs": dirs}}) } @@ -127,7 +126,7 @@ func (a *BusinessAPI) createSuffixDir(c *gin.Context) { return } if in.ParentID == 0 { - apiError(c, 403, "forbidden", "只能建在「按信息价的目录」之内") + apiError(c, 403, "forbidden", "只能建在根目录之内") return } if !a.dirExists(c, in.ParentID) { @@ -158,10 +157,6 @@ func (a *BusinessAPI) dirIsRoot(c *gin.Context, id uint64) bool { func (a *BusinessAPI) renameSuffixDir(c *gin.Context) { id, _ := strconv.ParseUint(c.Param("id"), 10, 64) - if a.dirIsRoot(c, id) { - apiError(c, 403, "forbidden", "根目录名称固定,不能改名") - return - } var in struct { Name string `json:"name"` } @@ -250,15 +245,15 @@ func (a *BusinessAPI) suffixDirPage(c *gin.Context) { colRows.Close() type suffixLine struct { - ID uint64 `json:"id"` - GroupID uint64 `json:"group_id"` - GroupName string `json:"group_name"` - Name string `json:"name"` - Anchor bool `json:"anchor"` + ID uint64 `json:"id"` + GroupID uint64 `json:"group_id"` + GroupName string `json:"group_name"` + Name string `json:"name"` + AnchorValue string `json:"anchor_value"` } suffixes := []suffixLine{} sfxRows, err := a.db.QueryContext(c, - "SELECT s.id,s.group_id,g.name,s.name, EXISTS(SELECT 1 FROM suffix_dir_anchors x WHERE x.dir_id=? AND x.suffix_id=s.id)"+ + "SELECT s.id,s.group_id,g.name,s.name, COALESCE((SELECT x.value FROM suffix_dir_anchors x WHERE x.dir_id=? AND x.suffix_id=s.id),'')"+ " FROM suffixes s JOIN suffix_groups g ON g.id=s.group_id"+ " ORDER BY g.sort_order ASC,g.id ASC,s.sort_order ASC,s.id ASC", dirID) if err != nil { @@ -267,7 +262,7 @@ func (a *BusinessAPI) suffixDirPage(c *gin.Context) { } for sfxRows.Next() { var r suffixLine - if err := sfxRows.Scan(&r.ID, &r.GroupID, &r.GroupName, &r.Name, &r.Anchor); err != nil { + if err := sfxRows.Scan(&r.ID, &r.GroupID, &r.GroupName, &r.Name, &r.AnchorValue); err != nil { sfxRows.Close() apiError(c, 500, "internal_error", "后缀加载失败") return @@ -422,30 +417,73 @@ func (a *BusinessAPI) reorderSuffixColumns(c *gin.Context) { c.JSON(200, gin.H{"data": gin.H{"ok": true, "ordered": len(final)}}) } +// 列更新:name 与 width 至少传一个;重命名在同一目录内查重。 func (a *BusinessAPI) updateSuffixColumn(c *gin.Context) { id, _ := strconv.ParseUint(c.Param("id"), 10, 64) var in struct { - Width *int `json:"width"` + Name *string `json:"name"` + Width *int `json:"width"` } - if c.ShouldBindJSON(&in) != nil || in.Width == nil { - apiError(c, 400, "invalid_request", "width 必填") + if c.ShouldBindJSON(&in) != nil || (in.Name == nil && in.Width == nil) { + apiError(c, 400, "invalid_request", "name 或 width 至少传一个") return } - w := *in.Width - if w < 0 || w > 2000 { - apiError(c, 400, "invalid_request", "列宽须为 0–2000(0=自适应)") - return + if in.Name != nil { + name, ok := suffixTrimName(*in.Name, 190) + if !ok { + apiError(c, 400, "invalid_request", "列名须为 1–190 字") + return + } + var dirID uint64 + if err := a.db.QueryRowContext(c, + "SELECT dir_id FROM suffix_columns WHERE id=?", id).Scan(&dirID); err != nil { + apiError(c, 404, "not_found", "列不存在") + return + } + var dup int + if a.db.QueryRowContext(c, + "SELECT 1 FROM suffix_columns WHERE dir_id=? AND name=? AND id<>?", dirID, name, id).Scan(&dup) == nil { + apiError(c, 409, "duplicate_name", "这个目录里已有同名列") + return + } + if _, err := a.db.ExecContext(c, "UPDATE suffix_columns SET name=? WHERE id=?", name, id); err != nil { + apiError(c, 500, "internal_error", "列重命名失败") + return + } } - res, err := a.db.ExecContext(c, "UPDATE suffix_columns SET width=? WHERE id=?", w, id) - if err != nil || rowsAffected(res) == 0 { + if in.Width != nil { + w := *in.Width + if w < 0 || w > 2000 { + apiError(c, 400, "invalid_request", "列宽须为 0–2000(0=自适应)") + return + } + if _, err := a.db.ExecContext(c, "UPDATE suffix_columns SET width=? WHERE id=?", w, id); err != nil { + apiError(c, 500, "internal_error", "列宽保存失败") + return + } + } + var out suffixColumnRow + if err := a.db.QueryRowContext(c, + "SELECT id,name,is_value,width FROM suffix_columns WHERE id=?", id). + Scan(&out.ID, &out.Name, &out.IsValue, &out.Width); err != nil { apiError(c, 404, "not_found", "列不存在") return } - c.JSON(200, gin.H{"data": gin.H{"id": id, "width": w}}) + c.JSON(200, gin.H{"data": out}) } func (a *BusinessAPI) deleteSuffixColumn(c *gin.Context) { id, _ := strconv.ParseUint(c.Param("id"), 10, 64) + var filled int + if err := a.db.QueryRowContext(c, + "SELECT COUNT(*) FROM suffix_cells WHERE column_id=? AND value<>''", id).Scan(&filled); err != nil { + apiError(c, 500, "internal_error", "删除失败") + return + } + if filled > 0 { + apiError(c, 409, "column_has_data", "该列已有数据,不能删除") + return + } res, err := a.db.ExecContext(c, "DELETE FROM suffix_columns WHERE id=?", id) if err != nil || rowsAffected(res) == 0 { apiError(c, 404, "not_found", "列不存在") @@ -494,20 +532,27 @@ func (a *BusinessAPI) saveSuffixCell(c *gin.Context) { c.JSON(200, gin.H{"data": gin.H{"ok": true}}) } +// 锚定行存值:value 非空 upsert,空串删除(未锚定)。 func (a *BusinessAPI) setSuffixAnchor(c *gin.Context) { dirID, _ := strconv.ParseUint(c.Param("id"), 10, 64) var in struct { SuffixID uint64 `json:"suffix_id"` - On bool `json:"on"` + Value string `json:"value"` } if c.ShouldBindJSON(&in) != nil { apiError(c, 400, "invalid_request", "参数无效") return } + value := strings.TrimSpace(in.Value) + if utf8.RuneCountInString(value) > 190 { + apiError(c, 400, "invalid_request", "锚定值最多 190 字") + return + } var exec error - if in.On { + if value != "" { _, exec = a.db.ExecContext(c, - "INSERT IGNORE INTO suffix_dir_anchors(dir_id,suffix_id) VALUES(?,?)", dirID, in.SuffixID) + "INSERT INTO suffix_dir_anchors(dir_id,suffix_id,value) VALUES(?,?,?)"+ + " ON DUPLICATE KEY UPDATE value=VALUES(value)", dirID, in.SuffixID, value) } else { _, exec = a.db.ExecContext(c, "DELETE FROM suffix_dir_anchors WHERE dir_id=? AND suffix_id=?", dirID, in.SuffixID) @@ -519,6 +564,79 @@ func (a *BusinessAPI) setSuffixAnchor(c *gin.Context) { c.JSON(200, gin.H{"data": gin.H{"ok": true}}) } +// ---- 固定列列宽(序号/后缀/操作等,基本设置与目录工作区各一套,全部可自由设置) ---- + +// 默认值与前端 FIXED_COL_DEFAULTS 保持一致;0=自适应(导入文件为 0 时占满剩余宽度)。 +var suffixColWidthDefaults = map[string]map[string]int{ + "basic": {"idx": 50, "suffix": 50, "files": 0, "ops": 150}, + "workspace": {"idx": 50, "suffix": 50, "ops": 80, "anchor": 300}, +} + +func (a *BusinessAPI) suffixColWidths(c *gin.Context) { + out := map[string]map[string]int{} + for scope, keys := range suffixColWidthDefaults { + out[scope] = map[string]int{} + for k, def := range keys { + out[scope][k] = def + } + } + rows, err := a.db.QueryContext(c, "SELECT scope,col_key,width FROM suffix_col_widths") + if err != nil { + apiError(c, 500, "internal_error", "列宽加载失败") + return + } + defer rows.Close() + for rows.Next() { + var scope, key string + var w int + if rows.Scan(&scope, &key, &w) == nil { + if keys, ok := out[scope]; ok { + if _, known := keys[key]; known && w >= 0 { + keys[key] = w + } + } + } + } + if err := rows.Err(); err != nil { + apiError(c, 500, "internal_error", "列宽加载失败") + return + } + c.JSON(200, gin.H{"data": gin.H{"widths": out}}) +} + +func (a *BusinessAPI) saveSuffixColWidth(c *gin.Context) { + var in struct { + Scope string `json:"scope"` + Key string `json:"key"` + Width *int `json:"width"` + } + if c.ShouldBindJSON(&in) != nil || in.Width == nil { + apiError(c, 400, "invalid_request", "参数无效") + return + } + keys, ok := suffixColWidthDefaults[in.Scope] + if !ok { + apiError(c, 400, "invalid_request", "scope 只能是 basic 或 workspace") + return + } + if _, known := keys[in.Key]; !known { + apiError(c, 400, "invalid_request", "未知的固定列 key") + return + } + w := *in.Width + if w < 0 || w > 2000 { + apiError(c, 400, "invalid_request", "列宽须为 0–2000(0=自适应)") + return + } + if _, err := a.db.ExecContext(c, + "INSERT INTO suffix_col_widths(scope,col_key,width) VALUES(?,?,?)"+ + " ON DUPLICATE KEY UPDATE width=VALUES(width)", in.Scope, in.Key, w); err != nil { + apiError(c, 500, "internal_error", "列宽保存失败") + return + } + c.JSON(200, gin.H{"data": gin.H{"scope": in.Scope, "key": in.Key, "width": w}}) +} + // ---- 基本设置:分组 + 后缀 + 模板文件 ---- type suffixFileRow struct { @@ -526,6 +644,7 @@ type suffixFileRow struct { FileName string `json:"file_name"` FileSize int64 `json:"file_size"` CreatedAt string `json:"created_at"` + Published bool `json:"published"` } func (a *BusinessAPI) suffixOverview(c *gin.Context) { @@ -583,7 +702,7 @@ func (a *BusinessAPI) suffixOverview(c *gin.Context) { return } fRows, err := a.db.QueryContext(c, - "SELECT id,suffix_id,file_name,file_size,created_at FROM suffix_files ORDER BY id ASC") + "SELECT id,suffix_id,file_name,file_size,created_at,published FROM suffix_files ORDER BY id ASC") if err != nil { apiError(c, 500, "internal_error", "文件加载失败") return @@ -592,7 +711,7 @@ func (a *BusinessAPI) suffixOverview(c *gin.Context) { for fRows.Next() { var f suffixFileRow var sid uint64 - if err := fRows.Scan(&f.ID, &sid, &f.FileName, &f.FileSize, &f.CreatedAt); err != nil { + if err := fRows.Scan(&f.ID, &sid, &f.FileName, &f.FileSize, &f.CreatedAt, &f.Published); err != nil { apiError(c, 500, "internal_error", "文件加载失败") return } @@ -904,12 +1023,13 @@ type suffixTemplateRootError struct{} func (suffixTemplateRootError) Error() string { return "模板存储目录未配置" } +// 附件统一落盘在 PACKAGE_STORAGE_ROOT/attachments/<后缀id>/ 下(新软件,无旧目录兼容负担)。 func suffixTemplateRoot() (string, error) { base := strings.TrimSpace(os.Getenv("PACKAGE_STORAGE_ROOT")) if base == "" { return "", suffixTemplateRootError{} } - return filepath.Join(base, "suffix-templates"), nil + return filepath.Join(base, "attachments"), nil } func suffixUniqueName(dir string, name string) string { @@ -928,6 +1048,8 @@ func suffixUniqueName(dir string, name string) string { func (a *BusinessAPI) uploadSuffixFile(c *gin.Context) { suffixID, _ := strconv.ParseUint(c.Param("id"), 10, 64) + // base64 上传体放宽到 128MB + 少量 JSON 包装开销(该路由已在全局 64KiB JSON 上限中豁免)。 + c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, suffixUploadMax+(64<<10)) var in struct { FileName string `json:"file_name"` Size int64 `json:"size"` @@ -1009,7 +1131,7 @@ func (a *BusinessAPI) uploadSuffixFile(c *gin.Context) { }}) } -// 只认模板根目录以内的路径,越界一律不删。 +// 只认模板根目录以内的路径,越界一律不删;删完后顺手回收空的后缀目录。 func (a *BusinessAPI) removeDiskFiles(c *gin.Context, relPaths []string) { root, err := suffixTemplateRoot() if err != nil { @@ -1019,11 +1141,34 @@ func (a *BusinessAPI) removeDiskFiles(c *gin.Context, relPaths []string) { abs := filepath.Join(root, filepath.FromSlash(rel)) clean := filepath.Clean(abs) if strings.HasPrefix(clean, filepath.Clean(root)+string(filepath.Separator)) { - _ = os.Remove(clean) + if os.Remove(clean) == nil { + _ = os.Remove(filepath.Dir(clean)) + } } } } +func (a *BusinessAPI) publishSuffixFile(c *gin.Context) { + id, _ := strconv.ParseUint(c.Param("id"), 10, 64) + var in struct { + On bool `json:"on"` + } + if c.ShouldBindJSON(&in) != nil { + apiError(c, 400, "invalid_request", "参数无效") + return + } + on := 0 + if in.On { + on = 1 + } + res, err := a.db.ExecContext(c, "UPDATE suffix_files SET published=? WHERE id=?", on, id) + if err != nil || rowsAffected(res) == 0 { + apiError(c, 404, "not_found", "文件不存在") + return + } + c.JSON(200, gin.H{"data": gin.H{"id": id, "published": in.On}}) +} + func (a *BusinessAPI) deleteSuffixFile(c *gin.Context) { id, _ := strconv.ParseUint(c.Param("id"), 10, 64) var rel string diff --git a/backend/internal/httpapi/suffixes_test.go b/backend/internal/httpapi/suffixes_test.go index 7f1e595..e870c09 100644 --- a/backend/internal/httpapi/suffixes_test.go +++ b/backend/internal/httpapi/suffixes_test.go @@ -11,6 +11,8 @@ import ( "net/http" "net/http/httptest" "os" + "path/filepath" + "strconv" "strings" "testing" @@ -33,7 +35,7 @@ func TestSuffixAdminIntegration(t *testing.T) { if err = db.Ping(); err != nil { t.Fatal(err) } - for _, table := range []string{"suffix_files", "suffix_dir_anchors", "suffix_cells", "suffix_columns", "suffixes", "suffix_groups", "suffix_dirs"} { + for _, table := range []string{"suffix_files", "suffix_dir_anchors", "suffix_cells", "suffix_columns", "suffixes", "suffix_groups", "suffix_dirs", "suffix_col_widths"} { if _, err = db.Exec("DELETE FROM " + table); err != nil { t.Fatalf("清理 %s: %v", table, err) } @@ -55,7 +57,8 @@ func TestSuffixAdminIntegration(t *testing.T) { router := NewRouter() RegisterBusiness(router, db) - t.Setenv("PACKAGE_STORAGE_ROOT", t.TempDir()) + storageRoot := t.TempDir() + t.Setenv("PACKAGE_STORAGE_ROOT", storageRoot) do := func(method, path, body string) *httptest.ResponseRecorder { var reader *strings.Reader if body == "" { @@ -166,6 +169,16 @@ func TestSuffixAdminIntegration(t *testing.T) { if w.Code != 403 { t.Fatalf("删根 status=%d, want 403", w.Code) } + // 根目录支持重命名 + w = authed(http.MethodPut, fmt.Sprintf("/api/v1/suffix-admin/dirs/%d", rootID), `{"name":"建设项目"}`) + if w.Code != 200 { + t.Fatalf("改根名 status=%d body=%s", w.Code, w.Body.String()) + } + w = authed(http.MethodGet, "/api/v1/suffix-admin/tree", "") + dirs = getJSON(w)["data"].(map[string]any)["dirs"].([]any) + if dirs[0].(map[string]any)["name"] != "建设项目" { + t.Fatalf("改根名后=%v", dirs[0].(map[string]any)["name"]) + } // 列(值设置勾选)+ 单元格 + 锚定 w = authed(http.MethodPost, fmt.Sprintf("/api/v1/suffix-admin/dirs/%d/columns", dirID), `{"name":"招标人","is_value":false}`) @@ -235,9 +248,84 @@ func TestSuffixAdminIntegration(t *testing.T) { t.Fatal("第二列应为值列") } - // 锚定开与关 + // 列重命名:成功、同目录重名 409、空名 400 + w = authed(http.MethodPatch, fmt.Sprintf("/api/v1/suffix-admin/columns/%d", plainColID), `{"name":"招标单位"}`) + if w.Code != 200 { + t.Fatalf("重命名列 status=%d body=%s", w.Code, w.Body.String()) + } + if name := getJSON(w)["data"].(map[string]any)["name"].(string); name != "招标单位" { + t.Fatalf("重命名后 name=%q, want 招标单位", name) + } + w = authed(http.MethodPatch, fmt.Sprintf("/api/v1/suffix-admin/columns/%d", plainColID), `{"name":"工料机类型"}`) + if w.Code != 409 { + t.Fatalf("重名列 status=%d, want 409", w.Code) + } + w = authed(http.MethodPatch, fmt.Sprintf("/api/v1/suffix-admin/columns/%d", plainColID), `{"name":" "}`) + if w.Code != 400 { + t.Fatalf("空名列 status=%d, want 400", w.Code) + } + + // 列有值不可删除:普通列已存「普通文本」 + w = authed(http.MethodDelete, fmt.Sprintf("/api/v1/suffix-admin/columns/%d", plainColID), "") + if w.Code != 409 { + t.Fatalf("删有值列 status=%d, want 409", w.Code) + } + // 空列可直接删除 + w = authed(http.MethodDelete, fmt.Sprintf("/api/v1/suffix-admin/columns/%d", insertedID), "") + if w.Code != 200 { + t.Fatalf("删空列 status=%d body=%s", w.Code, w.Body.String()) + } + // 清空单元格后即可删除 + w = authed(http.MethodPut, "/api/v1/suffix-admin/cells", + fmt.Sprintf(`{"dir_id":%d,"suffix_id":%d,"column_id":%d,"value":""}`, dirID, suffixID, plainColID)) + if w.Code != 200 { + t.Fatalf("清空单元格 status=%d body=%s", w.Code, w.Body.String()) + } + w = authed(http.MethodDelete, fmt.Sprintf("/api/v1/suffix-admin/columns/%d", plainColID), "") + if w.Code != 200 { + t.Fatalf("清空后删列 status=%d body=%s", w.Code, w.Body.String()) + } + + // 固定列列宽:默认值(后缀 50)→ 保存 → 回读;非法参数拒绝 + w = authed(http.MethodGet, "/api/v1/suffix-admin/col-widths", "") + if w.Code != 200 { + t.Fatalf("读列宽 status=%d body=%s", w.Code, w.Body.String()) + } + widths := getJSON(w)["data"].(map[string]any)["widths"].(map[string]any) + if widths["basic"].(map[string]any)["suffix"].(float64) != 50 { + t.Fatalf("basic.suffix 默认应为 50,got %v", widths["basic"].(map[string]any)["suffix"]) + } + if _, has := widths["basic"].(map[string]any)["files"]; !has { + t.Fatal("basic 固定列应含 files") + } + w = authed(http.MethodPut, "/api/v1/suffix-admin/col-widths", `{"scope":"workspace","key":"ops","width":66}`) + if w.Code != 200 { + t.Fatalf("存列宽 status=%d body=%s", w.Code, w.Body.String()) + } + w = authed(http.MethodGet, "/api/v1/suffix-admin/col-widths", "") + widths = getJSON(w)["data"].(map[string]any)["widths"].(map[string]any) + if widths["workspace"].(map[string]any)["ops"].(float64) != 66 { + t.Fatalf("workspace.ops 应为 66,got %v", widths["workspace"].(map[string]any)["ops"]) + } + if widths["workspace"].(map[string]any)["suffix"].(float64) != 50 { + t.Fatalf("未保存过的 workspace.suffix 应仍为默认 50,got %v", widths["workspace"].(map[string]any)["suffix"]) + } + w = authed(http.MethodPut, "/api/v1/suffix-admin/col-widths", `{"scope":"nope","key":"ops","width":66}`) + if w.Code != 400 { + t.Fatalf("非法 scope status=%d, want 400", w.Code) + } + w = authed(http.MethodPut, "/api/v1/suffix-admin/col-widths", `{"scope":"basic","key":"files","width":9999}`) + if w.Code != 400 { + t.Fatalf("列宽越界 status=%d, want 400", w.Code) + } + w = authed(http.MethodPut, "/api/v1/suffix-admin/col-widths", `{"scope":"basic","key":"nope","width":10}`) + if w.Code != 400 { + t.Fatalf("未知列 key status=%d, want 400", w.Code) + } + + // 锚定行存值:保存 → 回读;空值清除;超长拒绝 w = authed(http.MethodPost, fmt.Sprintf("/api/v1/suffix-admin/dirs/%d/anchor", dirID), - fmt.Sprintf(`{"suffix_id":%d,"on":true}`, suffixID)) + fmt.Sprintf(`{"suffix_id":%d,"value":"3"}`, suffixID)) if w.Code != 200 { t.Fatalf("锚定 status=%d", w.Code) } @@ -252,8 +340,25 @@ func TestSuffixAdminIntegration(t *testing.T) { t.Fatal("找不到 cos4 行") return nil }() - if !cos4["anchor"].(bool) { - t.Fatal("锚定后 anchor 应为 true") + if cos4["anchor_value"].(string) != "3" { + t.Fatalf("锚定后 anchor_value=%q, want 3", cos4["anchor_value"]) + } + w = authed(http.MethodPost, fmt.Sprintf("/api/v1/suffix-admin/dirs/%d/anchor", dirID), + fmt.Sprintf(`{"suffix_id":%d,"value":""}`, suffixID)) + if w.Code != 200 { + t.Fatalf("清锚定 status=%d", w.Code) + } + w = authed(http.MethodGet, fmt.Sprintf("/api/v1/suffix-admin/dirs/%d/page", dirID), "") + sfx = getJSON(w)["data"].(map[string]any)["suffixes"].([]any) + for _, line := range sfx { + if line.(map[string]any)["name"] == "cos4" && line.(map[string]any)["anchor_value"].(string) != "" { + t.Fatal("清空后 anchor_value 应为空") + } + } + w = authed(http.MethodPost, fmt.Sprintf("/api/v1/suffix-admin/dirs/%d/anchor", dirID), + fmt.Sprintf(`{"suffix_id":%d,"value":"%s"}`, suffixID, strings.Repeat("长", 191))) + if w.Code != 400 { + t.Fatalf("超长锚定值 status=%d, want 400", w.Code) } // 模板上传(内容与哈希校验)→ 概览 → 删除 @@ -274,6 +379,11 @@ func TestSuffixAdminIntegration(t *testing.T) { t.Fatalf("传模板 status=%d body=%s", w.Code, w.Body.String()) } fileID := uint64(getJSON(w)["data"].(map[string]any)["id"].(float64)) + // 附件必须落盘在 attachments/<后缀id>/ 下 + storedName := getJSON(w)["data"].(map[string]any)["file_name"].(string) + if _, err := os.Stat(filepath.Join(storageRoot, "attachments", strconv.FormatUint(suffixID, 10), storedName)); err != nil { + t.Fatalf("附件未落在 attachments 目录: %v", err) + } badSum := sha256.Sum256([]byte("tampered")) w = authed(http.MethodPost, fmt.Sprintf("/api/v1/suffix-admin/suffixes/%d/files", suffixID), fmt.Sprintf(`{"file_name":"坏.cos4","size":%d,"sha256":"%s","content_base64":"%s"}`, diff --git a/backend/migrations/000018_suffix_col_widths.down.sql b/backend/migrations/000018_suffix_col_widths.down.sql new file mode 100644 index 0000000..a0c879d --- /dev/null +++ b/backend/migrations/000018_suffix_col_widths.down.sql @@ -0,0 +1 @@ +DROP TABLE suffix_col_widths; diff --git a/backend/migrations/000018_suffix_col_widths.up.sql b/backend/migrations/000018_suffix_col_widths.up.sql new file mode 100644 index 0000000..29c4980 --- /dev/null +++ b/backend/migrations/000018_suffix_col_widths.up.sql @@ -0,0 +1,9 @@ +-- Suffix management fixed-column widths (basic settings + directory workspace tables). +-- scope: 'basic' | 'workspace'; col_key: idx/suffix/files/ops/anchor; width 0 = auto. +CREATE TABLE suffix_col_widths ( + scope VARCHAR(20) NOT NULL, + col_key VARCHAR(32) NOT NULL, + width INT NOT NULL DEFAULT 0, + updated_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), + PRIMARY KEY(scope,col_key) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; diff --git a/backend/migrations/000019_rename_suffix_root.down.sql b/backend/migrations/000019_rename_suffix_root.down.sql new file mode 100644 index 0000000..74cff8a --- /dev/null +++ b/backend/migrations/000019_rename_suffix_root.down.sql @@ -0,0 +1,2 @@ +-- 回滚:恢复根目录名称 +UPDATE suffix_dirs SET name='按信息价的目录' WHERE parent_id IS NULL AND name='建设项目'; diff --git a/backend/migrations/000019_rename_suffix_root.up.sql b/backend/migrations/000019_rename_suffix_root.up.sql new file mode 100644 index 0000000..fa4c2a5 --- /dev/null +++ b/backend/migrations/000019_rename_suffix_root.up.sql @@ -0,0 +1,2 @@ +-- 根目录改名:按信息价的目录 → 建设项目(目录现已支持重命名,此处仅迁移存量数据) +UPDATE suffix_dirs SET name='建设项目' WHERE parent_id IS NULL AND name='按信息价的目录'; diff --git a/backend/migrations/000020_suffix_anchor_value.down.sql b/backend/migrations/000020_suffix_anchor_value.down.sql new file mode 100644 index 0000000..2dd1982 --- /dev/null +++ b/backend/migrations/000020_suffix_anchor_value.down.sql @@ -0,0 +1 @@ +ALTER TABLE suffix_dir_anchors DROP COLUMN value; diff --git a/backend/migrations/000020_suffix_anchor_value.up.sql b/backend/migrations/000020_suffix_anchor_value.up.sql new file mode 100644 index 0000000..9cea7e8 --- /dev/null +++ b/backend/migrations/000020_suffix_anchor_value.up.sql @@ -0,0 +1,2 @@ +-- 锚定行从 1/— 开关改为存值:value 为锚定内容(如行号),'' = 未锚定。 +ALTER TABLE suffix_dir_anchors ADD COLUMN value VARCHAR(190) NOT NULL DEFAULT ''; diff --git a/backend/migrations/000021_suffix_file_publish.down.sql b/backend/migrations/000021_suffix_file_publish.down.sql new file mode 100644 index 0000000..131b248 --- /dev/null +++ b/backend/migrations/000021_suffix_file_publish.down.sql @@ -0,0 +1 @@ +ALTER TABLE suffix_files DROP COLUMN published; diff --git a/backend/migrations/000021_suffix_file_publish.up.sql b/backend/migrations/000021_suffix_file_publish.up.sql new file mode 100644 index 0000000..a6c6bc1 --- /dev/null +++ b/backend/migrations/000021_suffix_file_publish.up.sql @@ -0,0 +1,2 @@ +-- 骨架文件发布状态:0=未发布,1=已发布 +ALTER TABLE suffix_files ADD COLUMN published TINYINT(1) NOT NULL DEFAULT 0; diff --git a/frontend/src/style.css b/frontend/src/style.css index f887ded..e4e18fb 100644 --- a/frontend/src/style.css +++ b/frontend/src/style.css @@ -3,7 +3,7 @@ @media(max-width:600px){.heading{align-items:start}.status-section{align-items:start;flex-direction:column}.scope dl div{grid-template-columns:1fr;gap:4px}.environment{display:none}} .integration-controls{display:flex;align-items:center;gap:12px;flex-wrap:wrap}.integration-controls label{display:flex;align-items:center;gap:8px;font-size:14px}.integration-controls select{min-height:34px;padding:4px 10px;border:1px solid #d8e0e3;border-radius:4px;background:white;color:#263840}.integration-controls .el-form-item{margin-bottom:8px}.integration-controls .el-select{width:150px}.integration-meta{display:flex;gap:20px;flex-wrap:wrap;color:#64737b;font-size:13px;margin:16px 0}.integration-panel h3{font-size:15px;margin:24px 0 12px}.prompt-box{border:1px solid #e0e5e6;padding:16px;border-radius:6px;background:#fbfcfd}.prompt-box pre,.vector-box{white-space:pre-wrap;overflow-wrap:anywhere;font:13px/1.7 ui-monospace,monospace;margin:0 0 12px;max-width:100%}.vector-box{padding:16px;background:#f5f7fa;border:1px solid #e0e5e6;border-radius:6px}.integration-rules{padding-left:20px;font-size:14px;line-height:1.8}.integration-panel summary{cursor:pointer;margin-bottom:12px}@media(max-width:620px){.integration-controls{align-items:stretch;flex-direction:column}.integration-controls .el-form-item{display:block}.integration-controls .el-select{width:100%}.integration-controls a{margin-left:0!important;white-space:normal;height:auto;min-height:32px}.integration-meta{gap:8px}.integration-panel .section-heading{display:block}} /* Demo-aligned administration shell */ -.admin-workspace{display:flex;min-height:100vh;background:#f6f8fb;color:#17202b}.admin-workspace .sidebar{width:242px;flex:0 0 242px;background:#14202e;color:#fff;padding:23px 14px;display:flex;flex-direction:column}.admin-workspace .brand{display:flex;gap:11px;align-items:center;padding:0 12px 31px;font-size:17px;font-weight:700}.admin-workspace .brand small{display:block;color:#96a5b6;font-size:11px;font-weight:400;margin-top:2px}.brand-mark{width:31px;height:31px;background:#2e83f1;border-radius:8px;display:grid;place-items:center;font-weight:800;color:#fff}.admin-workspace .nav{display:flex;flex-direction:column}.admin-workspace .nav-label{color:#617487;font-size:11px;letter-spacing:.08em;padding:0 13px;margin:13px 0 7px}.admin-workspace .nav a{width:100%;color:#96a5b6;text-decoration:none;text-align:left;padding:10px 13px;border-radius:7px;margin:2px 0;display:flex;gap:11px;align-items:center}.admin-workspace .nav a:hover,.admin-workspace .nav a.active{color:#fff;background:#213247}.admin-workspace .nav .ico{width:18px;text-align:center;font-size:16px}.admin-workspace .sidebar-footer{margin-top:auto;border-top:1px solid #2b3b4e;padding:15px 11px 0;color:#96a5b6;font-size:12px}.admin-workspace .main{flex:1;min-width:0}.admin-workspace .topbar{height:70px;padding:0 32px}.crumb{color:#687586}.crumb strong{color:#17202b;margin-left:7px}.admin-workspace .content{max-width:1440px;padding:30px 34px 46px}.admin-workspace .heading{margin-bottom:27px}.admin-workspace .heading h1{font-size:24px;letter-spacing:-.02em}.stats{display:grid;grid-template-columns:repeat(4,1fr);gap:16px;margin-bottom:23px}.stat{background:#fff;border:1px solid #e5e9ef;border-radius:8px;padding:19px 20px;position:relative}.stat>span{display:block;color:#687586;font-size:13px}.stat strong{display:block;font-size:28px;margin-top:7px}.stat small{display:block;color:#16845b;font-size:12px;margin-top:7px}.stat i{position:absolute;right:18px;top:19px;width:36px;height:36px;border-radius:8px;display:grid;place-items:center;font-size:18px;font-style:normal}.i-blue{background:#eaf2ff;color:#1769e0}.i-green{background:#e9f8f1;color:#16845b}.i-amber{background:#fff5df;color:#ae6c00}.i-red{background:#fff0f0;color:#c23b3b}.dashboard-grid{display:grid;grid-template-columns:1.4fr 1fr;gap:18px;margin-bottom:23px}.panel{background:#fff;border:1px solid #e5e9ef;border-radius:8px;padding:20px}.panel-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:18px}.panel h2{font-size:16px;margin:0}.panel-head a,.link,.action{color:#1769e0;text-decoration:none;background:none}.chart{height:182px;display:flex;align-items:end;gap:13px;padding:20px 8px 0;border-bottom:1px solid #e5e9ef}.bar-group{flex:1;height:100%;display:flex;align-items:end;justify-content:center;gap:3px;position:relative;min-width:22px}.bar{width:calc(50% - 2px);min-height:0;border-radius:4px 4px 0 0}.bar.issued{background:#4c96ed}.bar.expired{background:#b9d5fa}.bar-group>span{position:absolute;bottom:-25px;font-size:11px;color:#687586}.legend{display:flex;gap:18px;margin-top:26px;color:#687586;font-size:12px}.legend i{display:inline-block;width:8px;height:8px;background:#4c96ed;border-radius:2px;margin-right:5px}.legend i.expired{background:#b9d5fa}.deadline{display:flex;justify-content:space-between;padding:13px 0;border-bottom:1px solid #edf0f4}.deadline:last-of-type{border-bottom:0}.deadline-name{border:0;background:none;padding:0;text-align:left;font-weight:600;color:#17202b}.deadline-name small{display:block;color:#687586;margin-top:3px;font-weight:400}.tag{font-size:12px;border-radius:4px;padding:3px 8px;white-space:nowrap;height:max-content}.tag.green{color:#16845b;background:#e9f8f1}.tag.amber{color:#ae6c00;background:#fff5df}.tag.red{color:#c23b3b;background:#fff0f0}.table-panel{padding:0;overflow:hidden}.table-head{padding:20px 20px 15px;display:flex;justify-content:space-between;align-items:center}.table-head h2{font-size:16px;margin:0}.filters{display:flex;gap:8px;align-items:center}.filters input,.filters select,.search-button{border:1px solid #e5e9ef;border-radius:5px;padding:7px 10px;background:#fff;color:#17202b}.search-button{color:#1769e0;cursor:pointer}.table-scroll{overflow:auto}.table-panel table{width:100%;border-collapse:collapse}.table-panel th,.table-panel td{text-align:left;padding:13px 20px;border-top:1px solid #edf0f4;white-space:nowrap}.table-panel th{font-size:12px;color:#687586;font-weight:500;background:#fbfcfd}.table-panel td{font-size:13px}.avatar{display:inline-grid;place-items:center;width:28px;height:28px;margin-right:9px;border-radius:50%;background:#e6eefc;color:#356db7;font-size:11px;font-weight:700}.license-code{font-family:ui-monospace,monospace;font-size:12px}.empty-state,.muted{color:#687586;text-align:center;padding:24px}.footer-note{text-align:right;color:#8a96a5;font-size:12px;margin-top:13px}.license-detail{display:grid;grid-template-columns:120px 1fr;gap:12px;border-top:1px solid #e5e9ef;padding-top:16px}.license-detail dt{color:#687586}.license-detail dd{margin:0;font-weight:500} +.admin-workspace{display:flex;min-height:100vh;background:#f6f8fb;color:#17202b}.admin-workspace .sidebar{width:242px;flex:0 0 242px;background:#14202e;color:#fff;padding:23px 14px;display:flex;flex-direction:column}.admin-workspace .brand{display:flex;gap:11px;align-items:center;padding:0 12px 31px;font-size:17px;font-weight:700}.admin-workspace .brand small{display:block;color:#96a5b6;font-size:11px;font-weight:400;margin-top:2px}.brand-mark{width:31px;height:31px;background:#2e83f1;border-radius:8px;display:grid;place-items:center;font-weight:800;color:#fff}.admin-workspace .nav{display:flex;flex-direction:column}.admin-workspace .nav-label{color:#617487;font-size:11px;letter-spacing:.08em;padding:0 13px;margin:13px 0 7px}.admin-workspace .nav a{width:100%;color:#96a5b6;text-decoration:none;text-align:left;padding:10px 13px;border-radius:7px;margin:2px 0;display:flex;gap:11px;align-items:center}.admin-workspace .nav a:hover,.admin-workspace .nav a.active{color:#fff;background:#213247}.admin-workspace .nav .ico{width:18px;text-align:center;font-size:16px}.admin-workspace .sidebar-footer{margin-top:auto;border-top:1px solid #2b3b4e;padding:15px 11px 0;color:#96a5b6;font-size:12px}.admin-workspace .main{flex:1;min-width:0}.admin-workspace .topbar{height:70px;padding:0 32px}.crumb{color:#687586}.crumb strong{color:#17202b;margin-left:7px}.admin-workspace .content{max-width:1440px;padding:30px 34px 46px}.admin-workspace .heading{margin-bottom:27px}.admin-workspace .heading h1{font-size:24px;letter-spacing:-.02em}.stats{display:grid;grid-template-columns:repeat(4,1fr);gap:16px;margin-bottom:23px}.stat{background:#fff;border:1px solid #e5e9ef;border-radius:8px;padding:19px 20px;position:relative}.stat>span{display:block;color:#687586;font-size:13px}.stat strong{display:block;font-size:28px;margin-top:7px}.stat small{display:block;color:#16845b;font-size:12px;margin-top:7px}.stat i{position:absolute;right:18px;top:19px;width:36px;height:36px;border-radius:8px;display:grid;place-items:center;font-size:18px;font-style:normal}.i-blue{background:#eaf2ff;color:#1769e0}.i-green{background:#e9f8f1;color:#16845b}.i-amber{background:#fff5df;color:#ae6c00}.i-red{background:#fff0f0;color:#c23b3b}.dashboard-grid{display:grid;grid-template-columns:1.4fr 1fr;gap:18px;margin-bottom:23px}.panel{background:#fff;border:1px solid #e5e9ef;border-radius:8px;padding:20px}.panel-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:18px}.panel h2{font-size:16px;margin:0}.panel-head a,.link,.action{color:#1769e0;text-decoration:none;background:none}.chart{height:182px;display:flex;align-items:end;gap:13px;padding:20px 8px 0;border-bottom:1px solid #e5e9ef}.bar-group{flex:1;height:100%;display:flex;align-items:end;justify-content:center;gap:3px;position:relative;min-width:22px}.chart .bar{width:calc(50% - 2px);min-height:0;border-radius:4px 4px 0 0}.bar.issued{background:#4c96ed}.bar.expired{background:#b9d5fa}.bar-group>span{position:absolute;bottom:-25px;font-size:11px;color:#687586}.legend{display:flex;gap:18px;margin-top:26px;color:#687586;font-size:12px}.legend i{display:inline-block;width:8px;height:8px;background:#4c96ed;border-radius:2px;margin-right:5px}.legend i.expired{background:#b9d5fa}.deadline{display:flex;justify-content:space-between;padding:13px 0;border-bottom:1px solid #edf0f4}.deadline:last-of-type{border-bottom:0}.deadline-name{border:0;background:none;padding:0;text-align:left;font-weight:600;color:#17202b}.deadline-name small{display:block;color:#687586;margin-top:3px;font-weight:400}.tag{font-size:12px;border-radius:4px;padding:3px 8px;white-space:nowrap;height:max-content}.tag.green{color:#16845b;background:#e9f8f1}.tag.amber{color:#ae6c00;background:#fff5df}.tag.red{color:#c23b3b;background:#fff0f0}.table-panel{padding:0;overflow:hidden}.table-head{padding:20px 20px 15px;display:flex;justify-content:space-between;align-items:center}.table-head h2{font-size:16px;margin:0}.filters{display:flex;gap:8px;align-items:center}.filters input,.filters select,.search-button{border:1px solid #e5e9ef;border-radius:5px;padding:7px 10px;background:#fff;color:#17202b}.search-button{color:#1769e0;cursor:pointer}.table-scroll{overflow:auto}.table-panel table{width:100%;border-collapse:collapse}.table-panel th,.table-panel td{text-align:left;padding:13px 20px;border-top:1px solid #edf0f4;white-space:nowrap}.table-panel th{font-size:12px;color:#687586;font-weight:500;background:#fbfcfd}.table-panel td{font-size:13px}.avatar{display:inline-grid;place-items:center;width:28px;height:28px;margin-right:9px;border-radius:50%;background:#e6eefc;color:#356db7;font-size:11px;font-weight:700}.license-code{font-family:ui-monospace,monospace;font-size:12px}.empty-state,.muted{color:#687586;text-align:center;padding:24px}.footer-note{text-align:right;color:#8a96a5;font-size:12px;margin-top:13px}.license-detail{display:grid;grid-template-columns:120px 1fr;gap:12px;border-top:1px solid #e5e9ef;padding-top:16px}.license-detail dt{color:#687586}.license-detail dd{margin:0;font-weight:500} @media(max-width:960px){.admin-workspace .sidebar{width:72px;flex-basis:72px;padding:20px 10px}.admin-workspace .brand{padding:0 10px 30px}.admin-workspace .brand>div:last-child,.admin-workspace .nav-label,.admin-workspace .nav a span:not(.ico),.admin-workspace .sidebar-footer>span:last-child{display:none}.admin-workspace .brand-mark{margin:auto}.admin-workspace .nav a{justify-content:center;padding:11px}.admin-workspace .sidebar-footer{text-align:center;padding-left:0;padding-right:0}.stats{grid-template-columns:repeat(2,1fr)}.dashboard-grid{grid-template-columns:1fr}.admin-workspace .content{padding:25px 20px}.admin-workspace .topbar{padding:0 20px}} @media(max-width:620px){.admin-workspace .topbar{height:60px}.stats{gap:10px}.stat{padding:14px}.stat strong{font-size:22px}.table-head{display:block}.filters{margin-top:13px;flex-wrap:wrap}.filters input{width:150px}.admin-workspace .content{padding:20px 13px}.dashboard-grid{gap:12px}.panel{padding:16px}.admin-workspace .heading{display:block}.admin-workspace .heading .el-button{margin-top:15px}} @@ -24,11 +24,11 @@ /* 全局侧栏折叠(决策:授权管理平台可收起隐藏) */ .admin-workspace{position:relative} .admin-workspace.nav-collapsed .sidebar{width:0;flex-basis:0;padding:0;overflow:hidden;border-right:0} -.nav-fold{position:fixed;left:242px;top:50%;transform:translateY(-50%);z-index:40;width:20px;height:56px;border:1px solid #d8dfe8;border-left:0;border-radius:0 6px 6px 0;background:#fff;color:#526173;cursor:pointer;display:grid;place-items:center;font-size:13px} +.nav-fold{position:fixed;left:242px;top:50%;transform:translateY(-50%);z-index:40;width:20px;height:56px;border:1px solid #c9d3df;border-left:0;border-radius:0 6px 6px 0;background:#e9eef5;color:#45586b;cursor:pointer;display:grid;place-items:center;font-size:13px} .nav-fold:hover{color:#1769e0;border-color:#1769e0} .admin-workspace.nav-collapsed .nav-fold{left:0;border-radius:0 6px 6px 0} .admin-workspace .sidebar-footer{display:flex;align-items:center;gap:8px;padding-right:0;margin-right:-9px} .footer-email{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap} .side-logout{margin-left:auto;border:0;background:none;cursor:pointer;color:#96a5b6;font-size:12px;padding:2px 4px;flex:0 0 auto} .side-logout:hover{color:#fff} -.content.content-suffix{margin-left:0;max-width:none;padding-left:5px;padding-top:16px;padding-right:16px} +.content.content-suffix{margin-left:0;max-width:none;padding-left:5px;padding-top:5px;padding-right:16px;padding-bottom:0} diff --git a/frontend/src/suffix-admin.ts b/frontend/src/suffix-admin.ts index e203adf..71cc6e5 100644 --- a/frontend/src/suffix-admin.ts +++ b/frontend/src/suffix-admin.ts @@ -4,10 +4,12 @@ import { api } from './api' export type SuffixDir = { id:number; parent_id:number; name:string; sort_order:number; children:number } export type SuffixColumn = { id:number; name:string; is_value:boolean; width:number } -export type SuffixLine = { id:number; group_id:number; group_name:string; name:string; anchor:boolean } +export type SuffixLine = { id:number; group_id:number; group_name:string; name:string; anchor_value:string } export type SuffixPage = { dir_id:number; columns:SuffixColumn[]; suffixes:SuffixLine[]; cells:Record } -export type SuffixFile = { id:number; suffix_id?:number; file_name:string; file_size:number; created_at?:string; sha256?:string } +export type SuffixFile = { id:number; suffix_id?:number; file_name:string; file_size:number; created_at?:string; sha256?:string; published?:boolean } export type SuffixGroup = { id:number; name:string; suffixes:{ id:number; name:string; files:SuffixFile[] }[] } +// 固定列列宽(basic: idx/suffix/files/ops;workspace: idx/suffix/ops/anchor),0=自适应 +export type SuffixColWidths = { basic:Record; workspace:Record } export const getSuffixTree = () => api.get<{data:{dirs:SuffixDir[]}}>('/suffix-admin/tree') export const createSuffixDir = (parent_id:number, name:string) => api.post<{data:SuffixDir}>('/suffix-admin/dirs', { parent_id, name }) @@ -17,10 +19,13 @@ export const deleteSuffixDir = (id:number) => api.delete(`/suffix-admin/dirs/${i export const getSuffixPage = (id:number) => api.get<{data:SuffixPage}>(`/suffix-admin/dirs/${id}/page`) export const createSuffixColumn = (dirId:number, name:string, is_value:boolean, after_id = 0, width = 0) => api.post<{data:SuffixColumn}>(`/suffix-admin/dirs/${dirId}/columns`, { name, is_value, after_id, width }) export const updateSuffixColumnWidth = (id:number, width:number) => api.patch<{data:{id:number;width:number}}>(`/suffix-admin/columns/${id}`, { width }) +export const renameSuffixColumn = (id:number, name:string) => api.patch<{data:SuffixColumn}>(`/suffix-admin/columns/${id}`, { name }) export const reorderSuffixColumns = (dirId:number, ids:number[]) => api.post<{data:{ok:boolean;ordered:number}}>(`/suffix-admin/dirs/${dirId}/columns/order`, { ids }) export const deleteSuffixColumn = (id:number) => api.delete(`/suffix-admin/columns/${id}`) export const saveSuffixCell = (dir_id:number, suffix_id:number, column_id:number, value:string) => api.put('/suffix-admin/cells', { dir_id, suffix_id, column_id, value }) -export const setSuffixAnchor = (dirId:number, suffix_id:number, on:boolean) => api.post(`/suffix-admin/dirs/${dirId}/anchor`, { suffix_id, on }) +export const getSuffixColWidths = () => api.get<{data:{widths:SuffixColWidths}}>('/suffix-admin/col-widths') +export const updateSuffixColWidth = (scope:'basic'|'workspace', key:string, width:number) => api.put<{data:{scope:string;key:string;width:number}}>('/suffix-admin/col-widths', { scope, key, width }) +export const setSuffixAnchor = (dirId:number, suffix_id:number, value:string) => api.post(`/suffix-admin/dirs/${dirId}/anchor`, { suffix_id, value }) export const getSuffixOverview = () => api.get<{data:{groups:SuffixGroup[]}}>('/suffix-admin/overview') export const createSuffixGroup = (name:string, first_suffix_name = '') => api.post<{data:SuffixGroup}>('/suffix-admin/groups', { name, first_suffix_name }) export const renameSuffixGroup = (id:number, name:string) => api.put(`/suffix-admin/groups/${id}`, { name }) @@ -30,8 +35,10 @@ export const createSuffix = (group_id:number, name:string, after_id = 0) => api. export const renameSuffix = (id:number, name:string) => api.put(`/suffix-admin/suffixes/${id}`, { name }) export const moveSuffix = (id:number, dir:number) => api.post(`/suffix-admin/suffixes/${id}/move`, { dir }) export const deleteSuffix = (id:number) => api.delete(`/suffix-admin/suffixes/${id}`) -export const uploadSuffixFile = (id:number, body:{file_name:string;size:number;sha256:string;content_base64:string}) => api.post<{data:SuffixFile}>(`/suffix-admin/suffixes/${id}/files`, body) +// 大文件 base64 上传耗时较长,单独关闭全局 8s 超时,避免被前端掐断后只剩兜底报错。 +export const uploadSuffixFile = (id:number, body:{file_name:string;size:number;sha256:string;content_base64:string}) => api.post<{data:SuffixFile}>(`/suffix-admin/suffixes/${id}/files`, body, { timeout: 0 }) export const deleteSuffixFile = (id:number) => api.delete(`/suffix-admin/files/${id}`) +export const publishSuffixFile = (id:number, on:boolean) => api.post(`/suffix-admin/files/${id}/publish`, { on }) export const suffixFileUrl = (id:number) => `/api/v1/suffix-admin/files/${id}/download` // 读文件:算 sha256 + 分块转 base64(与后端上传接口配对)。 diff --git a/frontend/src/views/Overview.vue b/frontend/src/views/Overview.vue index 465b6d4..776df01 100644 --- a/frontend/src/views/Overview.vue +++ b/frontend/src/views/Overview.vue @@ -134,7 +134,7 @@ async function submitRenewal() { onMounted(() => { checkConnection(); checkSession() })