You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-fly/tmpl/common.go

56 lines
1.3 KiB

package tmpl
import (
4 years ago
"github.com/gin-gonic/gin"
"github.com/taoshihan1991/imaptool/tools"
"html/template"
"net/http"
)
4 years ago
type CommonHtml struct {
Header template.HTML
Nav template.HTML
Left template.HTML
Bottom template.HTML
Rw http.ResponseWriter
}
4 years ago
func NewRender(rw http.ResponseWriter) *CommonHtml {
obj := new(CommonHtml)
obj.Rw = rw
header := tools.FileGetContent("html/header.html")
nav := tools.FileGetContent("html/nav.html")
4 years ago
obj.Header = template.HTML(header)
obj.Nav = template.HTML(nav)
return obj
}
4 years ago
func (obj *CommonHtml) SetLeft(file string) {
leftStr := tools.FileGetContent("html/" + file + ".html")
obj.Left = template.HTML(leftStr)
}
4 years ago
func (obj *CommonHtml) SetBottom(file string) {
str := tools.FileGetContent("html/" + file + ".html")
obj.Bottom = template.HTML(str)
}
4 years ago
func (obj *CommonHtml) Display(file string, data interface{}) {
if data == nil {
data = obj
5 years ago
}
4 years ago
main := tools.FileGetContent("html/" + file + ".html")
t, _ := template.New(file).Parse(main)
t.Execute(obj.Rw, data)
4 years ago
}
//登陆界面
func PageMain(c *gin.Context) {
nav := tools.FileGetContent("html/nav.html")
c.HTML(http.StatusOK, "main.html", gin.H{
"Nav": template.HTML(nav),
})
}
//客服界面
func PageChatMain(c *gin.Context) {
c.HTML(http.StatusOK, "chat_main.html", nil)
}