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
|
func GetOAMenuTable(ctx *context.Context) table.Table {
m := table.NewDefaultTable(table.DefaultConfigWithDriverAndConnection("mysql", table.DefaultConnectionName))
tableName := "menu"
title := "OA系统菜单"
info := m.GetInfo()
info.HideDetailButton()
info.HideFilterArea()
info.SetDefaultPageSize(100)
info.AddField("菜单ID", "id", db.Bigint).FieldFilterable().FieldSortable()
info.AddField("菜单名", "title", db.Varchar).FieldFilterable(types.FilterType{Operator: types.FilterOperatorLike})
info.AddField("父级菜单ID", "parent_id", db.Bigint)
info.AddField("前端标识", "slug", db.Varchar)
info.AddField("排序", "order", db.Int).FieldSortable()
info.AddField("图标", "icon", db.Varchar)
info.AddField("前端跳转uri", "uri", db.Varchar)
info.SetTable(tableName).SetTitle(title).SetSortField("order").SetSortAsc()
// 重定义删除方法
info.SetDeleteFn(func(ids []string) error {
return db2.Redis(db2.Redis).HDel(key, ids...).Err()
})
formList := m.GetForm()
formList.AddField("菜单ID", "id", db.Bigint, form.Default).FieldDisableWhenCreate().FieldHelpMsg("")
formList.AddField("菜单名", "title", db.Varchar, form.Text).FieldMust()
formList.AddField("父级菜单ID", "parent_id", db.Bigint, form.Text).FieldDefault("0")
formList.AddField("前端标识", "slug", db.Varchar, form.Text).FieldMust()
formList.AddField("排序", "order", db.Int, form.Number).FieldMust().FieldDefault("100").FieldHelpMsg("<p>小的排前面</p>")
formList.AddField("图标", "icon", db.Varchar, form.Text)
formList.AddField("前端跳转uri", "uri", db.Varchar, form.Text)
// 增改hook
formList.SetPostHook(func(values form2.Values) error {
_ = model.Menu{}.DelCache()
return nil
})
// 删除hook
if strings.Contains(ctx.Path(), "/admin/delete/oa_menu") {
defer func() {
_ = model.Menu{}.DelCache()
}()
}
// 重定义新增方法
formList.SetInsertFn(func(values form2.Values) error {
return db2.Redis(db2.Redis).HSet(key, values.Get("name"), values.Get("article_id")).Err()
})
// 重定义编辑方法
formList.SetUpdateFn(func(values form2.Values) error {
return db2.Redis(db2.Redis).HSet(key, values.Get("name"), values.Get("article_id")).Err()
})
// NULL设置:config字段为空时删除该变量,借此达到设置为 NULL 的目的
formList.SetPostValidator(func(values form2.Values) error {
if values.Get("config") == "" {
values.Delete("config")
}
return nil
})
formList.SetTable(tableName).SetTitle(title)
return m
}
|