You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.6 KiB
75 lines
1.6 KiB
// Code scaffolded by goctl. Safe to edit.
|
|
// goctl 1.9.2
|
|
|
|
package menu
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/youruser/base/internal/svc"
|
|
"github.com/youruser/base/internal/types"
|
|
"github.com/youruser/base/model"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type CreateMenuLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 创建菜单
|
|
func NewCreateMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateMenuLogic {
|
|
return &CreateMenuLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *CreateMenuLogic) CreateMenu(req *types.CreateMenuRequest) (resp *types.MenuItem, err error) {
|
|
visible := true
|
|
if req.Visible != nil {
|
|
visible = *req.Visible
|
|
}
|
|
|
|
menuType := "config"
|
|
if req.Type != "" {
|
|
menuType = req.Type
|
|
}
|
|
|
|
menu := &model.Menu{
|
|
ParentId: req.ParentId,
|
|
Name: req.Name,
|
|
Path: req.Path,
|
|
Icon: req.Icon,
|
|
Component: req.Component,
|
|
Type: menuType,
|
|
SortOrder: req.SortOrder,
|
|
Visible: visible,
|
|
Status: 1,
|
|
}
|
|
|
|
_, err = model.MenuInsert(l.ctx, l.svcCtx.DB, menu)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("创建菜单失败: %v", err)
|
|
}
|
|
|
|
return &types.MenuItem{
|
|
Id: menu.Id,
|
|
ParentId: menu.ParentId,
|
|
Name: menu.Name,
|
|
Path: menu.Path,
|
|
Icon: menu.Icon,
|
|
Component: menu.Component,
|
|
Type: menu.Type,
|
|
SortOrder: menu.SortOrder,
|
|
Visible: menu.Visible,
|
|
Status: menu.Status,
|
|
Children: []types.MenuItem{},
|
|
CreatedAt: menu.CreatedAt.Format("2006-01-02 15:04:05"),
|
|
UpdatedAt: menu.UpdatedAt.Format("2006-01-02 15:04:05"),
|
|
}, nil
|
|
}
|
|
|