|
@@ -8,31 +8,44 @@ import (
|
|
pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
|
|
pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+const (
|
|
|
|
+ PermissionBtnAdd = "permission:btn:add"
|
|
|
|
+ PermissionBtnEdit = "permission:btn:edit"
|
|
|
|
+ PermissionBtnDelete = "permission:btn:delete"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+var PermissionBtnMap = map[pasturePb.ButtonType_Kind]string{
|
|
|
|
+ pasturePb.ButtonType_Add: PermissionBtnAdd,
|
|
|
|
+ pasturePb.ButtonType_Edit: PermissionBtnEdit,
|
|
|
|
+ pasturePb.ButtonType_Delete: PermissionBtnDelete,
|
|
|
|
+}
|
|
|
|
+
|
|
type SystemMenu struct {
|
|
type SystemMenu struct {
|
|
- Id int64 `json:"id"`
|
|
|
|
- Name string `json:"name"`
|
|
|
|
- Title string `json:"title"`
|
|
|
|
- Path string `json:"path"`
|
|
|
|
- Icon string `json:"icon"`
|
|
|
|
- Component string `json:"component"`
|
|
|
|
- Redirect string `json:"redirect"`
|
|
|
|
- Auths string `json:"auths"`
|
|
|
|
- MenuType pasturePb.MenuType_Kind `json:"menuType"`
|
|
|
|
- ParentId int64 `json:"parentId"`
|
|
|
|
- Rank int32 `json:"rank"`
|
|
|
|
- ExtraIcon string `json:"extraIcon"`
|
|
|
|
- EnterTransition string `json:"enterTransition"`
|
|
|
|
- ActivePath string `json:"activePath"`
|
|
|
|
- FrameSrc string `json:"frameSrc"`
|
|
|
|
- FrameLoading pasturePb.IsShow_Kind `json:"frameLoading"`
|
|
|
|
- Keepalive pasturePb.IsShow_Kind `json:"keepalive"`
|
|
|
|
- HiddenTag pasturePb.IsShow_Kind `json:"hiddenTag"`
|
|
|
|
- ShowLink pasturePb.IsShow_Kind `json:"showLink"`
|
|
|
|
- ShowParent pasturePb.IsShow_Kind `json:"showParent"`
|
|
|
|
- IsShow pasturePb.IsShow_Kind `json:"isShow"`
|
|
|
|
- IsDelete pasturePb.IsShow_Kind `json:"isDelete"`
|
|
|
|
- CreatedAt int64 `json:"createdAt"`
|
|
|
|
- UpdatedAt int64 `json:"updatedAt"`
|
|
|
|
|
|
+ Id int64 `json:"id"`
|
|
|
|
+ Name string `json:"name"`
|
|
|
|
+ Title string `json:"title"`
|
|
|
|
+ Path string `json:"path"`
|
|
|
|
+ Icon string `json:"icon"`
|
|
|
|
+ Component string `json:"component"`
|
|
|
|
+ Redirect string `json:"redirect"`
|
|
|
|
+ Auths string `json:"auths"`
|
|
|
|
+ MenuType pasturePb.MenuType_Kind `json:"menuType"`
|
|
|
|
+ ButtonType pasturePb.ButtonType_Kind `json:"buttonType"`
|
|
|
|
+ ParentId int64 `json:"parentId"`
|
|
|
|
+ Rank int32 `json:"rank"`
|
|
|
|
+ ExtraIcon string `json:"extraIcon"`
|
|
|
|
+ EnterTransition string `json:"enterTransition"`
|
|
|
|
+ ActivePath string `json:"activePath"`
|
|
|
|
+ FrameSrc string `json:"frameSrc"`
|
|
|
|
+ FrameLoading pasturePb.IsShow_Kind `json:"frameLoading"`
|
|
|
|
+ Keepalive pasturePb.IsShow_Kind `json:"keepalive"`
|
|
|
|
+ HiddenTag pasturePb.IsShow_Kind `json:"hiddenTag"`
|
|
|
|
+ ShowLink pasturePb.IsShow_Kind `json:"showLink"`
|
|
|
|
+ ShowParent pasturePb.IsShow_Kind `json:"showParent"`
|
|
|
|
+ IsShow pasturePb.IsShow_Kind `json:"isShow"`
|
|
|
|
+ IsDelete pasturePb.IsShow_Kind `json:"isDelete"`
|
|
|
|
+ CreatedAt int64 `json:"createdAt"`
|
|
|
|
+ UpdatedAt int64 `json:"updatedAt"`
|
|
}
|
|
}
|
|
|
|
|
|
func (s *SystemMenu) TableName() string {
|
|
func (s *SystemMenu) TableName() string {
|
|
@@ -152,22 +165,26 @@ func (s SystemMenuSlice) ToTree() []*pasturePb.MenuTree {
|
|
|
|
|
|
for i, v := range s {
|
|
for i, v := range s {
|
|
res[i] = &pasturePb.MenuTree{
|
|
res[i] = &pasturePb.MenuTree{
|
|
- Id: int32(v.Id),
|
|
|
|
- Path: v.Path,
|
|
|
|
- ParentId: int32(v.ParentId),
|
|
|
|
- Name: v.Name,
|
|
|
|
|
|
+ Id: int32(v.Id),
|
|
|
|
+ Path: v.Path,
|
|
|
|
+ ParentId: int32(v.ParentId),
|
|
|
|
+ Name: v.Name,
|
|
|
|
+ ButtonType: v.ButtonType,
|
|
Meta: &pasturePb.MenuMeta{
|
|
Meta: &pasturePb.MenuMeta{
|
|
Icon: v.Icon,
|
|
Icon: v.Icon,
|
|
Title: v.Title,
|
|
Title: v.Title,
|
|
Rank: v.Rank,
|
|
Rank: v.Rank,
|
|
Roles: []string{},
|
|
Roles: []string{},
|
|
ShowLink: v.ShowLink == pasturePb.IsShow_Ok,
|
|
ShowLink: v.ShowLink == pasturePb.IsShow_Ok,
|
|
|
|
+ Auths: make([]string, 0),
|
|
},
|
|
},
|
|
Children: make([]*pasturePb.MenuTree, 0),
|
|
Children: make([]*pasturePb.MenuTree, 0),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 构建树
|
|
// 构建树
|
|
- return buildTree(res)
|
|
|
|
|
|
+ tree := buildTree(res)
|
|
|
|
+ processMenuType4Nodes(tree)
|
|
|
|
+ return tree
|
|
}
|
|
}
|
|
|
|
|
|
func buildTree(menuTreeList []*pasturePb.MenuTree) []*pasturePb.MenuTree {
|
|
func buildTree(menuTreeList []*pasturePb.MenuTree) []*pasturePb.MenuTree {
|
|
@@ -197,6 +214,31 @@ func findByID(menuTreeList []*pasturePb.MenuTree, id int32) *pasturePb.MenuTree
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// 新增函数:处理 menu_type == 4 的节点
|
|
|
|
+func processMenuType4Nodes(menus []*pasturePb.MenuTree) {
|
|
|
|
+ // 首先构建一个快速查找表
|
|
|
|
+ nodeMap := make(map[int32]*pasturePb.MenuTree)
|
|
|
|
+ buildNodeMap(menus, nodeMap)
|
|
|
|
+
|
|
|
|
+ // 遍历所有节点
|
|
|
|
+ for _, menu := range nodeMap {
|
|
|
|
+ if menu.MenuType == pasturePb.MenuType_Button && menu.ButtonType > pasturePb.ButtonType_Invalid {
|
|
|
|
+ parent := nodeMap[menu.ParentId]
|
|
|
|
+ if parent != nil && parent.Meta != nil {
|
|
|
|
+ parent.Meta.Auths = append(parent.Meta.Auths, PermissionBtnMap[menu.ButtonType])
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 新增函数:构建节点映射表
|
|
|
|
+func buildNodeMap(menus []*pasturePb.MenuTree, nodeMap map[int32]*pasturePb.MenuTree) {
|
|
|
|
+ for _, menu := range menus {
|
|
|
|
+ nodeMap[menu.Id] = menu
|
|
|
|
+ buildNodeMap(menu.Children, nodeMap)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
type MenuItem struct {
|
|
type MenuItem struct {
|
|
Path string `json:"path"`
|
|
Path string `json:"path"`
|
|
Name string `json:"name"`
|
|
Name string `json:"name"`
|