-
-
Notifications
You must be signed in to change notification settings - Fork 263
/
get_menu_list_by_role_logic.go
70 lines (63 loc) · 1.92 KB
/
get_menu_list_by_role_logic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package menu
import (
"context"
"github.com/suyuan32/simple-admin-common/i18n"
"github.com/suyuan32/simple-admin-core/api/internal/svc"
"github.com/suyuan32/simple-admin-core/api/internal/types"
"github.com/suyuan32/simple-admin-core/rpc/types/core"
"github.com/zeromicro/go-zero/core/logx"
)
type GetMenuListByRoleLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetMenuListByRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMenuListByRoleLogic {
return &GetMenuListByRoleLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetMenuListByRoleLogic) GetMenuListByRole() (resp *types.MenuListResp, err error) {
roleId, _ := l.ctx.Value("roleId").(string)
data, err := l.svcCtx.CoreRpc.GetMenuListByRole(l.ctx, &core.BaseMsg{Msg: roleId})
if err != nil {
return nil, err
}
resp = &types.MenuListResp{}
resp.Data.Total = data.Total
for _, v := range data.Data {
resp.Data.Data = append(resp.Data.Data, types.MenuInfo{
BaseInfo: types.BaseInfo{
Id: v.Id,
CreatedAt: 0,
UpdatedAt: 0,
},
MenuType: v.MenuType,
Level: v.Level,
Path: v.Path,
Name: v.Name,
Redirect: v.Redirect,
Component: v.Component,
Sort: v.Sort,
ParentId: v.ParentId,
Meta: types.Meta{
Title: l.svcCtx.Trans.Trans(l.ctx, v.Meta.Title),
Icon: v.Meta.Icon,
HideMenu: v.Meta.HideMenu,
HideBreadcrumb: v.Meta.HideBreadcrumb,
IgnoreKeepAlive: v.Meta.IgnoreKeepAlive,
HideTab: v.Meta.HideTab,
FrameSrc: v.Meta.FrameSrc,
CarryParam: v.Meta.CarryParam,
HideChildrenInMenu: v.Meta.HideChildrenInMenu,
Affix: v.Meta.Affix,
DynamicLevel: v.Meta.DynamicLevel,
RealPath: v.Meta.RealPath,
},
})
}
resp.Msg = l.svcCtx.Trans.Trans(l.ctx, i18n.Success)
return resp, nil
}