更新
This commit is contained in:
1 parent
012f8edf8b
commit
36ff960fbd
33 files changed
+1644
-344
No files matched your search
@@ -52,7 +52,6 @@ func (c *PlatformModulesController) modulesClaims() (*jwtutil.Claims, error) {
|
||||
return identity.ClaimsByPath(c.Ctx.Request.Header.Get("Authorization"), c.Ctx.Request.URL.Path)
|
||||
}
|
||||
|
||||
|
||||
func (c *PlatformModulesController) jsonErr(httpStatus, bizCode int, msg string) {
|
||||
c.Ctx.Output.SetStatus(httpStatus)
|
||||
c.Data["json"] = map[string]interface{}{"code": bizCode, "msg": msg}
|
||||
@@ -79,18 +78,19 @@ func (c *PlatformModulesController) GetList() {
|
||||
list := make([]map[string]interface{}, 0, len(rows))
|
||||
for i := range rows {
|
||||
list = append(list, map[string]interface{}{
|
||||
"id": rows[i].ID,
|
||||
"mid": rows[i].Mid,
|
||||
"name": rows[i].Name,
|
||||
"code": rows[i].Code,
|
||||
"path": rows[i].Path,
|
||||
"icon": rows[i].Icon,
|
||||
"description": rows[i].Description,
|
||||
"type": rows[i].Type,
|
||||
"sort": rows[i].Sort,
|
||||
"status": rows[i].Status,
|
||||
"is_show": rows[i].IsShow,
|
||||
"platforms": platformList(&rows[i]),
|
||||
"id": rows[i].ID,
|
||||
"mid": rows[i].Mid,
|
||||
"name": rows[i].Name,
|
||||
"code": rows[i].Code,
|
||||
"path": rows[i].Path,
|
||||
"icon": rows[i].Icon,
|
||||
"description": rows[i].Description,
|
||||
"type": rows[i].Type,
|
||||
"sort": rows[i].Sort,
|
||||
"status": rows[i].Status,
|
||||
"is_show": rows[i].IsShow,
|
||||
"require_login": rows[i].RequireLogin,
|
||||
"platforms": platformList(&rows[i]),
|
||||
})
|
||||
}
|
||||
c.Data["json"] = map[string]interface{}{
|
||||
@@ -156,22 +156,54 @@ func (c *PlatformModulesController) GetDetail() {
|
||||
c.jsonErr(404, 404, "模块不存在")
|
||||
return
|
||||
}
|
||||
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "获取成功", "data": row}
|
||||
// 与 GetList 保持一致的规范化输出:platforms 统一为数组、带上 require_login。
|
||||
// 否则详情回填时 platforms 是原始 JSON 字符串,编辑提交会因 []string 反序列化失败报 400。
|
||||
c.Data["json"] = map[string]interface{}{
|
||||
"code": 200,
|
||||
"msg": "获取成功",
|
||||
"data": map[string]interface{}{
|
||||
"id": row.ID,
|
||||
"mid": row.Mid,
|
||||
"name": row.Name,
|
||||
"code": row.Code,
|
||||
"path": row.Path,
|
||||
"icon": row.Icon,
|
||||
"description": row.Description,
|
||||
"type": row.Type,
|
||||
"sort": row.Sort,
|
||||
"status": row.Status,
|
||||
"is_show": row.IsShow,
|
||||
"require_login": row.RequireLogin,
|
||||
"platforms": platformList(&row),
|
||||
},
|
||||
}
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
type modulePayload struct {
|
||||
Mid *uint64 `json:"mid"`
|
||||
Name string `json:"name"`
|
||||
Code string `json:"code"`
|
||||
Path string `json:"path"`
|
||||
Icon string `json:"icon"`
|
||||
Description string `json:"description"`
|
||||
Type int `json:"type"`
|
||||
Sort int `json:"sort"`
|
||||
Status int8 `json:"status"`
|
||||
IsShow int8 `json:"is_show"`
|
||||
Platforms []string `json:"platforms"` // 展示端:["web"] ["app"] ["web","app"];空=全端
|
||||
Mid *uint64 `json:"mid"`
|
||||
Name string `json:"name"`
|
||||
Code string `json:"code"`
|
||||
Path string `json:"path"`
|
||||
Icon string `json:"icon"`
|
||||
Description string `json:"description"`
|
||||
Type int `json:"type"`
|
||||
Sort int `json:"sort"`
|
||||
Status int8 `json:"status"`
|
||||
IsShow int8 `json:"is_show"`
|
||||
Platforms []string `json:"platforms"` // 展示端:["web"] ["app"] ["web","app"];空=全端
|
||||
RequireLogin *int8 `json:"require_login"` // 是否必须登录:1=必须 0=可免登录;指针以区分「未传」(默认 1)
|
||||
}
|
||||
|
||||
// resolveRequireLogin 未传该字段时回落为 1(必须登录),保持既有行为不变。
|
||||
func resolveRequireLogin(v *int8) int8 {
|
||||
if v == nil {
|
||||
return 1
|
||||
}
|
||||
if *v != 0 && *v != 1 {
|
||||
return 1
|
||||
}
|
||||
return *v
|
||||
}
|
||||
|
||||
// Add POST /platform/modules
|
||||
@@ -213,18 +245,19 @@ func (c *PlatformModulesController) Add() {
|
||||
now := time.Now()
|
||||
platforms := services.NormalizePlatforms(p.Platforms)
|
||||
row := &models.SystemModules{
|
||||
Mid: p.Mid,
|
||||
Name: p.Name,
|
||||
Code: p.Code,
|
||||
Path: strings.TrimSpace(p.Path),
|
||||
Icon: strings.TrimSpace(p.Icon),
|
||||
Description: strings.TrimSpace(p.Description),
|
||||
Type: p.Type,
|
||||
Sort: p.Sort,
|
||||
Status: p.Status,
|
||||
IsShow: p.IsShow,
|
||||
CreateTime: &now,
|
||||
UpdateTime: &now,
|
||||
Mid: p.Mid,
|
||||
Name: p.Name,
|
||||
Code: p.Code,
|
||||
Path: strings.TrimSpace(p.Path),
|
||||
Icon: strings.TrimSpace(p.Icon),
|
||||
Description: strings.TrimSpace(p.Description),
|
||||
Type: p.Type,
|
||||
Sort: p.Sort,
|
||||
Status: p.Status,
|
||||
IsShow: p.IsShow,
|
||||
RequireLogin: resolveRequireLogin(p.RequireLogin),
|
||||
CreateTime: &now,
|
||||
UpdateTime: &now,
|
||||
}
|
||||
if platforms != "" {
|
||||
row.Platforms = &platforms
|
||||
@@ -284,18 +317,19 @@ func (c *PlatformModulesController) Edit() {
|
||||
now := time.Now()
|
||||
// 展示端为空串表示「全端」,需显式落库以覆盖历史值
|
||||
up := map[string]interface{}{
|
||||
"mid": p.Mid,
|
||||
"name": p.Name,
|
||||
"code": p.Code,
|
||||
"path": strings.TrimSpace(p.Path),
|
||||
"icon": strings.TrimSpace(p.Icon),
|
||||
"description": strings.TrimSpace(p.Description),
|
||||
"type": p.Type,
|
||||
"sort": p.Sort,
|
||||
"status": p.Status,
|
||||
"is_show": p.IsShow,
|
||||
"platforms": services.NormalizePlatforms(p.Platforms),
|
||||
"update_time": now,
|
||||
"mid": p.Mid,
|
||||
"name": p.Name,
|
||||
"code": p.Code,
|
||||
"path": strings.TrimSpace(p.Path),
|
||||
"icon": strings.TrimSpace(p.Icon),
|
||||
"description": strings.TrimSpace(p.Description),
|
||||
"type": p.Type,
|
||||
"sort": p.Sort,
|
||||
"status": p.Status,
|
||||
"is_show": p.IsShow,
|
||||
"require_login": resolveRequireLogin(p.RequireLogin),
|
||||
"platforms": services.NormalizePlatforms(p.Platforms),
|
||||
"update_time": now,
|
||||
}
|
||||
n, err := models.Orm.QueryTable(new(models.SystemModules)).
|
||||
Filter("id", id).
|
||||
|
||||
Reference in new issue
Block a user