| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package tmpl
- import (
- "git.wanbits.cc/sin/flytalk/config"
- "git.wanbits.cc/sin/flytalk/models"
- "git.wanbits.cc/sin/flytalk/tools"
- "github.com/gin-gonic/gin"
- "html"
- "html/template"
- "net/http"
- )
- type CommonHtml struct {
- Header template.HTML
- Nav template.HTML
- Left template.HTML
- Bottom template.HTML
- Rw http.ResponseWriter
- }
- func NewRender(rw http.ResponseWriter) *CommonHtml {
- obj := new(CommonHtml)
- obj.Rw = rw
- header := tools.FileGetContent("html/header.html")
- nav := tools.FileGetContent("html/nav.html")
- obj.Header = template.HTML(header)
- obj.Nav = template.HTML(nav)
- return obj
- }
- func (obj *CommonHtml) SetLeft(file string) {
- leftStr := tools.FileGetContent("html/" + file + ".html")
- obj.Left = template.HTML(leftStr)
- }
- func (obj *CommonHtml) SetBottom(file string) {
- str := tools.FileGetContent("html/" + file + ".html")
- obj.Bottom = template.HTML(str)
- }
- func (obj *CommonHtml) Display(file string, data interface{}) {
- if data == nil {
- data = obj
- }
- main := tools.FileGetContent("html/" + file + ".html")
- t, _ := template.New(file).Parse(main)
- t.Execute(obj.Rw, data)
- }
- //首页
- func PageIndex(c *gin.Context) {
- if c.Request.RequestURI == "/favicon.ico" {
- return
- }
- lang, _ := c.Get("lang")
- language := config.CreateLanguage(lang.(string))
- about := models.FindAboutByPageLanguage("index", lang.(string))
- cssJs := html.UnescapeString(about.CssJs)
- title := about.TitleCn
- keywords := about.KeywordsCn
- desc := html.UnescapeString(about.DescCn)
- content := html.UnescapeString(about.HtmlCn)
- if lang == "en" {
- title = about.TitleEn
- keywords = about.KeywordsEn
- desc = html.UnescapeString(about.DescEn)
- content = html.UnescapeString(about.HtmlEn)
- }
- c.HTML(http.StatusOK, "index.html", gin.H{
- "OnlineChat": language.IndexOnlineChat,
- "Notice": language.Notice,
- "NowAsk": language.NowAsk,
- "LaterAsk": language.LaterAsk,
- "Lang": lang,
- "Title": title,
- "Keywords": keywords,
- "Desc": desc,
- "Content": template.HTML(content),
- "CssJs": template.HTML(cssJs),
- })
- }
- //登陆界面
- 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)
- }
|