common.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package tmpl
  2. import (
  3. "git.wanbits.cc/sin/flytalk/config"
  4. "git.wanbits.cc/sin/flytalk/g"
  5. "git.wanbits.cc/sin/flytalk/tools"
  6. "github.com/gin-gonic/gin"
  7. "html/template"
  8. "net/http"
  9. )
  10. type CommonHtml struct {
  11. Header template.HTML
  12. Nav template.HTML
  13. Left template.HTML
  14. Bottom template.HTML
  15. Rw http.ResponseWriter
  16. }
  17. func NewRender(rw http.ResponseWriter) *CommonHtml {
  18. obj := new(CommonHtml)
  19. obj.Rw = rw
  20. header := tools.FileGetContent("html/header.html")
  21. nav := tools.FileGetContent("html/nav.html")
  22. obj.Header = template.HTML(header)
  23. obj.Nav = template.HTML(nav)
  24. return obj
  25. }
  26. func (obj *CommonHtml) SetLeft(file string) {
  27. leftStr := tools.FileGetContent("html/" + file + ".html")
  28. obj.Left = template.HTML(leftStr)
  29. }
  30. func (obj *CommonHtml) SetBottom(file string) {
  31. str := tools.FileGetContent("html/" + file + ".html")
  32. obj.Bottom = template.HTML(str)
  33. }
  34. func (obj *CommonHtml) Display(file string, data interface{}) {
  35. if data == nil {
  36. data = obj
  37. }
  38. main := tools.FileGetContent("html/" + file + ".html")
  39. t, _ := template.New(file).Parse(main)
  40. t.Execute(obj.Rw, data)
  41. }
  42. //首页
  43. func PageIndex(c *gin.Context) {
  44. if c.Request.RequestURI == "/favicon.ico" {
  45. return
  46. }
  47. ilang, _ := c.Get("lang")
  48. lang := ilang.(string)
  49. c.HTML(http.StatusOK, "index.html", gin.H{
  50. "OnlineChat": g.T("chat_entry", lang),
  51. "Notice": g.T("notice", lang),
  52. "NowAsk": g.T("start_chat", lang),
  53. "LaterAsk": g.T("chat_later", lang),
  54. "Lang": lang,
  55. "Title": g.T("title", lang),
  56. "Keywords": g.T("keywords", lang),
  57. "Desc": g.T("description", lang),
  58. "Copyright": g.T("copyright", lang),
  59. "MainTech": g.T("main_tech", lang),
  60. "DocEntry": g.T("doc_entry", lang),
  61. "VisitorsEntry": g.T("visitors_entry", lang),
  62. "AgentsEntry": g.T("agents_entry", lang),
  63. "ChatEntry": g.T("chat_entry", lang),
  64. "ProjectTitle": g.T("project_title", lang),
  65. "ProjectDesc": g.T("project_desc", lang),
  66. "Version": config.VERSION,
  67. })
  68. }
  69. //登陆界面
  70. func PageMain(c *gin.Context) {
  71. nav := tools.FileGetContent("html/nav.html")
  72. c.HTML(http.StatusOK, "main.html", gin.H{
  73. "Nav": template.HTML(nav),
  74. })
  75. }
  76. //客服界面
  77. func PageChatMain(c *gin.Context) {
  78. c.HTML(http.StatusOK, "chat_main.html", nil)
  79. }