| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- package schema
- import "time"
- // Menu Menu对象
- type Menu struct {
- RecordID string `json:"record_id"` // 记录id
- Name string `json:"name"` // 名称
- Path string `json:"path"` // 路径
- Component string `json:"component"` // 组件
- Meta MenuMeta `json:"meta"` // 元数据
- ParentId string `json:"parent_id"` // 父级id
- Sequence int `json:"sequence"` // 排序值
- CreatedAt time.Time `json:"created_at"` // 创建时间
- CreatorId string `json:"creator_id"` // 创建者id
- CreatorName string `json:"creator_name"` // 创建者名称
- }
- type MenuMeta struct {
- Icon string `json:"icon"` // 图标
- Title string `json:"title"` // 标题
- IsLink string `json:"isLink"` // 是否外链
- IsHide bool `json:"isHide"` // 是否隐藏
- IsFull bool `json:"isFull"` // 是否全屏
- IsAffix bool `json:"isAffix"` // 是否固定
- IsKeepAlive bool `json:"isKeepAlive"` // 是否缓存
- }
- // MenuQueryParam 查询条件
- type MenuQueryParam struct {
- LikeName string
- RecordIDs []string
- }
- // MenuQueryOptions Menu对象查询可选参数项
- type MenuQueryOptions struct {
- PageParam *PaginationParam // 分页参数
- }
- type Menus []*Menu
- // MenuQueryResult Menu对象查询结果
- type MenuQueryResult struct {
- Data Menus
- PageResult *PaginationResult
- }
- // MenuTree 菜单树
- type MenuTree struct {
- RecordID string `json:"record_id"`
- Name string `json:"name" binding:"required" `
- Path string `json:"path"` // 路径
- Component string `json:"component"` // 组件
- Meta MenuMeta `json:"meta"` // 元数据
- ParentId string `json:"parent_id"` // 父级id
- Children MenuTrees `json:"children"` // 子级
- }
- // MenuTrees 菜单树列表
- type MenuTrees []*MenuTree
- func ToTree(List MenuTrees, pid string) MenuTrees {
- var newArr MenuTrees
- for _, v := range List {
- if v.ParentId == pid {
- v.Children = ToTree(List, v.RecordID)
- newArr = append(newArr, v)
- }
- }
- return newArr
- }
- // ToTrees 转换为菜单列表
- func (a Menus) ToTrees() MenuTrees {
- list := make(MenuTrees, len(a))
- for i, item := range a {
- list[i] = &MenuTree{
- RecordID: item.RecordID,
- Name: item.Name,
- Path: item.Path,
- Component: item.Component,
- Meta: item.Meta,
- ParentId: item.ParentId,
- }
- }
- return list
- }
- // FillCreator 填充创建者信息
- func (a Menus) FillCreator(users Users) {
- for _, o := range a {
- for _, u := range users {
- if o.CreatorId == u.RecordID {
- o.CreatorName = u.RealName
- continue
- }
- }
- }
- }
|