Documentation
¶
Index ¶
- Constants
- Variables
- func Add(name string, temp Template)
- func AddComp(comp Component)
- func AddFromPlugin(name string, mod string)
- func AddLoginComp(comp Component)
- func CSS(s string) template.CSS
- func CheckRequirements() (bool, bool)
- func CheckThemeRequirements() bool
- func Execute(ctx *context.Context, param *ExecuteParam) *bytes.Buffer
- func GetAsset(path string) ([]byte, error)
- func GetComponentAsset() []string
- func GetComponentAssetImportHTML(ctx *context.Context) (res template.HTML)
- func GetComponentAssetWithinPage() []string
- func GetPageContentFromPageType(ctx *context.Context, title, desc, msg string, pt PageType) (template.HTML, template.HTML, template.HTML)
- func HTML(s string) template.HTML
- func JS(s string) template.JS
- func SetComp(name string, comp Component)
- func Themes() []string
- func VersionCompare(toCompare string, versions []string) bool
- func WarningPanel(ctx *context.Context, msg string, pts ...PageType) types.Panel
- func WarningPanelWithDescAndTitle(ctx *context.Context, msg, desc, title string, pts ...PageType) types.Panel
- type BaseComponent
- func (b *BaseComponent) BindActionTo(ctx *context.Context, action types.Action, id string)
- func (b *BaseComponent) GetAsset(name string) ([]byte, error)
- func (b *BaseComponent) GetAssetList() []string
- func (b *BaseComponent) GetCSS() template.CSS
- func (b *BaseComponent) GetCallbacks() types.Callbacks
- func (b *BaseComponent) GetContentWithData(obj interface{}) template.HTML
- func (b *BaseComponent) GetJS() template.JS
- func (b *BaseComponent) GetName() string
- func (b *BaseComponent) GetTemplate() (*template.Template, string)
- func (b *BaseComponent) IsAPage() bool
- type Component
- type ExecuteOptions
- type ExecuteParam
- type PageType
- type Template
Constants ¶
const ( CompCol = "col" // 列组件 CompRow = "row" // 行组件 CompForm = "form" // 表单组件 CompTable = "table" // 表格组件 CompDataTable = "datatable" // 数据表格组件 CompTree = "tree" // 树组件 CompTreeView = "treeview" // 树视图组件 CompTabs = "tabs" // 标签页组件 CompAlert = "alert" // 警告组件 CompLink = "link" // 链接组件 CompPaginator = "paginator" // 分页组件 CompPopup = "popup" // 弹窗组件 CompBox = "box" // 盒子组件 CompLabel = "label" // 标签组件 CompImage = "image" // 图片组件 CompButton = "button" // 按钮组件 )
组件类型常量定义
Variables ¶
var DefaultFuncMap = template.FuncMap{ "lang": language.Get, "langHtml": language.GetFromHtml, "link": func(cdnUrl, prefixUrl, assetsUrl string) string { if cdnUrl == "" { return prefixUrl + assetsUrl } return cdnUrl + assetsUrl }, "isLinkUrl": func(s string) bool { return (len(s) > 7 && s[:7] == "http://") || (len(s) > 8 && s[:8] == "https://") }, "render": func(s, old, repl template.HTML) template.HTML { return template.HTML(strings.ReplaceAll(string(s), string(old), string(repl))) }, "renderJS": func(s template.JS, old, repl template.HTML) template.JS { return template.JS(strings.ReplaceAll(string(s), string(old), string(repl))) }, "divide": func(a, b int) int { return a / b }, "renderRowDataHTML": func(id, content template.HTML, value ...map[string]types.InfoItem) template.HTML { return template.HTML(types.ParseTableDataTmplWithID(id, string(content), value...)) }, "renderRowDataJS": func(id template.HTML, content template.JS, value ...map[string]types.InfoItem) template.JS { return template.JS(types.ParseTableDataTmplWithID(id, string(content), value...)) }, "attr": func(s template.HTML) template.HTMLAttr { return template.HTMLAttr(s) }, "js": func(s interface{}) template.JS { if ss, ok := s.(string); ok { return template.JS(ss) } if ss, ok := s.(template.HTML); ok { return template.JS(ss) } return "" }, "changeValue": func(f types.FormField, index int) types.FormField { if len(f.ValueArr) > 0 { f.Value = template.HTML(f.ValueArr[index]) } if len(f.OptionsArr) > 0 { f.Options = f.OptionsArr[index] } if f.FormType.IsSelect() { f.FieldClass += "_" + strconv.Itoa(index) } return f }, }
DefaultFuncMap 默认模板函数映射
var DefaultThemeNames = []string{"sword", "adminlte"}
DefaultThemeNames 默认主题名称列表
Functions ¶
func AddComp ¶
func AddComp(comp Component)
AddComp 通过提供的名称使组件可用 如果使用相同的名称调用两次Add或组件为nil,会触发panic 参数:
- comp: 组件接口
func CheckRequirements ¶
CheckRequirements 检查主题和GoAdmin的相互依赖限制 第一个返回参数表示GoAdmin版本是否满足所使用主题的要求 第二个返回参数表示所使用主题的版本是否满足GoAdmin的要求 返回:
- bool: GoAdmin版本是否满足主题要求
- bool: 主题版本是否满足GoAdmin要求
func CheckThemeRequirements ¶
func CheckThemeRequirements() bool
CheckThemeRequirements 检查主题要求 返回: GoAdmin版本是否满足主题要求
func Execute ¶
func Execute(ctx *context.Context, param *ExecuteParam) *bytes.Buffer
Execute 执行模板渲染 参数:
- ctx: 上下文对象
- param: 执行参数
返回: 渲染后的缓冲区
func GetComponentAsset ¶
func GetComponentAsset() []string
GetComponentAsset 获取所有组件的资源列表 返回: 资源URL后缀列表
func GetComponentAssetImportHTML ¶
GetComponentAssetImportHTML 获取组件资源导入HTML 参数:
- ctx: 上下文对象
返回: 资源导入HTML
func GetComponentAssetWithinPage ¶
func GetComponentAssetWithinPage() []string
GetComponentAssetWithinPage 获取页面内组件的资源列表(不包括页面组件) 返回: 资源URL后缀列表
func GetPageContentFromPageType ¶
func GetPageContentFromPageType(ctx *context.Context, title, desc, msg string, pt PageType) (template.HTML, template.HTML, template.HTML)
GetPageContentFromPageType 根据页面类型获取页面内容 参数:
- ctx: 上下文对象
- title: 页面标题
- desc: 页面描述
- msg: 消息内容
- pt: 页面类型
返回: 标题HTML、描述HTML、内容HTML
Types ¶
type BaseComponent ¶
type BaseComponent struct {
Name string // 组件名称
HTMLData string // HTML数据
CSS template.CSS // CSS样式
JS template.JS // JavaScript代码
Callbacks types.Callbacks // 回调函数
}
BaseComponent 基础组件结构体
func (*BaseComponent) GetAsset ¶
func (b *BaseComponent) GetAsset(name string) ([]byte, error)
GetAsset 根据名称获取资源 参数:
- name: 资源名称
返回: 资源内容和错误
func (*BaseComponent) GetAssetList ¶
func (b *BaseComponent) GetAssetList() []string
GetAssetList 获取资源列表 返回: 资源URL后缀列表
func (*BaseComponent) GetCSS ¶
func (b *BaseComponent) GetCSS() template.CSS
GetCSS 获取CSS样式 返回: CSS样式
func (*BaseComponent) GetCallbacks ¶
func (b *BaseComponent) GetCallbacks() types.Callbacks
GetCallbacks 获取回调函数 返回: 回调函数列表
func (*BaseComponent) GetContentWithData ¶
func (b *BaseComponent) GetContentWithData(obj interface{}) template.HTML
GetContentWithData 使用数据获取内容 参数:
- obj: 数据对象
返回: HTML内容
func (*BaseComponent) GetJS ¶
func (b *BaseComponent) GetJS() template.JS
GetJS 获取JavaScript代码 返回: JavaScript代码
func (*BaseComponent) GetTemplate ¶
func (b *BaseComponent) GetTemplate() (*template.Template, string)
GetTemplate 获取模板对象 返回: 模板对象和模板名称
func (*BaseComponent) IsAPage ¶
func (b *BaseComponent) IsAPage() bool
IsAPage 判断是否为页面组件 返回: 是否为页面组件
type Component ¶
type Component interface {
// GetTemplate 返回一个 *template.Template 和一个给定的键
GetTemplate() (*template.Template, string)
// GetAssetList 返回组件中使用的资源URL后缀
// 示例:
//
// {{.UrlPrefix}}/assets/login/css/bootstrap.min.css => login/css/bootstrap.min.css
//
// 参见:
// https://github.com/purpose168/GoAdmin/blob/master/template/login/theme1.tmpl#L32
// https://github.com/purpose168/GoAdmin/blob/master/template/login/list.go
GetAssetList() []string
// GetAsset 根据相应的URL后缀返回资源内容
// 建议使用go-bindata工具生成资源内容
//
// 参见: http://github.com/jteeuwen/go-bindata
GetAsset(string) ([]byte, error)
GetContent() template.HTML
IsAPage() bool
GetName() string
GetJS() template.JS
GetCSS() template.CSS
GetCallbacks() types.Callbacks
}
Component 是表示UI组件的接口
type ExecuteOptions ¶
type ExecuteOptions struct {
Animation bool // 是否启用动画
NoCompress bool // 是否不压缩
HideSideBar bool // 是否隐藏侧边栏
HideHeader bool // 是否隐藏头部
UpdateMenu bool // 是否更新菜单
}
ExecuteOptions 执行选项结构体
func GetExecuteOptions ¶
func GetExecuteOptions(options []ExecuteOptions) ExecuteOptions
GetExecuteOptions 获取执行选项 参数:
- options: 执行选项列表
返回: 执行选项
type ExecuteParam ¶
type ExecuteParam struct {
User models.UserModel // 用户模型
Tmpl *template.Template // 模板对象
TmplName string // 模板名称
IsPjax bool // 是否为PJAX请求
Panel types.Panel // 面板
Logo template.HTML // Logo HTML
Config *c.Config // 配置对象
Menu *menu.Menu // 菜单
Animation bool // 是否启用动画
Buttons types.Buttons // 按钮
NoCompress bool // 是否不压缩
Iframe bool // 是否在iframe中
}
ExecuteParam 执行参数结构体
type PageType ¶
type PageType uint8
PageType 页面类型枚举
type Template ¶
type Template interface {
Name() string
// 布局
Col() types.ColAttribute
Row() types.RowAttribute
// 表单和表格
Form() types.FormAttribute
Table() types.TableAttribute
DataTable() types.DataTableAttribute
TreeView() types.TreeViewAttribute
Tree() types.TreeAttribute
Tabs() types.TabsAttribute
Alert() types.AlertAttribute
Link() types.LinkAttribute
Paginator() types.PaginatorAttribute
Popup() types.PopupAttribute
Box() types.BoxAttribute
Label() types.LabelAttribute
Image() types.ImgAttribute
Button() types.ButtonAttribute
// 构建器方法
GetTmplList() map[string]string
GetAssetList() []string
GetAssetImportHTML(exceptComponents ...string) template.HTML
GetAsset(string) ([]byte, error)
GetTemplate(bool) (*template.Template, string)
GetVersion() string
GetRequirements() []string
GetHeadHTML() template.HTML
GetFootJS() template.HTML
Get404HTML() template.HTML
Get500HTML() template.HTML
Get403HTML() template.HTML
}
Template 是包含UI组件方法的接口 它将在插件中用于自定义UI
Directories
¶
| Path | Synopsis |
|---|---|
|
Code generated by go-bindata.
|
Code generated by go-bindata. |
|
Code generated by go-bindata.
|
Code generated by go-bindata. |
|
Code generated by go-bindata.
|
Code generated by go-bindata. |