forked from bufanyun/hotgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.go
147 lines (127 loc) · 5.07 KB
/
menu.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Package adminin
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <[email protected]>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package adminin
import (
"context"
"github.com/gogf/gf/v2/errors/gerror"
"hotgo/internal/model"
"hotgo/internal/model/entity"
"hotgo/internal/model/input/form"
)
// MenuEditInp 修改/新增菜单
type MenuEditInp struct {
entity.AdminMenu
}
func (in *MenuEditInp) Filter(ctx context.Context) (err error) {
if in.Title == "" {
err = gerror.New("菜单名称不能为空")
return
}
if in.Type != 3 && in.Path == "" {
err = gerror.New("路由地址不能为空")
return
}
if in.Name == "" {
err = gerror.New("路由名称不能为空")
return
}
return
}
type MenuEditModel struct{}
// MenuDeleteInp 删除菜单
type MenuDeleteInp struct {
Id interface{} `json:"id" v:"required#菜单ID不能为空" dc:"菜单ID"`
}
func (in *MenuDeleteInp) Filter(ctx context.Context) (err error) {
return
}
type MenuDeleteModel struct{}
// MenuListInp 获取菜单列表
type MenuListInp struct {
form.PageReq
Pid int64 `json:"pid" dc:"父ID"`
}
func (in *MenuListInp) Filter(ctx context.Context) (err error) {
return
}
// MenuSearchListInp 查询菜单列表
type MenuSearchListInp struct {
Name string `json:"name" dc:"菜单名称"`
form.StatusReq
}
func (in *MenuSearchListInp) Filter(ctx context.Context) (err error) {
return
}
type MenuSearchListModel []*model.TreeMenu
// MenuTree 树
type MenuTree struct {
entity.AdminMenu
Key int64 `json:"key" `
Label string `json:"label" dc:"标签"`
Children []*MenuTree `json:"children"`
}
type MenuListModel struct {
List []*MenuTree `json:"list"`
}
// MenuRouteMeta 菜单路由
type MenuRouteMeta struct {
// 解释参考:https://naive-ui-admin-docs.vercel.app/guide/router.html#%E5%A4%9A%E7%BA%A7%E8%B7%AF%E7%94%B1
Title string `json:"title"` // 菜单名称 一般必填
// Disabled bool `json:"disabled,omitempty"` // 禁用菜单
Icon string `json:"icon,omitempty"` // 菜单图标
KeepAlive bool `json:"keepAlive,omitempty"` // 缓存该路由
Hidden bool `json:"hidden,omitempty"` // 隐藏菜单
Sort int `json:"sort,omitempty"` // 排序越小越排前
AlwaysShow bool `json:"alwaysShow,omitempty"` // 取消自动计算根路由模式
ActiveMenu string `json:"activeMenu,omitempty"` // 当路由设置了该属性,则会高亮相对应的侧边栏。
// 这在某些场景非常有用,比如:一个列表页路由为:/list/basic-list
// 点击进入详情页,这时候路由为/list/basic-info/1,但你想在侧边栏高亮列表的路由,就可以进行如下设置
// 注意是配置高亮路由 `name`,不是path
IsRoot bool `json:"isRoot,omitempty"` // 是否跟路由 顶部混合菜单,必须传 true,否则左侧会显示异常(场景就是,分割菜单之后,当一级菜单没有子菜单)
FrameSrc string `json:"frameSrc,omitempty" ` // 内联外部地址
Permissions string `json:"permissions,omitempty"` // 菜单包含权限集合,满足其中一个就会显示
Affix bool `json:"affix,omitempty"` // 是否固定 设置为 true 之后 多页签不可删除
Type int `json:"type"` // 菜单类型
}
type MenuRoute struct {
Name string `json:"name"`
Path string `json:"path"`
Redirect string `json:"redirect"`
Component string `json:"component"`
Meta *MenuRouteMeta `json:"meta"`
Children []*MenuRoute `json:"children,omitempty" dc:"子路由"`
}
// MenuRouteSummary 菜单树结构
type MenuRouteSummary struct {
entity.AdminMenu
Children []*MenuRouteSummary
}
// DynamicMeta 动态路由元数据
type DynamicMeta struct {
Title string `json:"title" description:"菜单标题"`
Icon string `json:"icon" description:"菜单图标"`
NoCache bool `json:"noCache" description:"是否缓存"`
Remark string `json:"remark" description:"备注"`
}
// DynamicBase 动态路由
type DynamicBase struct {
Id int64 `json:"id" description:"菜单ID"`
Pid int64 `json:"pid" description:"父ID"`
Name string `json:"name" description:"菜单名称"`
Code string `json:"code" description:"菜单编码"`
Path string `json:"path" description:"路由地址"`
Hidden bool `json:"hidden" description:"是否隐藏"`
Redirect string `json:"redirect" description:"重定向"`
Component string `json:"component" description:"组件路径"`
AlwaysShow bool `json:"alwaysShow" description:"暂时不知道干啥"`
IsFrame string `json:"isFrame" description:"是否为外链(0是 1否)"`
Meta *DynamicMeta `json:"meta" description:"配置数据集"`
}
// DynamicMenu 动态路由菜单
type DynamicMenu struct {
DynamicBase
Children []*DynamicBase `json:"children" description:"子菜单"`
}