Skip to content

Commit

Permalink
fix: authority tree generation and init database code
Browse files Browse the repository at this point in the history
  • Loading branch information
suyuan32 committed Sep 30, 2022
1 parent df4eb98 commit ad1318b
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 60 deletions.
4 changes: 3 additions & 1 deletion rpc/internal/logic/getmenuauthoritylogic.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ func (l *GetMenuAuthorityLogic) GetMenuAuthority(in *core.IDReq) (*core.RoleMenu
}
var menuIds []uint64
for _, v := range r.Menus {
menuIds = append(menuIds, uint64(v.ID))
if v.ID != 1 {
menuIds = append(menuIds, uint64(v.ID))
}
}
return &core.RoleMenuAuthorityResp{MenuId: menuIds}, nil
}
80 changes: 41 additions & 39 deletions rpc/internal/logic/getmenulistbyrolelogic.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,55 +48,57 @@ func (l *GetMenuListByRoleLogic) GetMenuListByRole(in *core.IDReq) (*core.MenuIn
for _, v := range r.Menus {
validId[v.ID] = struct{}{}
}
res.Data = findRoleMenuChildren(r.Menus, validId)
res.Data = findRoleMenuChildren(r.Menus, validId, 1)
// delete menus whose menu levels are not 1
var tmp []*core.MenuInfo
for _, v := range res.Data {
if v.Level == 1 {
tmp = append(tmp, v)
}
}
res.Data = tmp
//var tmp []*core.MenuInfo
//for _, v := range res.Data {
// if v.Level == 1 {
// tmp = append(tmp, v)
// }
//}
//res.Data = tmp
return res, nil
}

func findRoleMenuChildren(data []model.Menu, validId map[uint]struct{}) []*core.MenuInfo {
func findRoleMenuChildren(data []model.Menu, validId map[uint]struct{}, parentId uint) []*core.MenuInfo {
if data == nil {
return nil
}
var result []*core.MenuInfo
for _, v := range data {
if _, ok := validId[v.ID]; ok {
tmp := &core.MenuInfo{
Id: uint64(v.ID),
CreateAt: v.CreatedAt.Unix(),
UpdateAt: v.UpdatedAt.Unix(),
MenuType: v.MenuType,
Level: v.MenuLevel,
ParentId: uint32(v.ParentId),
Path: v.Path,
Name: v.Name,
Redirect: v.Redirect,
Component: v.Component,
OrderNo: v.OrderNo,
Meta: &core.Meta{
Title: v.Meta.Title,
Icon: v.Meta.Icon,
HideMenu: v.Meta.HideMenu,
HideBreadcrumb: v.Meta.HideBreadcrumb,
CurrentActiveMenu: v.Meta.CurrentActiveMenu,
IgnoreKeepAlive: v.Meta.IgnoreKeepAlive,
HideTab: v.Meta.HideTab,
FrameSrc: v.Meta.FrameSrc,
CarryParam: v.Meta.CarryParam,
HideChildrenInMenu: v.Meta.HideChildrenInMenu,
Affix: v.Meta.Affix,
DynamicLevel: v.Meta.DynamicLevel,
RealPath: v.Meta.RealPath,
},
Children: findRoleMenuChildren(v.Children, validId),
if v.ParentId == parentId && v.ID != v.ParentId {
if _, ok := validId[v.ID]; ok {
tmp := &core.MenuInfo{
Id: uint64(v.ID),
CreateAt: v.CreatedAt.UnixMilli(),
UpdateAt: v.UpdatedAt.UnixMilli(),
MenuType: v.MenuType,
Level: v.MenuLevel,
ParentId: uint32(v.ParentId),
Path: v.Path,
Name: v.Name,
Redirect: v.Redirect,
Component: v.Component,
OrderNo: v.OrderNo,
Meta: &core.Meta{
Title: v.Meta.Title,
Icon: v.Meta.Icon,
HideMenu: v.Meta.HideMenu,
HideBreadcrumb: v.Meta.HideBreadcrumb,
CurrentActiveMenu: v.Meta.CurrentActiveMenu,
IgnoreKeepAlive: v.Meta.IgnoreKeepAlive,
HideTab: v.Meta.HideTab,
FrameSrc: v.Meta.FrameSrc,
CarryParam: v.Meta.CarryParam,
HideChildrenInMenu: v.Meta.HideChildrenInMenu,
Affix: v.Meta.Affix,
DynamicLevel: v.Meta.DynamicLevel,
RealPath: v.Meta.RealPath,
},
Children: findRoleMenuChildren(data, validId, v.ID),
}
result = append(result, tmp)
}
result = append(result, tmp)
}
}
return result
Expand Down
62 changes: 42 additions & 20 deletions rpc/internal/logic/initdatabaselogic.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ func (l *InitDatabaseLogic) insertMenuData() error {
Meta: model.Meta{
Title: "routes.system.fileManagementTitle",
Icon: "ant-design:folder-open-outlined",
HideMenu: false,
HideMenu: true,
HideBreadcrumb: true,
IgnoreKeepAlive: false,
HideTab: false,
Expand All @@ -595,18 +595,18 @@ func (l *InitDatabaseLogic) insertMenuData() error {
},
},
{
MenuLevel: 1,
MenuLevel: 2,
MenuType: 1,
ParentId: 7,
Path: "/profile",
Name: "Profile",
Component: "/sys/profile/index",
OrderNo: 3,
ParentId: 3,
Path: "/dictionary",
Name: "Dictionary Management",
Component: "/sys/dictionary/index",
OrderNo: 5,
Disabled: false,
Meta: model.Meta{
Title: "routes.system.userProfileTitle",
Icon: "ant-design:profile-outlined",
HideMenu: true,
Title: "routes.system.dictionaryManagementTitle",
Icon: "ant-design:book-outlined",
HideMenu: false,
HideBreadcrumb: true,
IgnoreKeepAlive: false,
HideTab: false,
Expand All @@ -617,18 +617,18 @@ func (l *InitDatabaseLogic) insertMenuData() error {
},
},
{
MenuLevel: 2,
MenuType: 1,
ParentId: 3,
Path: "/dictionary",
Name: "Dictionary Management",
Component: "/sys/dictionary/index",
OrderNo: 5,
MenuLevel: 1,
MenuType: 0,
ParentId: 1,
Path: "",
Name: "Other Pages",
Component: "LAYOUT",
OrderNo: 4,
Disabled: false,
Meta: model.Meta{
Title: "routes.system.dictionaryManagementTitle",
Icon: "ant-design:book-outlined",
HideMenu: false,
Title: "routes.system.otherPages",
Icon: "ant-design:question-circle-outlined",
HideMenu: true,
HideBreadcrumb: true,
IgnoreKeepAlive: false,
HideTab: false,
Expand Down Expand Up @@ -660,6 +660,28 @@ func (l *InitDatabaseLogic) insertMenuData() error {
DynamicLevel: 20,
},
},
{
MenuLevel: 1,
MenuType: 1,
ParentId: 10,
Path: "/profile",
Name: "Profile",
Component: "/sys/profile/index",
OrderNo: 3,
Disabled: false,
Meta: model.Meta{
Title: "routes.system.userProfileTitle",
Icon: "ant-design:profile-outlined",
HideMenu: true,
HideBreadcrumb: true,
IgnoreKeepAlive: false,
HideTab: false,
CarryParam: false,
HideChildrenInMenu: false,
Affix: false,
DynamicLevel: 20,
},
},
}
result := l.svcCtx.DB.CreateInBatches(menus, 100)
if result.Error != nil {
Expand Down

0 comments on commit ad1318b

Please sign in to comment.