-
-
Notifications
You must be signed in to change notification settings - Fork 275
/
menu.go
412 lines (394 loc) · 14.3 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/suyuan32/simple-admin-core/rpc/ent/menu"
)
// Menu is the model entity for the Menu schema.
type Menu struct {
config `json:"-"`
// ID of the ent.
ID uint64 `json:"id,omitempty"`
// Create Time | 创建日期
CreatedAt time.Time `json:"created_at,omitempty"`
// Update Time | 修改日期
UpdatedAt time.Time `json:"updated_at,omitempty"`
// Sort Number | 排序编号
Sort uint32 `json:"sort,omitempty"`
// Parent menu ID | 父菜单ID
ParentID uint64 `json:"parent_id,omitempty"`
// Menu level | 菜单层级
MenuLevel uint32 `json:"menu_level,omitempty"`
// Menu type | 菜单类型 (菜单或目录)0 目录 1 菜单
MenuType uint32 `json:"menu_type,omitempty"`
// Index path | 菜单路由路径
Path string `json:"path,omitempty"`
// Index name | 菜单名称
Name string `json:"name,omitempty"`
// Redirect path | 跳转路径 (外链)
Redirect string `json:"redirect,omitempty"`
// The path of vue file | 组件路径
Component string `json:"component,omitempty"`
// Disable status | 是否停用
Disabled bool `json:"disabled,omitempty"`
// Menu name | 菜单显示标题
Title string `json:"title,omitempty"`
// Menu icon | 菜单图标
Icon string `json:"icon,omitempty"`
// Hide menu | 是否隐藏菜单
HideMenu bool `json:"hide_menu,omitempty"`
// Hide the breadcrumb | 隐藏面包屑
HideBreadcrumb bool `json:"hide_breadcrumb,omitempty"`
// Do not keep alive the tab | 取消页面缓存
IgnoreKeepAlive bool `json:"ignore_keep_alive,omitempty"`
// Hide the tab header | 隐藏页头
HideTab bool `json:"hide_tab,omitempty"`
// Show iframe | 内嵌 iframe
FrameSrc string `json:"frame_src,omitempty"`
// The route carries parameters or not | 携带参数
CarryParam bool `json:"carry_param,omitempty"`
// Hide children menu or not | 隐藏所有子菜单
HideChildrenInMenu bool `json:"hide_children_in_menu,omitempty"`
// Affix tab | Tab 固定
Affix bool `json:"affix,omitempty"`
// The maximum number of pages the router can open | 能打开的子TAB数
DynamicLevel uint32 `json:"dynamic_level,omitempty"`
// The real path of the route without dynamic part | 菜单路由不包含参数部分
RealPath string `json:"real_path,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the MenuQuery when eager-loading is set.
Edges MenuEdges `json:"edges"`
selectValues sql.SelectValues
}
// MenuEdges holds the relations/edges for other nodes in the graph.
type MenuEdges struct {
// Roles holds the value of the roles edge.
Roles []*Role `json:"roles,omitempty"`
// Parent holds the value of the parent edge.
Parent *Menu `json:"parent,omitempty"`
// Children holds the value of the children edge.
Children []*Menu `json:"children,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [3]bool
}
// RolesOrErr returns the Roles value or an error if the edge
// was not loaded in eager-loading.
func (e MenuEdges) RolesOrErr() ([]*Role, error) {
if e.loadedTypes[0] {
return e.Roles, nil
}
return nil, &NotLoadedError{edge: "roles"}
}
// ParentOrErr returns the Parent value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e MenuEdges) ParentOrErr() (*Menu, error) {
if e.loadedTypes[1] {
if e.Parent == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: menu.Label}
}
return e.Parent, nil
}
return nil, &NotLoadedError{edge: "parent"}
}
// ChildrenOrErr returns the Children value or an error if the edge
// was not loaded in eager-loading.
func (e MenuEdges) ChildrenOrErr() ([]*Menu, error) {
if e.loadedTypes[2] {
return e.Children, nil
}
return nil, &NotLoadedError{edge: "children"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Menu) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case menu.FieldDisabled, menu.FieldHideMenu, menu.FieldHideBreadcrumb, menu.FieldIgnoreKeepAlive, menu.FieldHideTab, menu.FieldCarryParam, menu.FieldHideChildrenInMenu, menu.FieldAffix:
values[i] = new(sql.NullBool)
case menu.FieldID, menu.FieldSort, menu.FieldParentID, menu.FieldMenuLevel, menu.FieldMenuType, menu.FieldDynamicLevel:
values[i] = new(sql.NullInt64)
case menu.FieldPath, menu.FieldName, menu.FieldRedirect, menu.FieldComponent, menu.FieldTitle, menu.FieldIcon, menu.FieldFrameSrc, menu.FieldRealPath:
values[i] = new(sql.NullString)
case menu.FieldCreatedAt, menu.FieldUpdatedAt:
values[i] = new(sql.NullTime)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Menu fields.
func (m *Menu) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case menu.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
m.ID = uint64(value.Int64)
case menu.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
m.CreatedAt = value.Time
}
case menu.FieldUpdatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
} else if value.Valid {
m.UpdatedAt = value.Time
}
case menu.FieldSort:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field sort", values[i])
} else if value.Valid {
m.Sort = uint32(value.Int64)
}
case menu.FieldParentID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field parent_id", values[i])
} else if value.Valid {
m.ParentID = uint64(value.Int64)
}
case menu.FieldMenuLevel:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field menu_level", values[i])
} else if value.Valid {
m.MenuLevel = uint32(value.Int64)
}
case menu.FieldMenuType:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field menu_type", values[i])
} else if value.Valid {
m.MenuType = uint32(value.Int64)
}
case menu.FieldPath:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field path", values[i])
} else if value.Valid {
m.Path = value.String
}
case menu.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
m.Name = value.String
}
case menu.FieldRedirect:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field redirect", values[i])
} else if value.Valid {
m.Redirect = value.String
}
case menu.FieldComponent:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field component", values[i])
} else if value.Valid {
m.Component = value.String
}
case menu.FieldDisabled:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field disabled", values[i])
} else if value.Valid {
m.Disabled = value.Bool
}
case menu.FieldTitle:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field title", values[i])
} else if value.Valid {
m.Title = value.String
}
case menu.FieldIcon:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field icon", values[i])
} else if value.Valid {
m.Icon = value.String
}
case menu.FieldHideMenu:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field hide_menu", values[i])
} else if value.Valid {
m.HideMenu = value.Bool
}
case menu.FieldHideBreadcrumb:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field hide_breadcrumb", values[i])
} else if value.Valid {
m.HideBreadcrumb = value.Bool
}
case menu.FieldIgnoreKeepAlive:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field ignore_keep_alive", values[i])
} else if value.Valid {
m.IgnoreKeepAlive = value.Bool
}
case menu.FieldHideTab:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field hide_tab", values[i])
} else if value.Valid {
m.HideTab = value.Bool
}
case menu.FieldFrameSrc:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field frame_src", values[i])
} else if value.Valid {
m.FrameSrc = value.String
}
case menu.FieldCarryParam:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field carry_param", values[i])
} else if value.Valid {
m.CarryParam = value.Bool
}
case menu.FieldHideChildrenInMenu:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field hide_children_in_menu", values[i])
} else if value.Valid {
m.HideChildrenInMenu = value.Bool
}
case menu.FieldAffix:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field affix", values[i])
} else if value.Valid {
m.Affix = value.Bool
}
case menu.FieldDynamicLevel:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field dynamic_level", values[i])
} else if value.Valid {
m.DynamicLevel = uint32(value.Int64)
}
case menu.FieldRealPath:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field real_path", values[i])
} else if value.Valid {
m.RealPath = value.String
}
default:
m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Menu.
// This includes values selected through modifiers, order, etc.
func (m *Menu) Value(name string) (ent.Value, error) {
return m.selectValues.Get(name)
}
// QueryRoles queries the "roles" edge of the Menu entity.
func (m *Menu) QueryRoles() *RoleQuery {
return NewMenuClient(m.config).QueryRoles(m)
}
// QueryParent queries the "parent" edge of the Menu entity.
func (m *Menu) QueryParent() *MenuQuery {
return NewMenuClient(m.config).QueryParent(m)
}
// QueryChildren queries the "children" edge of the Menu entity.
func (m *Menu) QueryChildren() *MenuQuery {
return NewMenuClient(m.config).QueryChildren(m)
}
// Update returns a builder for updating this Menu.
// Note that you need to call Menu.Unwrap() before calling this method if this Menu
// was returned from a transaction, and the transaction was committed or rolled back.
func (m *Menu) Update() *MenuUpdateOne {
return NewMenuClient(m.config).UpdateOne(m)
}
// Unwrap unwraps the Menu entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (m *Menu) Unwrap() *Menu {
_tx, ok := m.config.driver.(*txDriver)
if !ok {
panic("ent: Menu is not a transactional entity")
}
m.config.driver = _tx.drv
return m
}
// String implements the fmt.Stringer.
func (m *Menu) String() string {
var builder strings.Builder
builder.WriteString("Menu(")
builder.WriteString(fmt.Sprintf("id=%v, ", m.ID))
builder.WriteString("created_at=")
builder.WriteString(m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(m.UpdatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("sort=")
builder.WriteString(fmt.Sprintf("%v", m.Sort))
builder.WriteString(", ")
builder.WriteString("parent_id=")
builder.WriteString(fmt.Sprintf("%v", m.ParentID))
builder.WriteString(", ")
builder.WriteString("menu_level=")
builder.WriteString(fmt.Sprintf("%v", m.MenuLevel))
builder.WriteString(", ")
builder.WriteString("menu_type=")
builder.WriteString(fmt.Sprintf("%v", m.MenuType))
builder.WriteString(", ")
builder.WriteString("path=")
builder.WriteString(m.Path)
builder.WriteString(", ")
builder.WriteString("name=")
builder.WriteString(m.Name)
builder.WriteString(", ")
builder.WriteString("redirect=")
builder.WriteString(m.Redirect)
builder.WriteString(", ")
builder.WriteString("component=")
builder.WriteString(m.Component)
builder.WriteString(", ")
builder.WriteString("disabled=")
builder.WriteString(fmt.Sprintf("%v", m.Disabled))
builder.WriteString(", ")
builder.WriteString("title=")
builder.WriteString(m.Title)
builder.WriteString(", ")
builder.WriteString("icon=")
builder.WriteString(m.Icon)
builder.WriteString(", ")
builder.WriteString("hide_menu=")
builder.WriteString(fmt.Sprintf("%v", m.HideMenu))
builder.WriteString(", ")
builder.WriteString("hide_breadcrumb=")
builder.WriteString(fmt.Sprintf("%v", m.HideBreadcrumb))
builder.WriteString(", ")
builder.WriteString("ignore_keep_alive=")
builder.WriteString(fmt.Sprintf("%v", m.IgnoreKeepAlive))
builder.WriteString(", ")
builder.WriteString("hide_tab=")
builder.WriteString(fmt.Sprintf("%v", m.HideTab))
builder.WriteString(", ")
builder.WriteString("frame_src=")
builder.WriteString(m.FrameSrc)
builder.WriteString(", ")
builder.WriteString("carry_param=")
builder.WriteString(fmt.Sprintf("%v", m.CarryParam))
builder.WriteString(", ")
builder.WriteString("hide_children_in_menu=")
builder.WriteString(fmt.Sprintf("%v", m.HideChildrenInMenu))
builder.WriteString(", ")
builder.WriteString("affix=")
builder.WriteString(fmt.Sprintf("%v", m.Affix))
builder.WriteString(", ")
builder.WriteString("dynamic_level=")
builder.WriteString(fmt.Sprintf("%v", m.DynamicLevel))
builder.WriteString(", ")
builder.WriteString("real_path=")
builder.WriteString(m.RealPath)
builder.WriteByte(')')
return builder.String()
}
// Menus is a parsable slice of Menu.
type Menus []*Menu