Commit 0c9d92ab authored by 黄智's avatar 黄智

菜单管理模块

parent 2d7aa2c2
package entity
import "time"
type DictionaryBase struct {
Id string `json:"id" xorm:"pk autoincr" ` //id
Class int `json:"class"` //菜单分组id
Name string `json:"name" ` //字典名称
ParentId int `json:"parent_id" ` //父级id
Status int32 `json:"status" ` //状态 1-启用 2-禁用
IsDelete int32 `json:"is_delete" ` //是否删除 1-是 0-否
DictType int32 `json:"dict_type" ` //字典类型(0-用户 1-系统)
Description string `json:"description" ` //描述
CreatedBy int `json:"created_by" ` //创建者
CreatedAt time.Time `json:"created_at" xorm:"created" ` //创建时间
UpdatedBy int `json:"updated_by" ` //更新者
UpdatedAt time.Time `json:"updated_at" xorm:"updated" ` //更新时间
Sort int64 `json:"sort" ` //排序字段 降序排列
}
package entity
import "time"
type SystemMenu struct {
Id int32 `json:"id" xorm:"pk autoincr" ` //id
Level int `json:"level" xorm:"level"` //菜单等级
Sort int `json:"sort" xorm:"sort"` //菜单排序
MenuName string `json:"menu_name" xorm:"menu_name"` //菜单名称
MenuType int `json:"menu_type" xorm:"menu_type"` //菜单类型(0目录1菜单2子页面)
DictGroupId string `json:"dict_group_id" xorm:"dict_group_id"` //字典分组id
State int `json:"state" xorm:"state"` //状态0禁用1启用
MenuUrl string `json:"menu_url" xorm:"menu_url"` //菜单路径
MenuLogo string `json:"menu_logo" xorm:"menu_logo"` //菜单图标
CreatedBy int `json:"created_by" ` //创建者
CreatedTime time.Time `json:"created_time" xorm:"created" ` //创建时间
UpdatedBy int `json:"updated_by" ` //更新者
UpdatedTime time.Time `json:"updated_time" xorm:"updated" ` //更新时间
IsDeleted int `json:"is_deleted" xorm:"is_deleted"` //是否删除
MenuId string `json:"menu_id" xorm:"menu_id"` //菜单id
PMenuId string `json:"p_menu_id" xorm:"p_menu_id"` //上级菜单id
Source string `json:"source"`
NewWindow int `json:"new_window"`
Remark string `json:"remark"`
}
package request
type SystemMenuReq struct {
MenuName string `json:"menu_name" vd:"len($)>0;msg:'请输入菜单名称'"`
Level int `json:"level"`
Sort int `json:"sort"`
MenuType int `json:"menu_type"`
DictGroupId string `json:"dict_group_id"`
State int `json:"state"`
MenuUrl string `json:"menu_url"`
MenuLogo string `json:"menu_logo"`
PMenuId string `json:"p_menu_id"`
Source string `json:"source"`
NewWindow int `json:"new_window"`
Remark string `json:"remark"`
}
// 组织排序参数
type MenuSortInput struct {
Id int64 `json:"id" xorm:"pk autoincr"` //id
Sort int `json:"sort"` //排序
}
package response
import (
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
)
// 系统菜单表
type SystemMenuTree struct {
Id int32 `json:"id" xorm:"pk autoincr" ` //id
Level int `json:"level" xorm:"level"` //菜单等级
Sort int `json:"sort" xorm:"sort"` //菜单排序
MenuName string `json:"menu_name" xorm:"menu_name"` //菜单名称
MenuType int `json:"menu_type" xorm:"menu_type"` //菜单类型(0目录1菜单2子页面)
DictGroupId string `json:"dict_group_id" xorm:"dict_group_id"` //字典分组id
State int `json:"state" xorm:"state"` //状态0禁用1启用
MenuUrl string `json:"menu_url" xorm:"menu_url"` //菜单路径
MenuLogo string `json:"menu_logo" xorm:"menu_logo"` //菜单图标
CreatedTime jsontime.Time `json:"created_time" xorm:"created"` //创建时间
UpdatedTime jsontime.Time `json:"updated_time" xorm:"updated"` //更新时间
CreatedBy string `json:"created_by"` //创建者
UpdatedBy string `json:"updated_by"` //更新者
MenuId string `json:"menu_id" xorm:"menu_id"` //菜单id
PMenuId string `json:"p_menu_id" xorm:"p_menu_id"` //上级菜单id
Source string `json:"source" xorm:"source"` //源
Child []SystemMenuTree `xorm:"-"`
}
// 系统菜单表
type SystemMenuTreePer struct {
Id int32 `json:"id" xorm:"pk autoincr" ` //id
Level int `json:"level" xorm:"level"` //菜单等级
Sort int `json:"sort" xorm:"sort"` //菜单排序
MenuName string `json:"menuName" xorm:"menu_name"` //菜单名称
DictGroupId string `json:"dict_group_id" xorm:"dict_group_id"` //字典分类id
MenuType int `json:"menuType" xorm:"menu_type"` //菜单类型(0目录1菜单2子页面)
Path string `json:"path" xorm:"menu_url"` //菜单路径
ParentPath string `json:"parentPath" xorm:"-"`
Icon string `json:"icon" xorm:"menu_logo"` //菜单图标
MenuId string `json:"menu_id" xorm:"menu_id"` //菜单id
PMenuId string `json:"p_menu_id" xorm:"p_menu_id"` //上级菜单id
Children []SystemMenuTreePer `json:"children" xorm:"-"`
}
package controller
import (
"errors"
vd "github.com/bytedance/go-tagexpr/validator"
"github.com/gin-gonic/gin"
"github.com/spf13/cast"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/service"
)
func AddSystemMenu(c *gin.Context) {
input := request.SystemMenuReq{}
if err := c.ShouldBindJSON(&input); err != nil {
SendJsonResponse(c, resp.InvalidParam.ErrorDetail(err), nil)
return
}
if input.PMenuId != "" && input.MenuType == 0 && input.DictGroupId == "" {
SendJsonResponse(c, resp.InvalidParam.ErrorDetail(errors.New("请选择分组")), nil)
return
}
if input.PMenuId != "" && input.MenuUrl == "" {
SendJsonResponse(c, resp.InvalidParam.ErrorDetail(errors.New("请填写菜单路径")), nil)
return
}
sm := service.SystemMenu{User: header.GetUser(c)}
data, err := sm.AddSystemMenu(input)
if err != nil {
SendJsonResponse(c, err, nil)
return
}
SendJsonResponse(c, resp.OK, data)
}
func DeleteMenu(c *gin.Context) {
sm := service.SystemMenu{}
if err := sm.DeleteMenu(cast.ToInt64(c.Param("id"))); err != nil {
SendJsonResponse(c, err, nil)
return
}
SendJsonResponse(c, resp.OK, nil)
}
func MenuSort(c *gin.Context) {
var input []request.MenuSortInput
if err := c.ShouldBindJSON(&input); err != nil {
SendJsonResponse(c, resp.InvalidParam.ErrorDetail(err), nil)
return
}
sm := service.SystemMenu{User: header.GetUser(c)}
if err := sm.SortMenu(input); err != nil {
SendJsonResponse(c, err, nil)
return
}
SendJsonResponse(c, resp.OK, nil)
}
// 更新菜单
func UpdateMenu(c *gin.Context) {
var input request.SystemMenuReq
if err := c.ShouldBindJSON(&input); err != nil {
SendJsonResponse(c, resp.InvalidParam.ErrorDetail(err), nil)
return
}
//参数检测
if err := vd.Validate(input); err != nil {
SendJsonResponse(c, resp.InvalidParam.ErrorDetail(err), "")
return
}
sm := service.SystemMenu{User: header.GetUser(c)}
if err := sm.UpdateMenu(cast.ToInt64(c.Param("id")), input); err != nil {
SendJsonResponse(c, err, nil)
return
}
SendJsonResponse(c, resp.OK, nil)
}
func GetMenuTree(c *gin.Context) {
sm := service.SystemMenu{}
result, err := sm.GetMenuTree()
if err != nil {
SendJsonResponse(c, err, nil)
return
}
SendJsonResponse(c, resp.OK, result)
}
func GetGroupDict(c *gin.Context) {
sm := service.SystemMenu{}
result, err := sm.GetGroupDict()
if err != nil {
SendJsonResponse(c, err, nil)
return
}
SendJsonResponse(c, resp.OK, result)
}
func GetSystemTree(c *gin.Context) {
search := c.Query("search")
sm := service.SystemMenu{User: header.GetUser(c)}
result, err := sm.GetSystemTree(search)
if err != nil {
SendJsonResponse(c, err, nil)
return
}
SendJsonResponse(c, resp.OK, result)
}
...@@ -38,6 +38,8 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) { ...@@ -38,6 +38,8 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) {
InitOrganizationRouter(r) InitOrganizationRouter(r)
// 初始化用户相关路由 // 初始化用户相关路由
InitSystemUserRouter(r) InitSystemUserRouter(r)
// 初始化菜单相关路由(r)
InitSystemMenuRouter(r)
// 初始化指标配置路由 // 初始化指标配置路由
InitMetricConfigRouter(r) InitMetricConfigRouter(r)
// 初始化prometheus路由 // 初始化prometheus路由
......
package router
import (
"fmt"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/controller"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
"github.com/gin-gonic/gin"
)
func InitSystemMenuRouter(e *gin.Engine) {
base := e.Group(fmt.Sprintf("%s/menu", conf.Options.Prefix), header.SetContext)
{
base.GET("/group/dict", controller.GetGroupDict) //获取字典分组
base.POST("/add", controller.AddSystemMenu) //新增菜单
base.PUT("/:id", controller.UpdateMenu) //菜单更新
base.GET("/tree", controller.GetMenuTree) //获取菜单树形结构
base.PUT("/sort", controller.MenuSort) //菜单排序
base.DELETE("/:id", controller.DeleteMenu) //删除菜单
base.GET("/user/tree", controller.GetSystemTree) //获取当前系统用户树
}
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment