|
@@ -12,7 +12,7 @@ var MenuService = new(menuService)
|
|
|
|
|
|
type menuService struct{}
|
|
type menuService struct{}
|
|
|
|
|
|
-func (s *menuService) Get(id int64) (*dao.Menu, error) {
|
|
|
|
|
|
+func (s *menuService) Get(id int) (*dao.Menu, error) {
|
|
menu := &dao.Menu{
|
|
menu := &dao.Menu{
|
|
ID: id,
|
|
ID: id,
|
|
}
|
|
}
|
|
@@ -24,10 +24,9 @@ func (s *menuService) Get(id int64) (*dao.Menu, error) {
|
|
}
|
|
}
|
|
|
|
|
|
func (s *menuService) Submit(req model.MenuSubmit) *common.Errors {
|
|
func (s *menuService) Submit(req model.MenuSubmit) *common.Errors {
|
|
- pId, _ := strconv.ParseInt(req.ParentId, 10, 64)
|
|
|
|
menu := &dao.Menu{
|
|
menu := &dao.Menu{
|
|
ID: req.ID,
|
|
ID: req.ID,
|
|
- ParentId: pId,
|
|
|
|
|
|
+ ParentId: req.ParentId,
|
|
Code: req.Code,
|
|
Code: req.Code,
|
|
Name: req.Name,
|
|
Name: req.Name,
|
|
Alias: req.Alias,
|
|
Alias: req.Alias,
|
|
@@ -41,10 +40,16 @@ func (s *menuService) Submit(req model.MenuSubmit) *common.Errors {
|
|
IsDeleted: 0,
|
|
IsDeleted: 0,
|
|
}
|
|
}
|
|
if menu.ID == 0 {
|
|
if menu.ID == 0 {
|
|
|
|
+ menu.IsOpen = 1
|
|
err := menu.Save()
|
|
err := menu.Save()
|
|
if err != nil {
|
|
if err != nil {
|
|
return common.FailResponse(err.Error(), nil)
|
|
return common.FailResponse(err.Error(), nil)
|
|
}
|
|
}
|
|
|
|
+ roleMenu := dao.RoleMenu{
|
|
|
|
+ MenuId: menu.ID,
|
|
|
|
+ RoleId: 1,
|
|
|
|
+ }
|
|
|
|
+ roleMenu.Save()
|
|
return common.SuccessResponse(common.Succeeded, nil)
|
|
return common.SuccessResponse(common.Succeeded, nil)
|
|
}
|
|
}
|
|
err := menu.Update()
|
|
err := menu.Update()
|
|
@@ -67,7 +72,7 @@ func (s *menuService) Tree() ([]model.MenuTreeDetail, error) {
|
|
allMenus := s.GetAll()
|
|
allMenus := s.GetAll()
|
|
var rsp []model.MenuTreeDetail
|
|
var rsp []model.MenuTreeDetail
|
|
//上级角色——多个下级角色数组
|
|
//上级角色——多个下级角色数组
|
|
- tmp := make(map[int64][]dao.Menu)
|
|
|
|
|
|
+ tmp := make(map[int][]dao.Menu)
|
|
for _, menu := range allMenus {
|
|
for _, menu := range allMenus {
|
|
childes, isExist := tmp[menu.ParentId]
|
|
childes, isExist := tmp[menu.ParentId]
|
|
if isExist {
|
|
if isExist {
|
|
@@ -87,9 +92,9 @@ func (s *menuService) Tree() ([]model.MenuTreeDetail, error) {
|
|
return rsp, nil
|
|
return rsp, nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *menuService) Routes(roleId int64) ([]model.MenuRouteDetail, error) {
|
|
|
|
|
|
+func (s *menuService) Routes(roleId int) ([]model.MenuRouteDetail, error) {
|
|
allMenus := s.GetAll()
|
|
allMenus := s.GetAll()
|
|
- menuMap := make(map[int64]dao.Menu)
|
|
|
|
|
|
+ menuMap := make(map[int]dao.Menu)
|
|
for _, menu := range allMenus {
|
|
for _, menu := range allMenus {
|
|
menuMap[menu.ID] = menu
|
|
menuMap[menu.ID] = menu
|
|
}
|
|
}
|
|
@@ -97,7 +102,7 @@ func (s *menuService) Routes(roleId int64) ([]model.MenuRouteDetail, error) {
|
|
roleMenus := RoleMenuService.GetMenuByRole(roleId)
|
|
roleMenus := RoleMenuService.GetMenuByRole(roleId)
|
|
var rsp []model.MenuRouteDetail
|
|
var rsp []model.MenuRouteDetail
|
|
//上级角色——多个下级角色数组
|
|
//上级角色——多个下级角色数组
|
|
- tmp := make(map[int64][]dao.Menu)
|
|
|
|
|
|
+ tmp := make(map[int][]dao.Menu)
|
|
for _, roleMenu := range roleMenus {
|
|
for _, roleMenu := range roleMenus {
|
|
if menu, isExist := menuMap[roleMenu.MenuId]; isExist {
|
|
if menu, isExist := menuMap[roleMenu.MenuId]; isExist {
|
|
childes, isExist := tmp[menu.ParentId]
|
|
childes, isExist := tmp[menu.ParentId]
|
|
@@ -125,7 +130,7 @@ func (s *menuService) Routes(roleId int64) ([]model.MenuRouteDetail, error) {
|
|
return rsp, nil
|
|
return rsp, nil
|
|
}
|
|
}
|
|
|
|
|
|
-func menuDfs(result []model.MenuRouteDetail, menus []dao.Menu, tmp map[int64][]dao.Menu) []model.MenuRouteDetail {
|
|
|
|
|
|
+func menuDfs(result []model.MenuRouteDetail, menus []dao.Menu, tmp map[int][]dao.Menu) []model.MenuRouteDetail {
|
|
if len(menus) == 0 {
|
|
if len(menus) == 0 {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
@@ -145,17 +150,17 @@ func menuDfs(result []model.MenuRouteDetail, menus []dao.Menu, tmp map[int64][]d
|
|
return result
|
|
return result
|
|
}
|
|
}
|
|
|
|
|
|
-func menuTreeDfs(result []model.MenuTreeDetail, menus []dao.Menu, tmp map[int64][]dao.Menu) []model.MenuTreeDetail {
|
|
|
|
|
|
+func menuTreeDfs(result []model.MenuTreeDetail, menus []dao.Menu, tmp map[int][]dao.Menu) []model.MenuTreeDetail {
|
|
if len(menus) == 0 {
|
|
if len(menus) == 0 {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
for _, child := range menus {
|
|
for _, child := range menus {
|
|
detail := model.MenuTreeDetail{}
|
|
detail := model.MenuTreeDetail{}
|
|
detail.Title = child.Name
|
|
detail.Title = child.Name
|
|
- detail.ID = strconv.FormatInt(child.ID, 10)
|
|
|
|
- detail.ParentId = strconv.FormatInt(child.ParentId, 10)
|
|
|
|
- detail.Key = strconv.FormatInt(child.ID, 10)
|
|
|
|
- detail.Value = strconv.FormatInt(child.ID, 10)
|
|
|
|
|
|
+ detail.ID = strconv.Itoa(child.ID)
|
|
|
|
+ detail.ParentId = strconv.Itoa(child.ParentId)
|
|
|
|
+ detail.Key = strconv.Itoa(child.ID)
|
|
|
|
+ detail.Value = strconv.Itoa(child.ID)
|
|
childes, isExist := tmp[child.ID]
|
|
childes, isExist := tmp[child.ID]
|
|
if isExist {
|
|
if isExist {
|
|
detail.HasChildren = true
|
|
detail.HasChildren = true
|
|
@@ -169,7 +174,7 @@ func menuTreeDfs(result []model.MenuTreeDetail, menus []dao.Menu, tmp map[int64]
|
|
return result
|
|
return result
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *menuService) LazyList(parentId int64, name, code, alias string) ([]model.MenuLazyListDetail, error) {
|
|
|
|
|
|
+func (s *menuService) LazyList(parentId int, name, code, alias string) ([]model.MenuLazyListDetail, error) {
|
|
menu := &dao.Menu{
|
|
menu := &dao.Menu{
|
|
ParentId: parentId,
|
|
ParentId: parentId,
|
|
Name: name,
|
|
Name: name,
|
|
@@ -180,7 +185,7 @@ func (s *menuService) LazyList(parentId int64, name, code, alias string) ([]mode
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
- var parentIds []int64
|
|
|
|
|
|
+ var parentIds []int
|
|
for _, m := range menus {
|
|
for _, m := range menus {
|
|
parentIds = append(parentIds, m.ID)
|
|
parentIds = append(parentIds, m.ID)
|
|
}
|
|
}
|
|
@@ -200,7 +205,7 @@ func (s *menuService) LazyList(parentId int64, name, code, alias string) ([]mode
|
|
}
|
|
}
|
|
|
|
|
|
func (s *menuService) GetTree() ([]model.MenuRouteDetail, error) {
|
|
func (s *menuService) GetTree() ([]model.MenuRouteDetail, error) {
|
|
- menuDao := dao.Menu{ParentId: int64(0)}
|
|
|
|
|
|
+ menuDao := dao.Menu{ParentId: 0}
|
|
var menuDetails []model.MenuRouteDetail
|
|
var menuDetails []model.MenuRouteDetail
|
|
var temp model.MenuRouteDetail
|
|
var temp model.MenuRouteDetail
|
|
|
|
|