作者 yangfu

菜单调整

... ... @@ -25,6 +25,8 @@ type CreateMenuCommand struct {
Desc string `json:"desc,omitempty"`
// 菜单是否公开状态,[0:隐藏],[1:显示],默认显示
IsPublish int `json:"isPublish"`
// 启用状态(启用:1 禁用:2),默认启用
EnableStatus int `json:"enableStatus"`
}
func (createMenuCommand *CreateMenuCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -27,6 +27,8 @@ type UpdateMenuCommand struct {
Desc string `json:"desc,omitempty"`
// 菜单是否公开状态,[0:隐藏],[1:显示],默认显示
IsPublish int `json:"isPublish,omitempty"`
// 启用状态(启用:1 禁用:2),默认启用
EnableStatus int `json:"enableStatus"`
}
func (updateMenuCommand *UpdateMenuCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -19,10 +19,17 @@ type ListMenuQuery struct {
Offset int `json:"offset"`
// 查询限制
Limit int `json:"limit" valid:"Required"`
// web分页
PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize" valid:"Required"`
}
func (listMenuQuery *ListMenuQuery) Valid(validation *validation.Validation) {
if listMenuQuery.PageSize > 0 {
listMenuQuery.Limit = listMenuQuery.PageSize
listMenuQuery.Offset = (listMenuQuery.PageNumber - 1) * listMenuQuery.PageSize
}
}
func (listMenuQuery *ListMenuQuery) ValidateQuery() error {
... ...
... ... @@ -32,15 +32,16 @@ func (menuService *MenuService) CreateMenu(createMenuCommand *command.CreateMenu
transactionContext.RollbackTransaction()
}()
newMenu := &domain.Menu{
ParentId: createMenuCommand.ParentId,
MenuName: createMenuCommand.MenuName,
Code: createMenuCommand.Code,
AccessCode: createMenuCommand.AccessCode,
MenuType: createMenuCommand.MenuType,
Icon: createMenuCommand.Icon,
Sort: createMenuCommand.Sort,
Remark: createMenuCommand.Desc,
IsPublish: createMenuCommand.IsPublish,
ParentId: createMenuCommand.ParentId,
MenuName: createMenuCommand.MenuName,
Code: createMenuCommand.Code,
AccessCode: createMenuCommand.AccessCode,
MenuType: createMenuCommand.MenuType,
Icon: createMenuCommand.Icon,
Sort: createMenuCommand.Sort,
Remark: createMenuCommand.Desc,
IsPublish: createMenuCommand.IsPublish,
EnableStatus: createMenuCommand.EnableStatus,
}
var menuRepository domain.MenuRepository
if value, err := factory.CreateMenuRepository(map[string]interface{}{
... ...
... ... @@ -19,6 +19,18 @@ var (
ErrorMenuType = errors.New(fmt.Sprintf("菜单类型有误 可选值 %v、%v、%v", Catalog, Menu_, Button))
)
// 菜单启用状态 结合用户菜单权限
const (
MenuStatusEnable = 1 // 菜单启用
MenuStatusDisable = 2 // 菜单禁用
)
// 菜单公开状态
const (
MenuPublic = 1 // 菜单公开
MenuPrivate = 2 // 菜单未公开
)
// 菜单类型
type MenuType string
... ... @@ -46,9 +58,9 @@ type Menu struct {
Category string `json:"category"`
// 路径节点路径("0,11,12,")
ParentPath string `json:"parentPath"`
// 菜单是否公开状态,[0:隐藏],[1:显示],默认显示
// 菜单是否公开状态,[1:显示],[2:隐藏],默认显示
IsPublish int `json:"isPublish"`
// 启用状态(启用:1 禁用:0),默认启用
// 启用状态(启用:1 禁用:2),默认启用
EnableStatus int `json:"enableStatus"`
}
... ...
package controllers
import (
"github.com/beego/beego/v2/server/web/context"
"github.com/linmadan/egglib-go/web/beego"
"github.com/linmadan/egglib-go/web/beego/utils"
)
func ResponseGrid(c beego.BaseController, data interface{}, err error) {
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(c.Ctx, err)
} else {
response = ResponseGridData(c.Ctx, data)
}
c.Data["json"] = response
c.ServeJSON()
}
func ResponseGridData(ctx *context.Context, data interface{}) utils.JsonResponse {
jsonResponse := utils.JsonResponse{}
jsonResponse["code"] = 0
jsonResponse["msg"] = "ok"
jsonResponse["data"] = map[string]interface{}{"grid": data}
ctx.Input.SetData("outputData", jsonResponse)
return jsonResponse
}
... ...
... ... @@ -62,3 +62,13 @@ func (controller *MenuController) ListMenu() {
data, err := menuService.ListMenu(listMenuQuery)
controller.Response(data, err)
}
func (controller *MenuController) SearchMenu() {
menuService := service.NewMenuService(nil)
listMenuQuery := &query.ListMenuQuery{}
controller.Unmarshal(listMenuQuery)
listMenuQuery.Offset = 0
listMenuQuery.Limit = 0
data, err := menuService.ListMenu(listMenuQuery)
controller.Response(data, err)
}
... ...
... ... @@ -10,5 +10,13 @@ func init() {
web.Router("/menus/:menuId", &controllers.MenuController{}, "Put:UpdateMenu")
web.Router("/menus/:menuId", &controllers.MenuController{}, "Get:GetMenu")
web.Router("/menus/:menuId", &controllers.MenuController{}, "Delete:RemoveMenu")
web.Router("/menus/", &controllers.MenuController{}, "Get:ListMenu")
web.Router("/menus/search", &controllers.MenuController{}, "Get:ListMenu")
web.Router("/menus/search", &controllers.MenuController{}, "Post:SearchMenu")
web.Router("/v1/web/menus/", &controllers.MenuController{}, "Post:CreateMenu")
web.Router("/v1/web/menus/:menuId", &controllers.MenuController{}, "Put:UpdateMenu")
web.Router("/v1/web/menus/:menuId", &controllers.MenuController{}, "Get:GetMenu")
web.Router("/v1/web/menus/:menuId", &controllers.MenuController{}, "Delete:RemoveMenu")
web.Router("/v1/web/menus/search", &controllers.MenuController{}, "Get:ListMenu")
web.Router("/v1/web/menus/search", &controllers.MenuController{}, "Post:SearchMenu")
}
... ...
... ... @@ -24,7 +24,7 @@ var _ = Describe("返回菜单服务列表", func() {
It("返回系统菜单数据列表", func() {
return
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/menus/").
httpExpect.GET("/menus/search").
WithQuery("offset", 0).
WithQuery("limit", 20).
Expect().
... ...