-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu_mod.go
140 lines (116 loc) · 3.93 KB
/
menu_mod.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
package service_swa
import (
"github.com/ServiceWeaver/weaver"
)
type ModMenu struct {
weaver.AutoMarshal
ModBase
MenuLevel uint `json:"-"`
ParentId string `json:"parentId" gorm:"comment:父菜单ID"`
Path string `json:"path" gorm:"comment:路由path"`
Name string `json:"name" gorm:"comment:路由name"`
Hidden bool `json:"hidden" gorm:"comment:是否在列表隐藏"`
Component string `json:"component" gorm:"comment:对应前端文件路径"`
Sort int `json:"sort" gorm:"comment:排序标记"`
Meta `json:"meta" gorm:"embedded;comment:附加属性"`
}
type Meta struct {
weaver.AutoMarshal
ActiveName string `json:"activeName" gorm:"comment:高亮菜单"`
KeepAlive bool `json:"keepAlive" gorm:"comment:是否缓存"`
DefaultMenu bool `json:"defaultMenu" gorm:"comment:是否是基础路由(开发中)"`
Title string `json:"title" gorm:"comment:菜单名"`
Icon string `json:"icon" gorm:"comment:菜单图标"`
CloseTab bool `json:"closeTab" gorm:"comment:自动关闭tab"`
}
type SysBaseMenu struct {
weaver.AutoMarshal
ModMenu
SwaRoles []SwaRole `json:"roles" gorm:"many2many:swa_menu_role;"`
Parameters []SysBaseMenuParameter `json:"parameters" gorm:"-"`
MenuBtn []SysBaseMenuBtn `json:"menuBtn" gorm:"-"`
Meta `json:"meta" gorm:"embedded;comment:附加属性"`
}
func (m SysBaseMenu) TableName() string {
return "swa_menus"
}
type MenuRole struct {
Menu SysBaseMenu
Roles []SwaRole `json:"roles" gorm:"-"`
Parameters []SysBaseMenuParameter `json:"parameters" gorm:"-"`
MenuBtn []SysBaseMenuBtn `json:"menuBtn" gorm:"-"`
}
type SysBaseMenuParameter struct {
weaver.AutoMarshal
ModBase
SysBaseMenuID uint `json:"menuId"`
Type string `json:"type" gorm:"comment:地址栏携带参数为params还是query"`
Key string `json:"key" gorm:"comment:地址栏携带参数的key"`
Value string `json:"value" gorm:"comment:地址栏携带参数的值"`
}
func (SysBaseMenuParameter) TableName() string {
return "swa_menu_param"
}
type SysBaseMenuBtn struct {
weaver.AutoMarshal
ModBase
Name string `json:"name" gorm:"comment:按钮关键key"`
Desc string `json:"desc" gorm:"按钮备注"`
SysBaseMenuID uint `json:"sysBaseMenuID" gorm:"comment:菜单ID"`
}
func (SysBaseMenuBtn) TableName() string {
return "swa_btns"
}
type SwaRoleMenu struct {
MenuId string `json:"menuId" gorm:"comment:菜单ID;column:sys_base_menu_id"`
RoleId string `json:"-" gorm:"comment:角色ID;column:sys_role_role_id"`
}
func (SwaRoleMenu) TableName() string {
return "swa_menu_role"
}
type SwaRoleBtn struct {
RoleId uint `gorm:"comment:角色ID"`
SysMenuID uint `gorm:"comment:菜单ID"`
SysBaseMenuBtnID uint `gorm:"comment:菜单按钮ID"`
SysBaseMenuBtn SysBaseMenuBtn ` gorm:"comment:按钮详情"`
}
func (SwaRoleBtn) TableName() string {
return "swa_btn_role"
}
type AddMenuRoleInfo struct {
Menus []SysBaseMenu `json:"menus"`
RoleId uint `json:"roleId"`
}
func DefaultMenu() []SysBaseMenu {
return []SysBaseMenu{{
ModMenu: ModMenu{
ModBase: ModBase{ID: 1},
ParentId: "0",
Path: "dashboard",
Name: "dashboard",
Component: "view/dashboard/index.vue",
Sort: 1,
},
Meta: Meta{
Title: "仪表盘",
Icon: "setting",
},
}}
}
type SysMenusResponse struct {
Menus []SysMenu `json:"menus"`
}
type SysMenu struct {
SysBaseMenu
MenuId string `json:"menuId" gorm:"comment:菜单ID"`
RoleId uint `json:"-" gorm:"comment:角色ID"`
Parameters []SysBaseMenuParameter `json:"parameters" gorm:"-"`
Children []SysMenu `json:"children" gorm:"-"`
Btns map[string]uint `json:"btns" gorm:"-"`
}
type SysBaseMenusResponse struct {
Menus []SysBaseMenu `json:"menus"`
}
type SysBaseMenuResponse struct {
Menu SysBaseMenu `json:"menu"`
}