go-admin UI组件学习一

go-admin UI组件学习一

需要利用go-admin框架编写自定义页面,必须先了解掌握UI组件。初步学习框架UI组件的基本代码框架、基本处理逻辑。

模板 template

主题模板是一套UI的抽象表示,包括一系列组件和静态资源的集合,会在插件中被调用。
主题定义在go-admin/template/template.go中,主要有各组件的获取方法。

type Template interface {
	Name() string

	// Components

	// layout
	Col() types.ColAttribute
	Row() types.RowAttribute

	// form and table
	Form() types.FormAttribute
	Table() types.TableAttribute
	DataTable() types.DataTableAttribute

	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

	// Builder methods
	GetTmplList() map[string]string
	GetAssetList() []string
	GetAssetImportHTML(exceptComponents ...string) template.HTML
	GetAsset(string) ([]byte, error)
	GetTemplate(bool) (*template.Template, string)
	GetVersion() string
	GetRequirements() []string
}

实现是在 themes/adminlte.go,通过Theme结构实现(sword主题同理),还有一部分共用的在common.go实现。

type Theme struct {
	ThemeName string
	components.Base
	common.BaseTheme
}

var Adminlte = Theme{
	ThemeName: "adminlte",
	Base: components.Base{
		Attribute: types.Attribute{
			TemplateList: TemplateList,
		},
	},
}

UI组件

组件定义在go-admin/template/types/components.go。
以col组件为例

type ColAttribute interface {
	SetSize(value S) ColAttribute
	SetContent(value template.HTML) ColAttribute
	AddContent(value template.HTML) ColAttribute
	GetContent() template.HTML
}

实现在go-admin/template/components/col.go,没在themes实现,所以,这些组件是各主题通用的。

type ColAttribute struct {
	Name    string
	Content template.HTML
	Size    string
	types.Attribute
}

func (compo *ColAttribute) SetContent(value template.HTML) types.ColAttribute {
	compo.Content = value
	return compo
}

func (compo *ColAttribute) AddContent(value template.HTML) types.ColAttribute {
	compo.Content += value
	return compo
}

func (compo *ColAttribute) SetSize(value types.S) types.ColAttribute {
	compo.Size = ""
	for key, size := range value {
		compo.Size += "col-" + key + "-" + size + " "
	}
	return compo
}

func (compo *ColAttribute) GetContent() template.HTML {
	return ComposeHtml(compo.TemplateList, *compo, "col")
}

GetContent方法用于根据模板生成html,此方法是关键部分。

GoAdmin 是一个基于 golang 面向生产的数据可视化管理平台搭建框架,可以让你用简短的代码在极短时间内搭建起一个管理后台。

========================================================== \根目录 ├── _blank.html 空白页(每次我们都拿空白页去创建,这样比较干净!) ├── _footer.html 页脚公共代码片段 ├── _header.html 头部公共代码片段 ├── _meta.html meta公共代码片段 ├── robots.txt 搜索引擎爬虫配置文件 ├── login.html 管理员登陆 ├── index.html 首页(主框架) ├── welcome.html 我的桌面(默认永远打开的页面) ├── member-开头的 用户相关 ├── artice-开头的 资讯相关 ├── picture-开头的 图片相关 ├── product-开头的 产品相关 ├── page-开头的 页面相关 ├── system-开头的 系统相关 ├── admin-开头的 管理员相关 ├── charts-开头的 统计相关 …… static/ 资源 ├── h-ui/ H-ui特有资源 │ ├── css/ 样式 │ │ ├── H-ui.css H-ui基础样式 │ │ ├── H-ui.min.css H-ui.css 压缩版 │ │ ├── H-ui.ie.css H-ui.css IE低版本兼容补丁 │ ├── images/ 图片资源 │ ├── js/ │ │ ├── H-ui.js H-ui核心脚本 ├── h-ui.admin/ H-ui.admin核心资源 │ ├── css/ 样式 │ │ ├── H-ui.login.css 后台管理员登录页样式 │ │ ├── H-ui.admin.css 后台界面主要样式 │ ├── images/ 图片资源 │ ├── js/ │ │ ├── H-ui.admin.js 后台管理核心脚本 │ ├── skin/ 皮肤资源 │ │ ├── blue 蓝色 │ │ ├── default 黑色(默认) │ │ ├── green 绿色 │ │ ├── orange 橙色 │ │ ├── red 红色 │ │ ├── yellow 黄色 Lib/ 第三方插件 ├── jquery jQuery类库(v1.9.1) ├── Hui-iconfont 阿里图标字体库(H-ui定制) ├── jquery.SuperSlide 幻灯片组件 ├── Validform 表单验证插件 ├── jquery.validation 表单验证插件 ├── My97DatePicker 日期插件 ├── datatables 表格插件 ├── nprogress 进度条插件 ├── layer layer弹出层插件 ├── laypage laypage 翻页插件 ├── jquery.contextmenu 右键菜单插件 ├── ueditor 百度编辑器 ├── Highcharts 图表插件 ├── echarts 百度图标插件 ├── datatables 表格排序,检索插件 ├── WebUploader 百度文件上传组件 ├── lightbox2 图片预览组件 ├── html5shiv.js html5插件,让低版本IE支持html5元素 ├── DD_belatedPNG_0.0.8a-min.js 解决IE6png透明 ├── swfobject.js Flash插件 ├── expressInstall.swf 检查flash插件 ├── respond.min.js 让IE兼容media ├── colpick.js 颜色插件 └─temp 测试数据、图片
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值