优化若干功能
This commit is contained in:
@@ -232,6 +232,49 @@ func (c *BackendMenuController) GetAllMenus() {
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
// filterAssignableMenus 仅保留「已启用且已显示」的菜单。
|
||||
// 停用或隐藏的菜单不参与角色权限分配,直接在服务端屏蔽,不依赖前端过滤。
|
||||
func filterAssignableMenus(menus []models.SystemMenu) []models.SystemMenu {
|
||||
out := make([]models.SystemMenu, 0, len(menus))
|
||||
for _, m := range menus {
|
||||
if m.Status != 1 {
|
||||
continue
|
||||
}
|
||||
// is_visible 为空视为显示
|
||||
if m.IsVisible != nil && *m.IsVisible == 0 {
|
||||
continue
|
||||
}
|
||||
out = append(out, m)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// GetAssignableMenus 获取可分配给角色的菜单树
|
||||
// 过滤规则(均在服务端完成):
|
||||
// 1. cid:按菜单所属端过滤(1=平台端 2=租户端,不传则不过滤)
|
||||
// 2. status=1:仅已启用的菜单
|
||||
// 3. is_visible != 0:仅已显示的菜单(为空视为显示)
|
||||
//
|
||||
// 父级菜单被过滤时,其子菜单一并不可分配(菜单树按 pid 构建,父级缺失则整条分支不会返回)。
|
||||
// GET /backend/assignableMenus?cid=2
|
||||
func (c *BackendMenuController) GetAssignableMenus() {
|
||||
var menus []models.SystemMenu
|
||||
cid, _ := c.GetInt("cid")
|
||||
|
||||
if _, err := models.Orm.QueryTable(new(models.SystemMenu)).All(&menus); err != nil {
|
||||
c.Data["json"] = map[string]interface{}{"code": 500, "msg": "获取菜单失败: " + err.Error(), "data": nil}
|
||||
_ = c.ServeJSON()
|
||||
return
|
||||
}
|
||||
if cid == 1 || cid == 2 {
|
||||
menus = filterMenusByView(menus, cid)
|
||||
}
|
||||
menus = filterAssignableMenus(menus)
|
||||
|
||||
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "success", "data": buildMenuTree(menus, 0)}
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
func (c *BackendMenuController) GetAllBackendMenus() {
|
||||
var menus []models.SystemMenu
|
||||
if _, err := models.Orm.QueryTable(new(models.SystemMenu)).All(&menus); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user