feat(config): 新增配置回收站与还原功能

- 配置列表支持 deleted=1 查询已删除配置
- 新增 POST /admin/config/restore/:id,还原配置并写入 restore 历史
- 前端新增回收站页面,配置列表「新建配置」右侧增加红色入口按钮
This commit is contained in:
2026-09-23 21:13:30 +08:00
parent 185e458b45
commit bb90f9cf79
7 changed files with 190 additions and 1 deletions
+1
View File
@@ -66,6 +66,7 @@ func main() {
admin.POST("/config/add", configHandler.Add)
admin.POST("/config/update", configHandler.Update)
admin.POST("/config/delete/:id", configHandler.Delete)
admin.POST("/config/restore/:id", configHandler.Restore)
admin.GET("/config/configHistories/:id", configHandler.GetHistory)
admin.POST("/config/history/delete/:id", configHandler.DeleteHistory)
admin.POST("/config/rollback/:id", configHandler.Rollback)
+37 -1
View File
@@ -28,6 +28,7 @@ type ConfigListRequest struct {
PageSize int `form:"pageSize" binding:"required"`
Env string `form:"env"`
AppId *int `form:"appId"`
Deleted bool `form:"deleted"`
}
func (h *ConfigHandler) List(c *gin.Context) {
@@ -48,7 +49,11 @@ func (h *ConfigHandler) List(c *gin.Context) {
}
// 构建查询条件
conditions := []string{"enabled = 1"}
enabledCond := "enabled = 1"
if req.Deleted {
enabledCond = "enabled = 0"
}
conditions := []string{enabledCond}
args := make([]interface{}, 0, 4)
if req.Env != "" {
conditions = append(conditions, "env = ?")
@@ -320,6 +325,37 @@ func (h *ConfigHandler) Delete(c *gin.Context) {
c.JSON(http.StatusOK, model.WrapperResponse{Code: 0})
}
// Restore 从回收站还原配置
func (h *ConfigHandler) Restore(c *gin.Context) {
id, _ := strconv.Atoi(c.Param("id"))
var config model.AppConfig
has, _ := dao.Engine.ID(id).Get(&config)
if !has {
c.JSON(http.StatusOK, model.WrapperResponse{Code: 404, Msg: "配置不存在"})
return
}
userInfo := middleware.GetUserInfo(c)
if err := h.permService.RequirePermission(userInfo, config.GroupId, config.AppId); err != nil {
c.JSON(http.StatusForbidden, model.WrapperResponse{Code: 403, Msg: err.Error()})
return
}
if config.Enabled {
c.JSON(http.StatusOK, model.WrapperResponse{Code: 400, Msg: "配置未被删除"})
return
}
now := time.Now()
h.saveHistory(&config, userInfo.Name, "restore", now)
config.Enabled = true
config.UpdatedBy = userInfo.Name
config.UpdatedAt = &now
dao.Engine.ID(config.Id).Cols("enabled", "updated_by", "updated_at").Update(&config)
c.JSON(http.StatusOK, model.WrapperResponse{Code: 0, Data: true})
}
func (h *ConfigHandler) GetHistory(c *gin.Context) {
id, _ := strconv.Atoi(c.Param("id"))