Skip to content

Commit

Permalink
fix(admin): fix routes and menus
Browse files Browse the repository at this point in the history
fix(admin): fix routes and menus
  • Loading branch information
jaronnie committed Nov 28, 2024
1 parent fcbd708 commit 4afd9af
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 116 deletions.
43 changes: 23 additions & 20 deletions server/desc/api/manage/menu.api
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,29 @@ type ListRequest {
}

type SystemMenu {
id uint64 `json:"id"`
parentId uint64 `json:"parentId"`
menuType string `json:"menuType"`
menuName string `json:"menuName"`
routeName string `json:"routeName"`
routePath string `json:"routePath"`
component string `json:"component"`
icon string `json:"icon"`
iconType string `json:"iconType"`
buttonCode string `json:"buttonCode"`
permissions []Permission `json:"permissions"`
order uint64 `json:"order"`
i18nKey string `json:"i18nKey"`
status string `json:"status"`
keepAlive bool `json:"keepAlive"`
constant bool `json:"constant"`
hideInMenu bool `json:"hideInMenu"`
multiTab bool `json:"mutiTab"`
activeMenu string `json:"activeMenu"`
children []SystemMenu `json:"children"`
id uint64 `json:"id"`
activeMenu string `json:"activeMenu,optional"`
menuType string `json:"menuType"`
menuName string `json:"menuName"`
routeName string `json:"routeName"`
routePath string `json:"routePath"`
component string `json:"component"`
icon string `json:"icon"`
iconType string `json:"iconType"`
parentId uint64 `json:"parentId"`
status string `json:"status"`
keepAlive bool `json:"keepAlive"`
constant bool `json:"constant"`
order uint64 `json:"order"`
hideInMenu bool `json:"hideInMenu"`
href string `json:"href,optional"`
multiTab bool `json:"multiTab,optional"`
fixedIndexInTab bool `json:"fixedIndexInTab,optional"`
query []Query `json:"query,optional"`
buttonCode string `json:"buttonCode,optional"`
permissions []Permission `json:"permissions,optional"`
i18nKey string `json:"i18nKey,optional"`
children []SystemMenu `json:"children"`
}

type ListResponse {
Expand Down
26 changes: 17 additions & 9 deletions server/desc/api/route/route.api
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,23 @@ type Route {
}

type RouteMeta {
title string `json:"title"`
i18nKey string `json:"i18nKey"`
icon string `json:"icon"`
order int `json:"order"`
hideInMenu bool `json:"hideInMenu"`
activeMenu string `json:"activeMenu"`
multiTab bool `json:"multiTab"`
keepAlive bool `json:"keepAlive"`
constant bool `json:"constant"`
title string `json:"title"`
i18nKey string `json:"i18nKey"`
icon string `json:"icon"`
order int `json:"order"`
hideInMenu bool `json:"hideInMenu"`
activeMenu string `json:"activeMenu"`
multiTab bool `json:"multiTab"`
fixedIndexInTab int `json:"fixedIndexInTab"`
keepAlive bool `json:"keepAlive"`
constant bool `json:"constant"`
href string `json:"href"`
query []Query `json:"query"`
}

type Query {
key string `json:"key"`
value string `json:"value"`
}

type GetConstantRoutesRequest {}
Expand Down
58 changes: 33 additions & 25 deletions server/desc/swagger/manage-menu.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,8 @@
"type": "integer",
"format": "int64"
},
"parentId": {
"type": "integer",
"format": "int64"
"activeMenu": {
"type": "string"
},
"menuType": {
"type": "string"
Expand All @@ -596,22 +595,10 @@
"iconType": {
"type": "string"
},
"buttonCode": {
"type": "string"
},
"permissions": {
"type": "array",
"items": {
"$ref": "#/definitions/Permission"
}
},
"order": {
"parentId": {
"type": "integer",
"format": "int64"
},
"i18nKey": {
"type": "string"
},
"status": {
"type": "string"
},
Expand All @@ -623,15 +610,41 @@
"type": "boolean",
"format": "boolean"
},
"order": {
"type": "integer",
"format": "int64"
},
"hideInMenu": {
"type": "boolean",
"format": "boolean"
},
"mutiTab": {
"href": {
"type": "string"
},
"multiTab": {
"type": "boolean",
"format": "boolean"
},
"activeMenu": {
"fixedIndexInTab": {
"type": "boolean",
"format": "boolean"
},
"query": {
"type": "array",
"items": {
"$ref": "#/definitions/Query"
}
},
"buttonCode": {
"type": "string"
},
"permissions": {
"type": "array",
"items": {
"$ref": "#/definitions/Permission"
}
},
"i18nKey": {
"type": "string"
},
"children": {
Expand All @@ -644,24 +657,19 @@
"title": "SystemMenu",
"required": [
"id",
"parentId",
"menuType",
"menuName",
"routeName",
"routePath",
"component",
"icon",
"iconType",
"buttonCode",
"permissions",
"order",
"i18nKey",
"parentId",
"status",
"keepAlive",
"constant",
"order",
"hideInMenu",
"mutiTab",
"activeMenu",
"children"
]
},
Expand Down
34 changes: 33 additions & 1 deletion server/desc/swagger/route.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@
"type": "object",
"title": "IsRouteExistRequest"
},
"Query": {
"type": "object",
"properties": {
"key": {
"type": "string"
},
"value": {
"type": "string"
}
},
"title": "Query",
"required": [
"key",
"value"
]
},
"Route": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -213,13 +229,26 @@
"type": "boolean",
"format": "boolean"
},
"fixedIndexInTab": {
"type": "integer",
"format": "int32"
},
"keepAlive": {
"type": "boolean",
"format": "boolean"
},
"constant": {
"type": "boolean",
"format": "boolean"
},
"href": {
"type": "string"
},
"query": {
"type": "array",
"items": {
"$ref": "#/definitions/Query"
}
}
},
"title": "RouteMeta",
Expand All @@ -231,8 +260,11 @@
"hideInMenu",
"activeMenu",
"multiTab",
"fixedIndexInTab",
"keepAlive",
"constant"
"constant",
"href",
"query"
]
},
"boolean": {
Expand Down
50 changes: 29 additions & 21 deletions server/internal/logic/manage/menu/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"sort"

"github.com/jzero-io/jzero-contrib/condition"
"github.com/spf13/cast"
"github.com/zeromicro/go-zero/core/logx"

Expand All @@ -30,7 +31,9 @@ func NewList(ctx context.Context, svcCtx *svc.ServiceContext) *List {
func (l *List) List(req *types.ListRequest) (resp *types.ListResponse, err error) {
resp = &types.ListResponse{}

list, err := l.svcCtx.Model.ManageMenu.FindByCondition(l.ctx, nil)
list, err := l.svcCtx.Model.ManageMenu.FindByCondition(l.ctx, nil, condition.NewChain().
Equal("constant", false).
Build()...)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -62,28 +65,33 @@ func convert(list []*manage_menu.ManageMenu) []*types.SystemMenu {
for _, item := range list {
var menu types.SystemMenu
var permissions []types.Permission
var query []types.Query
Unmarshal(item.Permissions.String, &permissions)
Unmarshal(item.Query.String, &query)
menu = types.SystemMenu{
Id: item.Id,
ParentId: uint64(item.ParentId),
MenuType: item.MenuType,
MenuName: item.MenuName,
RouteName: item.RouteName,
RoutePath: item.RoutePath,
Component: item.Component,
Icon: item.Icon,
IconType: item.IconType,
Order: uint64(item.Order),
I18nKey: item.I18nKey,
Status: item.Status,
Constant: cast.ToBool(item.Constant),
HideInMenu: cast.ToBool(item.HideInMenu),
MultiTab: cast.ToBool(item.MultiTab),
KeepAlive: cast.ToBool(item.KeepAlive),
ActiveMenu: item.ActiveMenu.String,
ButtonCode: item.ButtonCode.String,
Permissions: permissions,
Children: nil,
Id: item.Id,
ActiveMenu: item.ActiveMenu.String,
MenuType: item.MenuType,
MenuName: item.MenuName,
RouteName: item.RouteName,
RoutePath: item.RoutePath,
Component: item.Component,
Icon: item.Icon,
IconType: item.IconType,
ParentId: uint64(item.ParentId),
Status: item.Status,
KeepAlive: cast.ToBool(item.KeepAlive),
Constant: cast.ToBool(item.Constant),
Order: uint64(item.Order),
HideInMenu: cast.ToBool(item.HideInMenu),
Href: item.Href.String,
MultiTab: cast.ToBool(item.MultiTab),
FixedIndexInTab: cast.ToBool(item.FixedIndexInTab),
Query: query,
ButtonCode: item.ButtonCode.String,
Permissions: permissions,
I18nKey: item.I18nKey,
Children: nil,
}
records = append(records, &menu)
}
Expand Down
1 change: 0 additions & 1 deletion server/internal/logic/manage/menu/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func (l *Tree) Tree(req *types.TreeRequest) (resp []types.TreeResponse, err erro

list, err := l.svcCtx.Model.ManageMenu.FindByCondition(l.ctx, nil, condition.NewChain().
NotEqual("constant", true).
NotEqual("hide_in_menu", true).
Build()...)
if err != nil {
return nil, err
Expand Down
26 changes: 17 additions & 9 deletions server/internal/logic/route/get_user_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/zeromicro/go-zero/core/logx"

"server/internal/auth"
"server/internal/logic/manage/menu"
"server/internal/model/manage_menu"
"server/internal/svc"
types "server/internal/types/route"
Expand Down Expand Up @@ -77,21 +78,28 @@ func convert(list []*manage_menu.ManageMenu) []*types.Route {
var records []*types.Route
for _, item := range list {
var route types.Route
var query []types.Query

menu.Unmarshal(item.Query.String, &query)

route = types.Route{
Id: int64(item.Id),
ParentId: item.ParentId,
Name: item.RouteName,
Path: item.RoutePath,
Meta: types.RouteMeta{
Title: item.RouteName,
I18nKey: item.I18nKey,
Icon: item.Icon,
Order: int(item.Order),
HideInMenu: cast.ToBool(item.HideInMenu),
ActiveMenu: item.ActiveMenu.String,
MultiTab: cast.ToBool(item.MultiTab),
KeepAlive: cast.ToBool(item.KeepAlive),
Constant: cast.ToBool(item.Constant),
Title: item.RouteName,
I18nKey: item.I18nKey,
Icon: item.Icon,
Order: int(item.Order),
HideInMenu: cast.ToBool(item.HideInMenu),
ActiveMenu: item.ActiveMenu.String,
MultiTab: cast.ToBool(item.MultiTab),
FixedIndexInTab: int(item.FixedIndexInTab),
KeepAlive: cast.ToBool(item.KeepAlive),
Constant: cast.ToBool(item.Constant),
Href: item.Href.String,
Query: query,
},
Component: item.Component,
Props: strings.Contains(item.RoutePath, ":"),
Expand Down
Loading

0 comments on commit 4afd9af

Please sign in to comment.