支持板块图标与主题色自定义,并优化列表加载与未保存离开提示。
新增后端图标校验与色槽规范化,前端展示 BoardBadge/骨架屏,发帖与板块管理页增加未保存确认。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -45,14 +45,24 @@ func (s *BoardService) GetByID(id uint) (*model.Board, error) {
|
||||
return &board, nil
|
||||
}
|
||||
|
||||
func (s *BoardService) Create(name, desc string, sortOrder int) (*model.Board, error) {
|
||||
board := &model.Board{Name: name, Description: desc, SortOrder: sortOrder}
|
||||
func (s *BoardService) Create(name, desc, icon string, colorIndex, sortOrder int) (*model.Board, error) {
|
||||
board := &model.Board{
|
||||
Name: name,
|
||||
Description: desc,
|
||||
Icon: NormalizeBoardIcon(icon),
|
||||
ColorIndex: NormalizeBoardColorIndex(colorIndex),
|
||||
SortOrder: sortOrder,
|
||||
}
|
||||
return board, model.DB.Create(board).Error
|
||||
}
|
||||
|
||||
func (s *BoardService) Update(id uint, name, desc string, sortOrder int) error {
|
||||
func (s *BoardService) Update(id uint, name, desc, icon string, colorIndex, sortOrder int) error {
|
||||
return model.DB.Model(&model.Board{}).Where("id = ?", id).Updates(map[string]interface{}{
|
||||
"name": name, "description": desc, "sort_order": sortOrder,
|
||||
"name": name,
|
||||
"description": desc,
|
||||
"icon": NormalizeBoardIcon(icon),
|
||||
"color_index": NormalizeBoardColorIndex(colorIndex),
|
||||
"sort_order": sortOrder,
|
||||
}).Error
|
||||
}
|
||||
|
||||
|
||||
36
service/board_icon.go
Normal file
36
service/board_icon.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package service
|
||||
|
||||
import "strings"
|
||||
|
||||
// AllowedBoardIcons 与前端 BOARD_ICON_OPTIONS 的 key 保持一致
|
||||
var AllowedBoardIcons = map[string]struct{}{
|
||||
"code-2": {}, "coffee": {}, "help-circle": {}, "message-square": {},
|
||||
"lightbulb": {}, "book-open": {}, "gamepad-2": {}, "palette": {},
|
||||
"music": {}, "camera": {}, "heart": {}, "zap": {},
|
||||
"globe": {}, "users": {}, "briefcase": {}, "graduation-cap": {},
|
||||
"shopping-bag": {}, "map-pin": {}, "megaphone": {}, "flame": {},
|
||||
"star": {}, "folder": {}, "wrench": {}, "cpu": {},
|
||||
}
|
||||
|
||||
// NormalizeBoardIcon 校验并规范化板块图标 key,非法或空则返回空串
|
||||
func NormalizeBoardIcon(icon string) string {
|
||||
icon = strings.TrimSpace(strings.ToLower(icon))
|
||||
if icon == "" {
|
||||
return ""
|
||||
}
|
||||
if _, ok := AllowedBoardIcons[icon]; !ok {
|
||||
return ""
|
||||
}
|
||||
return icon
|
||||
}
|
||||
|
||||
// NormalizeBoardColorIndex -1 表示自动;0–7 为有效色槽
|
||||
func NormalizeBoardColorIndex(colorIndex int) int {
|
||||
if colorIndex < 0 {
|
||||
return -1
|
||||
}
|
||||
if colorIndex > 7 {
|
||||
return colorIndex % 8
|
||||
}
|
||||
return colorIndex
|
||||
}
|
||||
Reference in New Issue
Block a user