menu

package
v1.0.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MenuRoot  = "R"
	MenuApi   = "A"
	MenuPage  = "M"
	MenuGroup = "G"
	MenuBasic = "BA"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AllMenuRequest

type AllMenuRequest struct {
	NotType *string `json:"not_type"`
	RoleId  *uint32 `json:"role_id"`
}
type Menu struct {
	types.BaseModel
	ParentId        uint32  `json:"parent_id"`
	Title           string  `json:"title"`
	Type            string  `json:"type"`
	Keyword         *string `json:"keyword"`
	Icon            *string `json:"icon"`
	Api             *string `json:"api"`
	Method          *string `json:"method"`
	Path            *string `json:"path"`
	Permission      *string `json:"permission"`
	CheckObject     *bool   `json:"check_object"`
	CheckObjectRule *string `json:"check_object_rule"`
	Component       *string `json:"component"`
	Redirect        *string `json:"redirect"`
	Weight          *uint32 `json:"weight"`
	IsHidden        *bool   `json:"is_hidden"`
	IsCache         *bool   `json:"is_cache"`
	IsHome          *bool   `json:"is_home"`
	IsAffix         *bool   `json:"is_affix"`
	Children        []*Menu `json:"children"  gorm:"-"`
}
func (m *Menu) AppendChildren(child any)

AppendChildren 添加子节点

func (m *Menu) ChildrenNode() []tree.Tree

ChildrenNode 获取子节点

func (m *Menu) ID() uint32

ID 获取菜单树ID

func (m *Menu) Parent() uint32

Parent 获取父ID

type MenuClosure struct {
	ID       uint32 `json:"id"`
	Parent   uint32 `json:"parent"`
	Children uint32 `json:"children"`
}

type Repo

type Repo interface {
	InitBasicMenu(ctx kratosx.Context)
	AllRoleKeyword(ctx kratosx.Context, id uint32) ([]string, error)
	AllMenu(ctx kratosx.Context, in *AllMenuRequest) ([]*Menu, error)
	GetMenu(ctx kratosx.Context, id uint32) (*Menu, error)
	GetMenuByApi(ctx kratosx.Context, api, method string) (*Menu, error)
	AddMenu(ctx kratosx.Context, in *Menu) (uint32, error)
	UseHome(ctx kratosx.Context, app string, id uint32) error
	UpdateMenu(ctx kratosx.Context, in *Menu) error
	DeleteMenu(ctx kratosx.Context, ids []uint32) error
}

type UseCase

type UseCase struct {
	// contains filtered or unexported fields
}

func NewUseCase

func NewUseCase(conf *config.Config, repo Repo) *UseCase

func (*UseCase) AddMenu

func (u *UseCase) AddMenu(ctx kratosx.Context, in *Menu) (uint32, error)

func (*UseCase) DeleteMenu

func (u *UseCase) DeleteMenu(ctx kratosx.Context, id uint32) error

func (*UseCase) MenuTree

func (u *UseCase) MenuTree(ctx kratosx.Context, in *AllMenuRequest) ([]tree.Tree, error)

MenuTree 查询系统菜单树

func (*UseCase) MenuTreeFromRole

func (u *UseCase) MenuTreeFromRole(ctx kratosx.Context) ([]tree.Tree, error)

// MenuTree 查询系统菜单树

func (u *UseCase) MenuTree(ctx kratosx.Context, in *AllMenuRequest) ([]tree.Tree, error) {
	list, err := u.repo.AllMenu(ctx, in)
	if err != nil {
		return nil, errors.Database()
	}

	var (
		group = make(map[string][]tree.Tree)
		roots []tree.Tree
		apps  []*Menu
	)

	// 构建树枝,并选取根节点
	for _, item := range list {
		group[item.App] = append(group[item.App], item)
		if item.ParentId == 0 {
			apps = append(apps, item)
		}
	}

	// 通过根节点构造树
	for _, app := range apps {
		root := tree.BuildTreeByID(group[app.App], app.ID())
		roots = append(roots, root)
	}

	return roots, nil
}

func (*UseCase) UpdateMenu

func (u *UseCase) UpdateMenu(ctx kratosx.Context, in *Menu) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL