- SEO: 添加meta description/keywords/Open Graph/结构化数据/地理信息 - GEO: 添加geo.region/geo.position/ICBM等地理标记 - 手机端完全重写响应式: 咨询表单/导航卡片/hero区/标签全部适配 - 新增App候选码板块: 后台管理+导航页动态展示(支持录屏视频/下载链接) - 新增业务系统板块: 进销存/OA/财务/工单等,支持按年/按月/定制定价 - 后台新增App候选码管理页面(增删改查+上下架) - 后台新增业务系统管理页面(增删改查+上下架) - 导航页设置新增新板块标题配置 - 公开API: GET /api/v1/showcase/apps + /api/v1/showcase/systems
169 lines
3.9 KiB
Go
169 lines
3.9 KiB
Go
package handler
|
|
|
|
import (
|
|
"gotest/internal/model"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// ConfigHandler 系统配置处理器
|
|
type ConfigHandler struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
// NewConfigHandler 创建系统配置处理器
|
|
func NewConfigHandler(db *gorm.DB) *ConfigHandler {
|
|
return &ConfigHandler{db: db}
|
|
}
|
|
|
|
// GetConfig 获取配置 GET /api/v1/admin/config/:key
|
|
func (h *ConfigHandler) GetConfig(c *gin.Context) {
|
|
key := c.Param("key")
|
|
var config model.Config
|
|
if err := h.db.Where("`key` = ?", key).First(&config).Error; err != nil {
|
|
Success(c, gin.H{"key": key, "value": "", "remark": ""})
|
|
return
|
|
}
|
|
Success(c, config)
|
|
}
|
|
|
|
// SetConfig 设置配置 PUT /api/v1/admin/config/:key
|
|
func (h *ConfigHandler) SetConfig(c *gin.Context) {
|
|
key := c.Param("key")
|
|
var req struct {
|
|
Value string `json:"value"`
|
|
Remark string `json:"remark"`
|
|
}
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
FailBadRequest(c, "参数错误")
|
|
return
|
|
}
|
|
|
|
var config model.Config
|
|
result := h.db.Where("`key` = ?", key).First(&config)
|
|
if result.Error == gorm.ErrRecordNotFound {
|
|
config = model.Config{
|
|
Key: key,
|
|
Value: req.Value,
|
|
Remark: req.Remark,
|
|
}
|
|
if err := h.db.Create(&config).Error; err != nil {
|
|
FailInternal(c, "创建失败: "+err.Error())
|
|
return
|
|
}
|
|
} else if result.Error == nil {
|
|
config.Value = req.Value
|
|
if req.Remark != "" {
|
|
config.Remark = req.Remark
|
|
}
|
|
if err := h.db.Save(&config).Error; err != nil {
|
|
FailInternal(c, "更新失败: "+err.Error())
|
|
return
|
|
}
|
|
} else {
|
|
FailInternal(c, "数据库错误: "+result.Error.Error())
|
|
return
|
|
}
|
|
|
|
Success(c, config)
|
|
}
|
|
|
|
// ListConfigs 获取所有配置 GET /api/v1/admin/config
|
|
func (h *ConfigHandler) ListConfigs(c *gin.Context) {
|
|
var configs []model.Config
|
|
if err := h.db.Order("id ASC").Find(&configs).Error; err != nil {
|
|
FailInternal(c, "查询失败: "+err.Error())
|
|
return
|
|
}
|
|
Success(c, configs)
|
|
}
|
|
|
|
// BatchSetConfigs 批量设置配置 PUT /api/v1/admin/config
|
|
func (h *ConfigHandler) BatchSetConfigs(c *gin.Context) {
|
|
var req struct {
|
|
Items []ConfigItem `json:"items"`
|
|
}
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
FailBadRequest(c, "参数错误")
|
|
return
|
|
}
|
|
|
|
for _, item := range req.Items {
|
|
var config model.Config
|
|
result := h.db.Where("`key` = ?", item.Key).First(&config)
|
|
if result.Error == gorm.ErrRecordNotFound {
|
|
config = model.Config{
|
|
Key: item.Key,
|
|
Value: item.Value,
|
|
Remark: item.Remark,
|
|
}
|
|
h.db.Create(&config)
|
|
} else if result.Error == nil {
|
|
config.Value = item.Value
|
|
if item.Remark != "" {
|
|
config.Remark = item.Remark
|
|
}
|
|
h.db.Save(&config)
|
|
}
|
|
}
|
|
|
|
SuccessMsg(c, "保存成功")
|
|
}
|
|
|
|
// GetNavSettings 公开接口:获取导航页所有配置 GET /api/v1/nav-settings
|
|
func (h *ConfigHandler) GetNavSettings(c *gin.Context) {
|
|
// 导航页所有可配置项的 key 列表
|
|
keys := []string{
|
|
"nav_site_title",
|
|
"nav_hero_title",
|
|
"nav_hero_highlight",
|
|
"nav_hero_desc",
|
|
"nav_pill_templates",
|
|
"nav_pill_lines",
|
|
"nav_pill_industries",
|
|
"nav_pill_per_industry",
|
|
"nav_pill_responsive",
|
|
"nav_consult_title",
|
|
"nav_consult_desc",
|
|
"nav_consult_success",
|
|
"nav_footer_text",
|
|
"nav_company_name",
|
|
// 6 大行业标题
|
|
"nav_sec_enterprise_title",
|
|
"nav_sec_enterprise_sub",
|
|
"nav_sec_shop_title",
|
|
"nav_sec_shop_sub",
|
|
"nav_sec_food_title",
|
|
"nav_sec_food_sub",
|
|
"nav_sec_game_title",
|
|
"nav_sec_game_sub",
|
|
"nav_sec_app_title",
|
|
"nav_sec_app_sub",
|
|
"nav_sec_music_title",
|
|
"nav_sec_music_sub",
|
|
// 新板块
|
|
"nav_sec_appshow_title",
|
|
"nav_sec_appshow_sub",
|
|
"nav_sec_bizsys_title",
|
|
"nav_sec_bizsys_sub",
|
|
}
|
|
|
|
settings := map[string]string{}
|
|
for _, key := range keys {
|
|
var config model.Config
|
|
if err := h.db.Where("`key` = ?", key).First(&config).Error; err == nil {
|
|
settings[key] = config.Value
|
|
}
|
|
}
|
|
|
|
Success(c, settings)
|
|
}
|
|
|
|
// ConfigItem 配置项
|
|
type ConfigItem struct {
|
|
Key string `json:"key"`
|
|
Value string `json:"value"`
|
|
Remark string `json:"remark"`
|
|
}
|