新增获取全部菜单列表
This commit is contained in:
parent
db36b2f32b
commit
af1a0898c0
@ -3,12 +3,25 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"hospital-admin-api/api/responses"
|
"hospital-admin-api/api/responses"
|
||||||
|
"hospital-admin-api/api/service"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Menu struct{}
|
type Menu struct{}
|
||||||
|
|
||||||
// GetMenuList 获取菜单列表
|
// GetMenuList 获取菜单列表
|
||||||
func (r *Menu) GetMenuList(c *gin.Context) {
|
func (r *Menu) GetMenuList(c *gin.Context) {
|
||||||
responses.Ok(c)
|
MenuService := service.MenuService{}
|
||||||
|
MenuList, err := MenuService.GetMenuList()
|
||||||
|
if err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(MenuList) == 0 {
|
||||||
|
responses.FailWithMessage("请联系管理人员设置菜单", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
responses.OkWithData(MenuList, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
17
api/responses/menuResponse/menu.go
Normal file
17
api/responses/menuResponse/menu.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package menuResponse
|
||||||
|
|
||||||
|
// GetMenuList 角色详情
|
||||||
|
type GetMenuList struct {
|
||||||
|
MenuId int64 `json:"menu_id"`
|
||||||
|
MenuName string `json:"menu_name"` // 菜单名称
|
||||||
|
MenuTitle string `json:"menu_title"` // 菜单名称
|
||||||
|
ParentId int64 `json:"parent_id"` // 父菜单ID(0表示一级)
|
||||||
|
MenuStatus int `json:"menu_status"` // 菜单状态(0:隐藏 1:正常)此优先级最高
|
||||||
|
MenuType int `json:"menu_type"` // 菜单类型(1:模块 2:菜单 3:按钮)
|
||||||
|
Permission string `json:"permission"` // 标识
|
||||||
|
OrderNum int `json:"order_num"` // 显示顺序
|
||||||
|
Icon string `json:"icon"` // 图标地址
|
||||||
|
Path string `json:"path"` // 页面地址(#表示当前页)
|
||||||
|
Component string `json:"component"` // 组件名称
|
||||||
|
Children []*GetMenuList `json:"children"` // 下级页面
|
||||||
|
}
|
||||||
@ -1,15 +0,0 @@
|
|||||||
package menuResponse
|
|
||||||
|
|
||||||
// GetMenuList 角色详情
|
|
||||||
type GetMenuList struct {
|
|
||||||
MenuId int64 `json:"menu_id"`
|
|
||||||
MenuName string `json:"menu_name"` // 菜单名称
|
|
||||||
MenuTitle string `json:"menu_title"` // 菜单名称
|
|
||||||
ParentId int64 `json:"parent_id"` // 父菜单ID(0表示一级)
|
|
||||||
MenuStatus int `json:"menu_status"` // 菜单状态(0:隐藏 1:正常)此优先级最高
|
|
||||||
MenuType int `json:"menu_type"` // 菜单类型(1:模块 2:菜单 3:按钮)
|
|
||||||
Permission string `json:"permission"` // 标识
|
|
||||||
OrderNum int `json:"order_num"` // 显示顺序
|
|
||||||
Icon string `json:"icon"` // 图标地址
|
|
||||||
Path string `json:"path"` // 页面地址(#表示当前页)
|
|
||||||
}
|
|
||||||
@ -1,7 +1,50 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"hospital-admin-api/api/dao"
|
||||||
|
"hospital-admin-api/api/responses/menuResponse"
|
||||||
|
)
|
||||||
|
|
||||||
type MenuService struct{}
|
type MenuService struct{}
|
||||||
|
|
||||||
// func (r *MenuService) GetMenuList() ([]*roleResponse.RoleMenuList, error) {
|
// GetMenuList 获取菜单列表
|
||||||
//
|
func (r *MenuService) GetMenuList() ([]*menuResponse.GetMenuList, error) {
|
||||||
// }
|
// 获取全部菜单
|
||||||
|
AdminMenuDao := dao.AdminMenuDao{}
|
||||||
|
adminMenu, _ := AdminMenuDao.GetAdminMenuListSortOrderNum()
|
||||||
|
if adminMenu == nil {
|
||||||
|
return []*menuResponse.GetMenuList{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
menuMap := make(map[int64]*menuResponse.GetMenuList)
|
||||||
|
var menuTree []*menuResponse.GetMenuList
|
||||||
|
|
||||||
|
for _, menu := range adminMenu {
|
||||||
|
node := &menuResponse.GetMenuList{
|
||||||
|
MenuId: menu.MenuId,
|
||||||
|
MenuName: menu.MenuName,
|
||||||
|
MenuTitle: menu.MenuTitle,
|
||||||
|
ParentId: menu.ParentId,
|
||||||
|
MenuStatus: menu.MenuStatus,
|
||||||
|
MenuType: menu.MenuType,
|
||||||
|
Permission: menu.Permission,
|
||||||
|
OrderNum: menu.OrderNum,
|
||||||
|
Icon: menu.Icon,
|
||||||
|
Path: menu.Path,
|
||||||
|
Component: menu.Component,
|
||||||
|
Children: nil,
|
||||||
|
}
|
||||||
|
menuMap[menu.MenuId] = node
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建菜单树
|
||||||
|
for _, menu := range adminMenu {
|
||||||
|
if menu.ParentId == 0 {
|
||||||
|
menuTree = append(menuTree, menuMap[menu.MenuId])
|
||||||
|
} else if parent, ok := menuMap[menu.ParentId]; ok {
|
||||||
|
parent.Children = append(parent.Children, menuMap[menu.MenuId])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return menuTree, nil
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user