|
@@ -49,7 +49,6 @@ func (s *menuService) GetAll() []dao.Menu {
|
|
|
|
|
|
func (s *menuService) Tree() ([]model.MenuRouteDetail, error) {
|
|
|
allMenus := s.GetAll()
|
|
|
-
|
|
|
var rsp []model.MenuRouteDetail
|
|
|
//上级角色——多个下级角色数组
|
|
|
tmp := make(map[int64][]dao.Menu)
|
|
@@ -159,3 +158,41 @@ func (s *menuService) LazyList(parentId int64, name, code, alias string) ([]mode
|
|
|
}
|
|
|
return rsp, nil
|
|
|
}
|
|
|
+
|
|
|
+// 请求获取menu名称树(id,parent_id和name)
|
|
|
+func (s *menuService) GetNameTree() ([]model.MenuRouteDetail, error) {
|
|
|
+ menuDao := dao.Menu{
|
|
|
+ ParentId: int64(0),
|
|
|
+ }
|
|
|
+ var menuDetails []model.MenuRouteDetail
|
|
|
+ var temp model.MenuRouteDetail
|
|
|
+
|
|
|
+ //所有菜单包装为菜单详情
|
|
|
+ menus, _ := menuDao.GetMenuTree()
|
|
|
+ var allDetails []model.MenuRouteDetail
|
|
|
+ for _, v := range menus {
|
|
|
+ temp.Menu = v
|
|
|
+ allDetails = append(allDetails, temp)
|
|
|
+ }
|
|
|
+ //一级菜单 parent_id为0 包装为菜单详情
|
|
|
+ lv1s, _ := menuDao.GetByParentId()
|
|
|
+ for _, v := range lv1s {
|
|
|
+ temp.Menu = v
|
|
|
+ temp.Children, temp.HasChildren = s.getChildren(temp, allDetails)
|
|
|
+ menuDetails = append(menuDetails, temp)
|
|
|
+ }
|
|
|
+ return menuDetails, nil
|
|
|
+}
|
|
|
+
|
|
|
+func (s *menuService) getChildren(parent model.MenuRouteDetail,
|
|
|
+ all []model.MenuRouteDetail) ([]model.MenuRouteDetail, bool) {
|
|
|
+ id := parent.ID
|
|
|
+ var children []model.MenuRouteDetail
|
|
|
+ for _, detail := range all {
|
|
|
+ if detail.ParentId == id {
|
|
|
+ detail.Children, detail.HasChildren = s.getChildren(detail, all)
|
|
|
+ children = append(children, detail)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return children, children != nil
|
|
|
+}
|