171 lines
7.2 KiB
Go
171 lines
7.2 KiB
Go
package v1
|
||
|
||
import (
|
||
"encoding/json"
|
||
"errors"
|
||
|
||
"github.com/gogf/gf/v2/net/ghttp"
|
||
"github.com/gogf/gf/v2/util/gmeta"
|
||
)
|
||
|
||
// ============================== 配置模块 ==============================
|
||
|
||
// ConfigItemRow 配置项行数据
|
||
// 内嵌使用,供配置详情、配置列表展示配置项明细
|
||
type ConfigItemRow struct {
|
||
Id int64 `json:"id"` // 主键ID
|
||
Name string `json:"name"` // 配置项名称
|
||
Code string `json:"code"` // 配置项编码
|
||
Value string `json:"value"` // 配置项值
|
||
Type string `json:"type"` // 控件类型
|
||
Status int `json:"status"` // 状态
|
||
Sort int `json:"sort"` // 排序
|
||
}
|
||
|
||
// ConfigItem 配置行数据
|
||
// 用于分页列表等场景的配置基础信息
|
||
type ConfigItem struct {
|
||
Id int64 `json:"id"` // 主键ID
|
||
Name string `json:"name"` // 配置名称
|
||
Code string `json:"code"` // 配置编码
|
||
Sort int `json:"sort"` // 排序
|
||
Note string `json:"note"` // 备注
|
||
CreateUser string `json:"createUser"` // 创建人
|
||
}
|
||
|
||
// ConfigPageReq 配置分页请求
|
||
// 支持关键词、配置名称等条件组合查询
|
||
type ConfigPageReq struct {
|
||
gmeta.Meta `method:"get" path:"/api/config/page" summary:"配置分页" permission:"sys:config:page" log:"配置管理-查询分页记录" logType:"query"`
|
||
PageReq // 分页基础参数
|
||
Keyword string `json:"keyword" dc:"关键词(名称/编码模糊)"` // 关键词,名称或编码模糊匹配
|
||
Name string `json:"name" dc:"配置名称模糊"` // 配置名称模糊匹配
|
||
}
|
||
|
||
// ConfigPageRes 配置分页结果
|
||
type ConfigPageRes = PageData[ConfigItem]
|
||
|
||
// ConfigListReq 配置列表请求
|
||
// 返回的每一项均携带其下的配置项集合
|
||
type ConfigListReq struct {
|
||
gmeta.Meta `method:"get" path:"/api/config/list" summary:"配置列表" permission:"sys:config:list" log:"配置管理-查询列表" logType:"query"`
|
||
Keyword string `json:"keyword" dc:"关键词"` // 关键词
|
||
}
|
||
|
||
// ConfigListRes 配置列表结果
|
||
// 列表每一项携带其下的配置项集合
|
||
type ConfigListRes = []ConfigWithItems
|
||
|
||
// ConfigWithItems 配置及其配置项集合
|
||
// 用于列表、详情等需要同时返回配置与配置项的场景
|
||
type ConfigWithItems struct {
|
||
ConfigItem
|
||
Items []ConfigItemRow `json:"items"` // 配置项集合
|
||
}
|
||
|
||
// ConfigDetailReq 配置详情请求
|
||
type ConfigDetailReq struct {
|
||
gmeta.Meta `method:"get" path:"/api/config/detail/:id" summary:"配置详情" permission:"sys:config:detail" log:"配置管理-查询详情" logType:"query"`
|
||
Id int64 `json:"id" v:"required#缺少ID" dc:"配置ID"` // 配置ID
|
||
}
|
||
|
||
// ConfigDetailRes 配置详情结果
|
||
// 包含配置基础信息及其下的配置项集合
|
||
type ConfigDetailRes struct {
|
||
ConfigItem
|
||
Items []ConfigItemRow `json:"items"` // 配置项集合
|
||
}
|
||
|
||
// ConfigAddReq 新增配置请求
|
||
type ConfigAddReq struct {
|
||
gmeta.Meta `method:"post" path:"/api/config/add" summary:"新增配置" permission:"sys:config:add" log:"配置管理-新增记录" logType:"add"`
|
||
Name string `json:"name" v:"required#请输入配置名称" dc:"配置名称"` // 配置名称
|
||
Code string `json:"code" v:"required#请输入配置编码" dc:"配置编码"` // 配置编码
|
||
Sort int `json:"sort" dc:"排序"` // 排序
|
||
Note string `json:"note" dc:"备注"` // 备注
|
||
}
|
||
|
||
// ConfigUpdateReq 修改配置请求
|
||
type ConfigUpdateReq struct {
|
||
gmeta.Meta `method:"put" path:"/api/config/update" summary:"修改配置" permission:"sys:config:update" log:"配置管理-修改记录" logType:"update"`
|
||
Id int64 `json:"id" v:"required#缺少ID" dc:"配置ID"` // 配置ID
|
||
Name string `json:"name" v:"required#请输入配置名称" dc:"配置名称"` // 配置名称
|
||
Code string `json:"code" v:"required#请输入配置编码" dc:"配置编码"` // 配置编码
|
||
Sort int `json:"sort" dc:"排序"` // 排序
|
||
Note string `json:"note" dc:"备注"` // 备注
|
||
}
|
||
|
||
// ConfigUpdateRes 修改配置结果
|
||
type ConfigUpdateRes struct{}
|
||
|
||
// ConfigDeleteReq 删除配置请求
|
||
type ConfigDeleteReq struct {
|
||
gmeta.Meta `method:"delete" path:"/api/config/delete/:id" summary:"删除配置" permission:"sys:config:delete" log:"配置管理-删除记录" logType:"delete"`
|
||
Id int64 `json:"id" v:"required#缺少ID" dc:"配置ID"` // 配置ID
|
||
}
|
||
|
||
// ConfigDeleteRes 删除配置结果
|
||
type ConfigDeleteRes struct{}
|
||
|
||
// ConfigBatchDeleteReq 批量删除配置请求
|
||
type ConfigBatchDeleteReq struct {
|
||
gmeta.Meta `method:"delete" path:"/api/config/batchDelete" summary:"批量删除配置" permission:"sys:config:batchDelete" log:"配置管理-批量删除记录" logType:"delete"`
|
||
Ids []int64 `json:"ids" v:"required#请选择要删除的记录" dc:"配置ID列表"` // 配置ID列表
|
||
}
|
||
|
||
// ConfigBatchDeleteRes 批量删除结果
|
||
type ConfigBatchDeleteRes struct{}
|
||
|
||
// ConfigWebIndexReq 获取网站配置请求
|
||
// 返回配置分组及其下的配置项,供网站配置页渲染
|
||
type ConfigWebIndexReq struct {
|
||
gmeta.Meta `method:"get" path:"/api/config/web/index" summary:"获取网站配置" permission:"sys:configWeb:data" log:"网站配置-获取配置" logType:"query"`
|
||
}
|
||
|
||
// ConfigWebItem 网站配置项
|
||
// value 按控件类型拼接访问URL;images/files 类型拆分到 valueList;options 解析为 param 映射
|
||
type ConfigWebItem struct {
|
||
Id int64 `json:"id"` // 主键ID
|
||
Name string `json:"name"` // 配置项名称
|
||
Code string `json:"code"` // 配置项编码
|
||
Value string `json:"value"` // 配置项值
|
||
ValueList []string `json:"valueList"` // 值列表,多值类型使用
|
||
Type string `json:"type"` // 控件类型
|
||
Options string `json:"options"` // 可选项原始串
|
||
Param map[string]string `json:"param"` // 可选项解析后的映射
|
||
}
|
||
|
||
// ConfigWebGroup 配置分组
|
||
// 表示一个配置标签页下的配置项集合
|
||
type ConfigWebGroup struct {
|
||
ConfigName string `json:"configName"` // 配置分组名称
|
||
DataList []ConfigWebItem `json:"dataList"` // 分组下的配置项集合
|
||
}
|
||
|
||
// ConfigWebIndexRes 网站配置聚合结果
|
||
type ConfigWebIndexRes = []ConfigWebGroup
|
||
|
||
// ConfigWebSaveReq 保存网站配置请求
|
||
// body 顶层为配置项编码到值的平铺映射,采用自定义解析
|
||
type ConfigWebSaveReq struct {
|
||
gmeta.Meta `method:"post" path:"/api/config/web/save" summary:"保存网站配置" permission:"sys:configWeb:save" log:"网站配置-保存配置" logType:"update"`
|
||
Data map[string]any `json:"data" dc:"配置项编码 → 值"` // 配置项编码到值的映射
|
||
}
|
||
|
||
// UnmarshalBody 自定义请求体解析
|
||
// body 顶层为配置项编码到值的平铺映射,跳过默认的请求参数解析流程
|
||
func (r *ConfigWebSaveReq) UnmarshalBody(req *ghttp.Request) error {
|
||
var data map[string]any
|
||
if err := json.Unmarshal(req.GetBody(), &data); err != nil {
|
||
return err
|
||
}
|
||
if len(data) == 0 {
|
||
return errors.New("请提交配置数据")
|
||
}
|
||
r.Data = data
|
||
return nil
|
||
}
|
||
|
||
// ConfigWebSaveRes 保存网站配置结果
|
||
type ConfigWebSaveRes struct{}
|