Customize Your Page
call the method Contentof the engine:
1
package main
2
3
import (
4
_ "github.com/GoAdminGroup/go-admin/modules/db/drivers/mysql"
5
_ "github.com/GoAdminGroup/themes/adminlte"
6
"github.com/GoAdminGroup/go-admin/engine"
7
"github.com/GoAdminGroup/go-admin/examples/datamodel"
8
"github.com/GoAdminGroup/go-admin/modules/config"
9
"github.com/GoAdminGroup/go-admin/plugins/example"
10
"github.com/GoAdminGroup/go-admin/template/types"
11
ginAdapter "github.com/GoAdminGroup/go-admin/adapter/gin"
12
"github.com/gin-gonic/gin"
13
)
14
15
func main() {
16
r := gin.Default()
17
18
eng := engine.Default()
19
20
cfg := config.Config{}
21
22
if err := eng.AddConfig(cfg).
23
AddGenerators(datamodel.Generators).
24
AddPlugins(example.NewExample()).
25
Use(r); err != nil {
26
panic(err)
27
}
28
29
r.Static("/uploads", "./uploads")
30
31
// here to custom a page.
32
33
r.GET("/"+cfg.PREFIX+"/custom", ginAdapter.Content(YourPageFunc))
34
35
r.Run(":9033")
36
}
Copied!
Contentwill write the contents into the context of the framework.
here is the code of GetContent:
1
import (
2
"github.com/GoAdminGroup/go-admin/modules/config"
3
"github.com/GoAdminGroup/go-admin/modules/db"
4
"github.com/GoAdminGroup/go-admin/modules/language"
5
form2 "github.com/GoAdminGroup/go-admin/plugins/admin/modules/form"
6
template2 "github.com/GoAdminGroup/go-admin/template"
7
"github.com/GoAdminGroup/go-admin/template/icon"
8
"github.com/GoAdminGroup/go-admin/template/types"
9
"github.com/GoAdminGroup/go-admin/template/types/form"
10
"github.com/gin-gonic/gin"
11
)
12
13
func YourPageFunc(ctx *gin.Context) (types.Panel, error) {
14
15
components := template2.Get(config.Get().Theme)
16
17
col1 := components.Col().GetContent()
18
btn1 := components.Button().SetType("submit").
19
SetContent(language.GetFromHtml("Save")).
20
SetThemePrimary().
21
SetOrientationRight().
22
SetLoadingText(icon.Icon("fa-spinner fa-spin", 2) + `Save`).
23
GetContent()
24
btn2 := components.Button().SetType("reset").
25
SetContent(language.GetFromHtml("Reset")).
26
SetThemeWarning().
27
SetOrientationLeft().
28
GetContent()
29
col2 := components.Col().SetSize(types.SizeMD(8)).
30
SetContent(btn1 + btn2).GetContent()
31
32
var panel = types.NewFormPanel()
33
panel.AddField("Name", "name", db.Varchar, form.Text)
34
panel.AddField("Age", "age", db.Int, form.Number)
35
panel.AddField("HomePage", "homepage", db.Varchar, form.Url).FieldDefault("http://google.com")
36
panel.AddField("Email", "email", db.Varchar, form.Email).FieldDefault("[email protected]")
37
panel.AddField("Birthday", "birthday", db.Varchar, form.Datetime).FieldDefault("2010-09-05")
38
panel.AddField("Password", "password", db.Varchar, form.Password)
39
panel.AddField("IP", "ip", db.Varchar, form.Ip)
40
panel.AddField("Certificate", "certificate", db.Varchar, form.Multifile).FieldOptionExt(map[string]interface{}{
41
"maxFileCount": 10,
42
})
43
panel.AddField("Currency", "currency", db.Int, form.Currency)
44
panel.AddField("Content", "content", db.Text, form.RichText).
45
FieldDefault(`<h1>343434</h1><p>34344433434</p><ol><li>23234</li><li>2342342342</li><li>asdfads</li></ol><ul><li>3434334</li><li>34343343434</li><li>44455</li></ul><p><span style="color: rgb(194, 79, 74);">343434</span></p><p><span style="background-color: rgb(194, 79, 74); color: rgb(0, 0, 0);">434434433434</span></p><table border="0" width="100%" cellpadding="0" cellspacing="0"><tbody><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr></tbody></table><p><br></p><p><span style="color: rgb(194, 79, 74);"><br></span></p>`)
46
47
panel.AddField("Website", "website", db.Tinyint, form.Switch).
48
FieldHelpMsg("Help Message").
49
FieldOptions(types.FieldOptions{
50
{Value: "0"},
51
{Value: "1"},
52
})
53
panel.AddField("fruit", "fruit", db.Varchar, form.SelectBox).
54
FieldOptions(types.FieldOptions{
55
{Text: "apple", Value: "apple"},
56
{Text: "banana", Value: "banana"},
57
{Text: "watermelon", Value: "watermelon"},
58
{Text: "pear Value: ", Value: "pear"},
59
}).
60
FieldDisplay(func(value types.FieldModel) interface{} {
61
return []string{"梨"}
62
})
63
panel.AddField("gender", "gender", db.Tinyint, form.Radio).
64
FieldOptions(types.FieldOptions{
65
{Text: "male", Value: "0"},
66
{Text: "female", Value: "1"},
67
})
68
panel.AddField("饮料", "drink", db.Tinyint, form.Select).
69
FieldOptions(types.FieldOptions{
70
{Text: "bear", Value: "beer"},
71
{Text: "juice", Value: "juice"},
72
{Text: "water", Value: "water"},
73
{Text: "read bull", Value: "red bull"},
74
}).FieldDefault("beer")
75
panel.AddField("工作经验", "experience", db.Tinyint, form.SelectSingle).
76
FieldOptions(types.FieldOptions{
77
{Text: "Zero", Value: "0"},
78
{Text: "One year", Value: "1"},
79
{Text: "Four years", Value: "2"},
80
{Text: "Five years", Value: "3"},
81
}).FieldDefault("beer")
82
panel.SetTabGroups(types.TabGroups{
83
{"name", "age", "homepage", "email", "birthday", "password", "ip", "certificate", "currency", "content"},
84
{"website", "fruit", "gender", "drink", "experience"},
85
})
86
panel.SetTabHeaders("input", "select")
87
88
fields, headers := panel.GroupField()
89
90
aform := components.Form().
91
SetTabHeaders(headers).
92
SetTabContents(fields).
93
SetPrefix(config.Get().PrefixFixSlash()).
94
SetUrl("/admin/form/update").
95
SetTitle("Form").
96
SetHiddenFields(map[string]string{
97
form2.PreviousKey: "/admin",
98
}).
99
SetOperationFooter(col1 + col2)
100
101
return types.Panel{
102
Content: components.Box().
103
SetHeader(aform.GetDefaultBoxHeader()).
104
WithHeadBorder().
105
SetBody(aform.GetContent()).
106
GetContent(),
107
Title: "Title",
108
Description: "Description",
109
}, nil
110
}
Copied!
Last modified 1yr ago
Copy link