作者 yangfu

菜单调整

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