feat: refine suffix management layout and column ordering
- column sort dialog: reorder via arrows (persisted via new POST /dirs/:id/columns/order), precise column insertion after a selected position (create column accepts after_id), value columns shown in blue text inside the dialog - workspace cells: edit only after entering the row's 编辑 mode, then double-click the cell (matching legacy interaction) - collapsible global sidebar with edge handle (state persisted); suffix panel directory collapses independently; independent scrollbars for directory and workspace; 5px gap to the sidebar - suffix page drops the internal-console heading block and the 内部管理台 topbar label; 退出 moves to the sidebar footer (same line as the admin email, 5px from the edge); brand subtitle 统一授权管理平台 removed - integration test covers column reorder/precise insert/dedupe
This commit is contained in:
@@ -37,6 +37,7 @@ func registerSuffixRoutes(secured *gin.RouterGroup, a *BusinessAPI) {
|
||||
s.DELETE("/dirs/:id", a.deleteSuffixDir)
|
||||
s.GET("/dirs/:id/page", a.suffixDirPage)
|
||||
s.POST("/dirs/:id/columns", a.createSuffixColumn)
|
||||
s.POST("/dirs/:id/columns/order", a.reorderSuffixColumns)
|
||||
s.POST("/dirs/:id/anchor", a.setSuffixAnchor)
|
||||
s.DELETE("/columns/:id", a.deleteSuffixColumn)
|
||||
s.PUT("/cells", a.saveSuffixCell)
|
||||
@@ -305,6 +306,7 @@ func (a *BusinessAPI) createSuffixColumn(c *gin.Context) {
|
||||
var in struct {
|
||||
Name string `json:"name"`
|
||||
IsValue bool `json:"is_value"`
|
||||
AfterID uint64 `json:"after_id"`
|
||||
}
|
||||
if c.ShouldBindJSON(&in) != nil {
|
||||
apiError(c, 400, "invalid_request", "参数无效")
|
||||
@@ -321,12 +323,31 @@ func (a *BusinessAPI) createSuffixColumn(c *gin.Context) {
|
||||
apiError(c, 409, "duplicate_name", "这个目录里已有同名列")
|
||||
return
|
||||
}
|
||||
var order sql.NullInt64
|
||||
_ = a.db.QueryRowContext(c,
|
||||
"SELECT MAX(sort_order) FROM suffix_columns WHERE dir_id=?", dirID).Scan(&order)
|
||||
sortAt := -1
|
||||
if in.AfterID > 0 {
|
||||
var afterSort int
|
||||
var afterDir uint64
|
||||
if err := a.db.QueryRowContext(c,
|
||||
"SELECT sort_order,dir_id FROM suffix_columns WHERE id=?", in.AfterID).Scan(&afterSort, &afterDir); err != nil || afterDir != dirID {
|
||||
apiError(c, 404, "not_found", "插入位置的列不存在")
|
||||
return
|
||||
}
|
||||
if _, err := a.db.ExecContext(c,
|
||||
"UPDATE suffix_columns SET sort_order=sort_order+1 WHERE dir_id=? AND sort_order>?",
|
||||
dirID, afterSort); err != nil {
|
||||
apiError(c, 500, "internal_error", "列创建失败")
|
||||
return
|
||||
}
|
||||
sortAt = afterSort
|
||||
} else {
|
||||
var order sql.NullInt64
|
||||
_ = a.db.QueryRowContext(c,
|
||||
"SELECT MAX(sort_order) FROM suffix_columns WHERE dir_id=?", dirID).Scan(&order)
|
||||
sortAt = int(order.Int64)
|
||||
}
|
||||
res, err := a.db.ExecContext(c,
|
||||
"INSERT INTO suffix_columns(dir_id,name,is_value,sort_order) VALUES(?,?,?,?)",
|
||||
dirID, name, in.IsValue, order.Int64+1)
|
||||
dirID, name, in.IsValue, sortAt+1)
|
||||
if err != nil {
|
||||
apiError(c, 500, "internal_error", "列创建失败")
|
||||
return
|
||||
@@ -335,6 +356,65 @@ func (a *BusinessAPI) createSuffixColumn(c *gin.Context) {
|
||||
c.JSON(201, gin.H{"data": gin.H{"id": id, "name": name, "is_value": in.IsValue}})
|
||||
}
|
||||
|
||||
func (a *BusinessAPI) reorderSuffixColumns(c *gin.Context) {
|
||||
dirID, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
var in struct {
|
||||
IDs []uint64 `json:"ids"`
|
||||
}
|
||||
if c.ShouldBindJSON(&in) != nil || len(in.IDs) == 0 {
|
||||
apiError(c, 400, "invalid_request", "ids 必须为非空数组")
|
||||
return
|
||||
}
|
||||
// 校验:id 必须属于该目录且不可重复;没传进来的列按原顺序补到末尾,防漏传错位。
|
||||
owned := map[uint64]int{}
|
||||
rows, err := a.db.QueryContext(c,
|
||||
"SELECT id,sort_order FROM suffix_columns WHERE dir_id=? ORDER BY sort_order ASC,id ASC", dirID)
|
||||
if err != nil {
|
||||
apiError(c, 500, "internal_error", "列加载失败")
|
||||
return
|
||||
}
|
||||
original := []uint64{}
|
||||
for rows.Next() {
|
||||
var cid uint64
|
||||
var so int
|
||||
if err := rows.Scan(&cid, &so); err != nil {
|
||||
rows.Close()
|
||||
apiError(c, 500, "internal_error", "列加载失败")
|
||||
return
|
||||
}
|
||||
owned[cid] = so
|
||||
original = append(original, cid)
|
||||
}
|
||||
rows.Close()
|
||||
seen := map[uint64]bool{}
|
||||
for _, cid := range in.IDs {
|
||||
if _, ok := owned[cid]; !ok {
|
||||
apiError(c, 404, "not_found", fmt.Sprintf("列不属于该目录: %d", cid))
|
||||
return
|
||||
}
|
||||
if seen[cid] {
|
||||
apiError(c, 400, "invalid_request", "ids 重复")
|
||||
return
|
||||
}
|
||||
seen[cid] = true
|
||||
}
|
||||
final := []uint64{}
|
||||
final = append(final, in.IDs...)
|
||||
for _, cid := range original {
|
||||
if !seen[cid] {
|
||||
final = append(final, cid)
|
||||
}
|
||||
}
|
||||
for i, cid := range final {
|
||||
if _, err := a.db.ExecContext(c,
|
||||
"UPDATE suffix_columns SET sort_order=? WHERE id=?", i, cid); err != nil {
|
||||
apiError(c, 500, "internal_error", "排序失败")
|
||||
return
|
||||
}
|
||||
}
|
||||
c.JSON(200, gin.H{"data": gin.H{"ok": true, "ordered": len(final)}})
|
||||
}
|
||||
|
||||
func (a *BusinessAPI) deleteSuffixColumn(c *gin.Context) {
|
||||
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
res, err := a.db.ExecContext(c, "DELETE FROM suffix_columns WHERE id=?", id)
|
||||
|
||||
@@ -157,10 +157,46 @@ func TestSuffixAdminIntegration(t *testing.T) {
|
||||
if w.Code != 201 {
|
||||
t.Fatalf("建值列 status=%d body=%s", w.Code, w.Body.String())
|
||||
}
|
||||
valueColID := uint64(getJSON(w)["data"].(map[string]any)["id"].(float64))
|
||||
w = authed(http.MethodPost, fmt.Sprintf("/api/v1/suffix-admin/dirs/%d/columns", dirID), `{"name":"招标人","is_value":false}`)
|
||||
if w.Code != 409 {
|
||||
t.Fatalf("同目录重名列 status=%d, want 409", w.Code)
|
||||
}
|
||||
// 精准插入:插到 招标人 之后
|
||||
w = authed(http.MethodPost, fmt.Sprintf("/api/v1/suffix-admin/dirs/%d/columns", dirID),
|
||||
fmt.Sprintf(`{"name":"插队列","is_value":false,"after_id":%d}`, plainColID))
|
||||
if w.Code != 201 {
|
||||
t.Fatalf("精准插列 status=%d body=%s", w.Code, w.Body.String())
|
||||
}
|
||||
insertedID := uint64(getJSON(w)["data"].(map[string]any)["id"].(float64))
|
||||
w = authed(http.MethodGet, fmt.Sprintf("/api/v1/suffix-admin/dirs/%d/page", dirID), "")
|
||||
pageCols := getJSON(w)["data"].(map[string]any)["columns"].([]any)
|
||||
if pageCols[1].(map[string]any)["id"].(float64) != float64(insertedID) {
|
||||
t.Fatal("精准插列应落在 招标人 之后(第2位)")
|
||||
}
|
||||
// 列排序:插队列移回末位 → 顺序变为 招标人,工料机类型,插队列
|
||||
w = authed(http.MethodPost, fmt.Sprintf("/api/v1/suffix-admin/dirs/%d/columns/order", dirID),
|
||||
fmt.Sprintf(`{"ids":[%d,%d,%d]}`, plainColID, valueColID, insertedID))
|
||||
if w.Code != 200 {
|
||||
t.Fatalf("列排序 status=%d body=%s", w.Code, w.Body.String())
|
||||
}
|
||||
// 漏传列:没传的按原顺序补到末尾 → 顺序不变(招标人,工料机类型,插队列)
|
||||
w = authed(http.MethodPost, fmt.Sprintf("/api/v1/suffix-admin/dirs/%d/columns/order", dirID),
|
||||
fmt.Sprintf(`{"ids":[%d,%d]}`, plainColID, valueColID))
|
||||
if w.Code != 200 {
|
||||
t.Fatalf("漏传列补尾 status=%d body=%s", w.Code, w.Body.String())
|
||||
}
|
||||
// 外列 → 404
|
||||
w = authed(http.MethodPost, fmt.Sprintf("/api/v1/suffix-admin/dirs/%d/columns/order", dirID),
|
||||
`{"ids":[999999]}`)
|
||||
if w.Code != 404 {
|
||||
t.Fatalf("外列 status=%d, want 404", w.Code)
|
||||
}
|
||||
w = authed(http.MethodGet, fmt.Sprintf("/api/v1/suffix-admin/dirs/%d/page", dirID), "")
|
||||
orderedCols := getJSON(w)["data"].(map[string]any)["columns"].([]any)
|
||||
if orderedCols[0].(map[string]any)["name"] != "招标人" || orderedCols[1].(map[string]any)["name"] != "工料机类型" || orderedCols[2].(map[string]any)["name"] != "插队列" {
|
||||
t.Fatalf("排序后顺序不符: %v", orderedCols)
|
||||
}
|
||||
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 == 404 || w.Code == 400 {
|
||||
@@ -171,9 +207,10 @@ func TestSuffixAdminIntegration(t *testing.T) {
|
||||
w = authed(http.MethodGet, fmt.Sprintf("/api/v1/suffix-admin/dirs/%d/page", dirID), "")
|
||||
page := getJSON(w)["data"].(map[string]any)
|
||||
cols := page["columns"].([]any)
|
||||
if len(cols) != 2 {
|
||||
t.Fatalf("列数=%d, want 2", len(cols))
|
||||
if len(cols) != 3 {
|
||||
t.Fatalf("列数=%d, want 3", len(cols))
|
||||
}
|
||||
// 排序后顺序:招标人,工料机类型,插队列;第二列=值列
|
||||
if !cols[1].(map[string]any)["is_value"].(bool) {
|
||||
t.Fatal("第二列应为值列")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user