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)
|
||||
|
||||
Reference in New Issue
Block a user