|
@@ -5,6 +5,7 @@ import (
|
|
|
"iot_manager_service/app/system/model"
|
|
|
"iot_manager_service/util/common"
|
|
|
"sort"
|
|
|
+ "strconv"
|
|
|
)
|
|
|
|
|
|
var MenuService = new(menuService)
|
|
@@ -47,9 +48,9 @@ func (s *menuService) GetAll() []dao.Menu {
|
|
|
return menus
|
|
|
}
|
|
|
|
|
|
-func (s *menuService) Tree() ([]model.MenuRouteDetail, error) {
|
|
|
+func (s *menuService) Tree() ([]model.MenuTreeDetail, error) {
|
|
|
allMenus := s.GetAll()
|
|
|
- var rsp []model.MenuRouteDetail
|
|
|
+ var rsp []model.MenuTreeDetail
|
|
|
//上级角色——多个下级角色数组
|
|
|
tmp := make(map[int64][]dao.Menu)
|
|
|
for _, menu := range allMenus {
|
|
@@ -66,7 +67,7 @@ func (s *menuService) Tree() ([]model.MenuRouteDetail, error) {
|
|
|
return nil, nil
|
|
|
}
|
|
|
roots, _ := tmp[0]
|
|
|
- rsp = menuDfs(rsp, roots, tmp)
|
|
|
+ rsp = menuTreeDfs(rsp, roots, tmp)
|
|
|
|
|
|
return rsp, nil
|
|
|
}
|
|
@@ -129,6 +130,29 @@ func menuDfs(result []model.MenuRouteDetail, menus []dao.Menu, tmp map[int64][]d
|
|
|
return result
|
|
|
}
|
|
|
|
|
|
+func menuTreeDfs(result []model.MenuTreeDetail, menus []dao.Menu, tmp map[int64][]dao.Menu) []model.MenuTreeDetail {
|
|
|
+ if len(menus) == 0 {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ for _, child := range menus {
|
|
|
+ detail := model.MenuTreeDetail{}
|
|
|
+ detail.Title = child.Name
|
|
|
+ detail.ID = strconv.FormatInt(child.ID, 10)
|
|
|
+ detail.Key = strconv.FormatInt(child.ID, 10)
|
|
|
+ detail.Value = strconv.FormatInt(child.ID, 10)
|
|
|
+ childes, isExist := tmp[child.ID]
|
|
|
+ if isExist {
|
|
|
+ detail.HasChildren = true
|
|
|
+ detail.Children = menuTreeDfs([]model.MenuTreeDetail{}, childes, tmp)
|
|
|
+ result = append(result, detail)
|
|
|
+ } else {
|
|
|
+ detail.HasChildren = false
|
|
|
+ result = append(result, detail)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result
|
|
|
+}
|
|
|
+
|
|
|
func (s *menuService) LazyList(parentId int64, name, code, alias string) ([]model.MenuLazyListDetail, error) {
|
|
|
menu := &dao.Menu{
|
|
|
ParentId: parentId,
|