Skip to content

Latest commit

 

History

History
87 lines (64 loc) · 2.15 KB

modules.md

File metadata and controls

87 lines (64 loc) · 2.15 KB

页面模块化


页面自定义需要调用引擎的Content方法,需要返回一个对象types.Panel

以下是types.Panel的定义:

type Panel struct {
	Content     template.HTML   // 页面内容
	Title       string          // 页面标题
	Description string          // 页面描述
	Url         string

	MiniSidebar bool // 是否缩小侧边栏

	AutoRefresh bool // 是否自动刷新页面
	RefreshInterval []int // 刷新页面间隔,时间单位为秒

	Callbacks Callbacks // 页面回调函数
}

对应的ui,可以看下图:

如何使用

package datamodel

import (
	"github.com/GoAdminGroup/go-admin/modules/config"
	template2 "github.com/GoAdminGroup/go-admin/template"
	"github.com/GoAdminGroup/go-admin/template/types"
	"html/template"
)

func GetContent() (types.Panel, error) {

	components := template2.Get(config.Get().THEME)
	colComp := components.Col()

	infobox := components.InfoBox().
		SetText("CPU TRAFFIC").
		SetColor("blue").
		SetNumber("41,410").
		SetIcon("ion-ios-gear-outline").
		GetContent()

	var size = map[string]string{"md": "3", "sm": "6", "xs": "12"}
	infoboxCol1 := colComp.SetSize(size).SetContent(infobox).GetContent()
	row1 := components.Row().SetContent(infoboxCol1).GetContent()

	return types.Panel{
		Content:     row1,
		Title:       "Dashboard",
		Description: "this is a example",
	}, nil
}

Col 列

一个col列对应的是ColAttribute这个类型,有三个方法如下:

type ColAttribute interface {
	SetSize(value map[string]string) ColAttribute   // 设置大小
	SetContent(value template.HTML) ColAttribute    // 设置本列的内容
	GetContent() template.HTML                      // 获取内容
}

关于size,参考的例子是:map[string]string{"md": "3", "sm": "6", "xs": "12"}

Row 行

一个row行对应的是RowAttribute这个类型,有两个方法如下:

type RowAttribute interface {
	SetContent(value template.HTML) RowAttribute  // 设置内容
	GetContent() template.HTML                    // 获取内容
}