feat: 统一文件上传接口 + 模板图片展示 + 导航页 + 侧边栏调整

This commit is contained in:
admin
2026-07-10 20:43:02 +08:00
parent cbd0430452
commit ce6823e282
25 changed files with 933 additions and 166 deletions

View File

@@ -55,6 +55,62 @@ var tableLabels = map[string]string{
"music_categories": "音乐分类",
}
// tablesWithSort 拥有 sort 列的表(用于排序)
var tablesWithSort = map[string]bool{
"enterprise_services": true,
"enterprise_team": true,
"shop_products": true,
"shop_categories": true,
"food_restaurants": true,
"food_categories": true,
"food_menu_items": true,
"food_menu_categories": true,
"game_games": true,
"game_categories": true,
"app_apps": true,
"app_categories": true,
"music_songs": true,
"music_categories": true,
}
// tablesWithName 拥有 name 列的表(用于关键词搜索)
var tablesWithName = map[string]bool{
"enterprise_company": true,
"enterprise_team": true,
"enterprise_services": false, // 有 title 无 name
"enterprise_news": false,
"shop_products": true,
"shop_categories": true,
"food_restaurants": true,
"food_categories": true,
"food_menu_items": true,
"food_menu_categories": true,
"game_games": true,
"game_categories": true,
"app_apps": true,
"app_categories": true,
"music_songs": false, // 有 title 无 name
"music_categories": true,
}
// tablesWithTitle 拥有 title 列的表(用于关键词搜索)
var tablesWithTitle = map[string]bool{
"enterprise_news": true,
"enterprise_services": true,
"music_songs": true,
}
// tablesWithStatus 拥有 status 列的表(用于状态过滤)
var tablesWithStatus = map[string]bool{
"enterprise_news": true,
"shop_products": true,
"food_restaurants": true,
"food_menu_items": true,
"game_games": true,
"app_apps": true,
"music_songs": true,
}
// DashboardHandler 管理后台仪表盘处理器(通用 CRUD + 统计)
type DashboardHandler struct {
db *gorm.DB
@@ -174,21 +230,36 @@ func (h *DashboardHandler) ListItems(c *gin.Context) {
query := h.db.Model(modelType)
// 关键词搜索(按 name 或 title 字段)
// 关键词搜索(根据表实际拥有的列动态构建条件)
if keyword != "" {
query = query.Where("name LIKE ? OR title LIKE ?", "%"+keyword+"%", "%"+keyword+"%")
hasName := tablesWithName[table]
hasTitle := tablesWithTitle[table]
switch {
case hasName && hasTitle:
query = query.Where("name LIKE ? OR title LIKE ?", "%"+keyword+"%", "%"+keyword+"%")
case hasName:
query = query.Where("name LIKE ?", "%"+keyword+"%")
case hasTitle:
query = query.Where("title LIKE ?", "%"+keyword+"%")
}
}
// 状态过滤
if status != "" {
// 状态过滤(仅对拥有 status 列的表生效)
if status != "" && tablesWithStatus[table] {
query = query.Where("status = ?", status)
}
var total int64
query.Count(&total)
// 排序:有 sort 列的表按 sort ASC, id DESC;否则按 id DESC
orderClause := "id DESC"
if tablesWithSort[table] {
orderClause = "sort ASC, id DESC"
}
var results []map[string]interface{}
if err := query.Order("sort ASC, id DESC").Offset(offset).Limit(pageSize).Find(&results).Error; err != nil {
if err := query.Order(orderClause).Offset(offset).Limit(pageSize).Find(&results).Error; err != nil {
FailInternal(c, "查询失败: "+err.Error())
return
}