From db36b2f32b8e665f7063ce9d50b5a152d8052c42 Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Tue, 13 Jun 2023 14:12:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8F=9C=E5=8D=95=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E4=BD=93=E5=AD=97=E6=AE=B5=EF=BC=8C=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E4=BA=86=E4=B8=A4=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controller/base.go | 1 + api/controller/menu.go | 14 +++++++++++++ api/model/adminMenu.go | 2 ++ api/responses/menuResponse/menuResponse.go | 15 ++++++++++++++ api/responses/roleResponse/roleResponse.go | 2 ++ api/router/router.go | 24 ++++++++++++++-------- api/service/menu.go | 7 +++++++ api/service/role.go | 2 ++ 8 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 api/controller/menu.go create mode 100644 api/responses/menuResponse/menuResponse.go create mode 100644 api/service/menu.go diff --git a/api/controller/base.go b/api/controller/base.go index b6caa9d..07d595d 100644 --- a/api/controller/base.go +++ b/api/controller/base.go @@ -4,4 +4,5 @@ package controller type Api struct { Basic // 基础数据 Role // 角色数据 + Menu // 菜单数据 } diff --git a/api/controller/menu.go b/api/controller/menu.go new file mode 100644 index 0000000..199ea17 --- /dev/null +++ b/api/controller/menu.go @@ -0,0 +1,14 @@ +package controller + +import ( + "github.com/gin-gonic/gin" + "hospital-admin-api/api/responses" +) + +type Menu struct{} + +// GetMenuList 获取菜单列表 +func (r *Menu) GetMenuList(c *gin.Context) { + responses.Ok(c) + return +} diff --git a/api/model/adminMenu.go b/api/model/adminMenu.go index 5afa01a..b966d83 100644 --- a/api/model/adminMenu.go +++ b/api/model/adminMenu.go @@ -5,6 +5,7 @@ type AdminMenu struct { Model MenuId int64 `gorm:"column:menu_id;type:bigint(19);primary_key;comment:主键id" json:"menu_id"` MenuName string `gorm:"column:menu_name;type:varchar(30);comment:菜单名称" json:"menu_name"` + MenuTitle string `gorm:"column:title;menu_title:varchar(30);comment:菜单名称" json:"menu_title"` ParentId int64 `gorm:"column:parent_id;type:int(10);default:0;comment:父菜单ID(0表示一级)" json:"parent_id"` MenuStatus int `gorm:"column:menu_status;type:tinyint(1);default:1;comment:菜单状态(0:隐藏 1:正常)此优先级最高" json:"menu_status"` MenuType int `gorm:"column:menu_type;type:tinyint(1);comment:菜单类型(1:模块 2:菜单 3:按钮)" json:"menu_type"` @@ -12,6 +13,7 @@ type AdminMenu struct { OrderNum int `gorm:"column:order_num;type:int(4);default:0;comment:显示顺序" json:"order_num"` Icon string `gorm:"column:icon;type:varchar(255);comment:图标地址" json:"icon"` Path string `gorm:"column:path;type:varchar(255);comment:页面地址(#表示当前页)" json:"path"` + Component string `gorm:"column:component;type:varchar(255);comment:组件名称" json:"component"` } func (m *AdminMenu) TableName() string { diff --git a/api/responses/menuResponse/menuResponse.go b/api/responses/menuResponse/menuResponse.go new file mode 100644 index 0000000..18345f4 --- /dev/null +++ b/api/responses/menuResponse/menuResponse.go @@ -0,0 +1,15 @@ +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"` // 页面地址(#表示当前页) +} diff --git a/api/responses/roleResponse/roleResponse.go b/api/responses/roleResponse/roleResponse.go index b763675..6fb21e8 100644 --- a/api/responses/roleResponse/roleResponse.go +++ b/api/responses/roleResponse/roleResponse.go @@ -4,6 +4,7 @@ package roleResponse type RoleMenuList struct { MenuId int64 `json:"menu_id"` // 主键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:按钮) @@ -11,6 +12,7 @@ type RoleMenuList struct { OrderNum int `json:"order_num"` // 显示顺序 Icon string `json:"icon"` // 图标地址 Path string `json:"path"` // 页面地址(#表示当前页) + Component string `json:"component"` // 组件名称 Children []*RoleMenuList `json:"children"` // 下级页面 } diff --git a/api/router/router.go b/api/router/router.go index b847055..d044db0 100644 --- a/api/router/router.go +++ b/api/router/router.go @@ -55,13 +55,13 @@ func Init() *gin.Engine { // publicRouter 公开路由-不验证权限 func publicRouter(r *gin.Engine, api controller.Api) { adminGroup := r.Group("/admin") - baseGroup := adminGroup.Group("/basic") + basicGroup := adminGroup.Group("/basic") { // 验证码 - baseGroup.GET("captcha", api.Basic.GetCaptcha) + basicGroup.GET("captcha", api.Basic.GetCaptcha) // 登陆 - baseGroup.POST("login", api.Basic.Login) + basicGroup.POST("login", api.Basic.Login) } } @@ -70,22 +70,28 @@ func privateRouter(r *gin.Engine, api controller.Api) { adminGroup := r.Group("/admin") // 角色 - base1Group := adminGroup.Group("/role") + roleGroup := adminGroup.Group("/role") { // 获取登陆角色菜单列表 - base1Group.GET("menu", api.Role.GetRoleMenuList) + roleGroup.GET("menu", api.Role.GetRoleMenuList) // 搜索角色列表 - base1Group.GET("list", api.Role.GetRoleList) + roleGroup.GET("", api.Role.GetRoleList) // 角色禁用/启用 - base1Group.PUT("status/:id", api.Role.PutRoleStatus) + roleGroup.PUT("status/:id", api.Role.PutRoleStatus) // 角色新增 - base1Group.POST("", api.Role.AddRole) + roleGroup.POST("", api.Role.AddRole) // 角色详情 - base1Group.GET("/:role_id", api.Role.GetRole) + roleGroup.GET("/:role_id", api.Role.GetRole) } + // 菜单 + menuGroup := adminGroup.Group("/menu") + { + // 获取菜单列表 + menuGroup.GET("", api.Menu.GetMenuList) + } } diff --git a/api/service/menu.go b/api/service/menu.go new file mode 100644 index 0000000..b1c2b6d --- /dev/null +++ b/api/service/menu.go @@ -0,0 +1,7 @@ +package service + +type MenuService struct{} + +// func (r *MenuService) GetMenuList() ([]*roleResponse.RoleMenuList, error) { +// +// } diff --git a/api/service/role.go b/api/service/role.go index dfa8c31..f69ef59 100644 --- a/api/service/role.go +++ b/api/service/role.go @@ -51,6 +51,7 @@ func buildMenuTree(menuIds []int64, menuData []*model.AdminMenu) []*roleResponse node := &roleResponse.RoleMenuList{ MenuId: menu.MenuId, MenuName: menu.MenuName, + MenuTitle: menu.MenuTitle, ParentId: menu.ParentId, MenuStatus: menu.MenuStatus, MenuType: menu.MenuType, @@ -58,6 +59,7 @@ func buildMenuTree(menuIds []int64, menuData []*model.AdminMenu) []*roleResponse OrderNum: menu.OrderNum, Icon: menu.Icon, Path: menu.Path, + Component: menu.Component, Children: nil, }