mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-02-03 02:54:41 +08:00
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
// Package view
|
|
// @Link https://github.com/bufanyun/hotgo
|
|
// @Copyright Copyright (c) 2023 HotGo CLI
|
|
// @Author Ms <133814250@qq.com>
|
|
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
|
package view
|
|
|
|
import (
|
|
"hotgo/internal/consts"
|
|
|
|
"github.com/gogf/gf/v2/net/ghttp"
|
|
"github.com/gogf/gf/v2/os/gtime"
|
|
"github.com/gogf/gf/v2/text/gstr"
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
"github.com/gogf/gf/v2/util/gmode"
|
|
)
|
|
|
|
// 视图自定义方法管理对象
|
|
type viewBuildIn struct {
|
|
httpRequest *ghttp.Request
|
|
}
|
|
|
|
// Page 创建分页HTML内容
|
|
func (s *viewBuildIn) Page(total, size int) string {
|
|
page := s.httpRequest.GetPage(total, size)
|
|
page.LinkStyle = "page-link"
|
|
page.SpanStyle = "page-link"
|
|
page.PrevPageTag = "«"
|
|
page.NextPageTag = "»"
|
|
content := page.PrevPage() + page.PageBar() + page.NextPage()
|
|
content = gstr.ReplaceByMap(content, map[string]string{
|
|
"<span": "<li class=\"page-item disabled\"><span",
|
|
"/span>": "/span></li>",
|
|
"<a": "<li class=\"page-item\"><a",
|
|
"/a>": "/a></li>",
|
|
})
|
|
return content
|
|
}
|
|
|
|
// UrlPath 获取当前页面的Url Path.
|
|
func (s *viewBuildIn) UrlPath() string {
|
|
return s.httpRequest.URL.Path
|
|
}
|
|
|
|
// Version 随机数 开发环境时间戳,线上为前端版本号
|
|
func (s *viewBuildIn) Version() string {
|
|
var rand string
|
|
if gmode.IsDevelop() {
|
|
rand = gconv.String(gtime.TimestampMilli())
|
|
} else {
|
|
rand = consts.VersionApp
|
|
}
|
|
return rand
|
|
}
|