英文版聊天页

pull/30/head
taoshihan1991 4 years ago
parent 6e404ddb93
commit 587a336cc7

@ -15,6 +15,7 @@ const Dir = "config/"
const AccountConf = Dir + "account.json" const AccountConf = Dir + "account.json"
const MysqlConf = Dir + "mysql.json" const MysqlConf = Dir + "mysql.json"
const MailConf = Dir + "mail.json" const MailConf = Dir + "mail.json"
const LangConf=Dir+"language.json"
type Mysql struct{ type Mysql struct{
Server string Server string
Port string Port string

@ -1,11 +1,16 @@
package config package config
type Language struct { type Language struct {
WebCopyRight string WebCopyRight string
MainIntro string MainIntro string
IndexSubIntro,IndexVisitors,IndexAgent,IndexDocument string Send string
Notice string
IndexSubIntro,IndexVisitors,IndexAgent,IndexDocument,IndexOnlineChat string
} }
func CreateLanguage(lang string)*Language{ func CreateLanguage(lang string)*Language{
var language *Language var language *Language
if lang=="en"{ if lang=="en"{
language=&Language{ language=&Language{
WebCopyRight: "TaoShihan", WebCopyRight: "TaoShihan",
@ -14,6 +19,9 @@ func CreateLanguage(lang string)*Language{
IndexDocument:"API Documents", IndexDocument:"API Documents",
IndexVisitors:"Visitors Here", IndexVisitors:"Visitors Here",
IndexAgent:"Agents Here", IndexAgent:"Agents Here",
IndexOnlineChat:"Lets chat. - We're online",
Send:"Send",
Notice:"Hello and welcome to go-fly - how can we help?",
} }
} }
if lang=="cn"{ if lang=="cn"{
@ -24,6 +32,9 @@ func CreateLanguage(lang string)*Language{
IndexVisitors:"访客入口", IndexVisitors:"访客入口",
IndexAgent:"客服入口", IndexAgent:"客服入口",
IndexDocument:"接口文档", IndexDocument:"接口文档",
IndexOnlineChat:"在线咨询",
Send:"发送",
Notice:"欢迎您访问go-fly有什么我能帮助您的",
} }
} }
return language return language

@ -0,0 +1,20 @@
{
"En":{
"WebCopyRight": "TaoShihan",
"MainIntro": "Simple and Powerful Go language online customer chat system",
"IndexSubIntro": "GO-FLY, a Vue 2.0-based online customer service instant messaging system for PHP engineers and Golang engineers",
"IndexDocument":"API Documents",
"IndexVisitors":"Visitors Here",
"IndexAgent":"Agents Here",
"IndexOnlineChat":"Lets chat. - We're online"
},
"Cn":{
"WebCopyRight": "陶士涵的菜地版权所有",
"MainIntro":"极简强大的Go语言在线客服系统",
"IndexSubIntro":"GO-FLY一套为PHP工程师、Golang工程师准备的基于 Vue 2.0的在线客服即时通讯系统",
"IndexVisitors":"访客入口",
"IndexAgent":"客服入口",
"IndexDocument":"接口文档",
"IndexOnlineChat":"在线咨询"
}
}

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"github.com/taoshihan1991/imaptool/config"
"github.com/taoshihan1991/imaptool/models" "github.com/taoshihan1991/imaptool/models"
"github.com/taoshihan1991/imaptool/tools" "github.com/taoshihan1991/imaptool/tools"
"log" "log"
@ -12,12 +13,15 @@ import (
) )
func GetNotice(c *gin.Context) { func GetNotice(c *gin.Context) {
kefuId:=c.Query("kefu_id") kefuId:=c.Query("kefu_id")
lang,_:=c.Get("lang")
language:=config.CreateLanguage(lang.(string))
user:=models.FindUser(kefuId) user:=models.FindUser(kefuId)
info:=make(map[string]interface{}) info:=make(map[string]interface{})
info["nickname"]=user.Nickname info["nickname"]=user.Nickname
info["avator"]=user.Avator info["avator"]=user.Avator
info["name"]=user.Name info["name"]=user.Name
info["content"]="欢迎您!有什么我能帮助您的?" info["content"]=language.Notice
info["time"]=time.Now().Format("2006-01-02 15:04:05") info["time"]=time.Now().Format("2006-01-02 15:04:05")
c.JSON(200, gin.H{ c.JSON(200, gin.H{
"code": 200, "code": 200,

@ -34,7 +34,7 @@ func main() {
//登陆界面 //登陆界面
engine.GET("/login", tmpl.PageLogin) engine.GET("/login", tmpl.PageLogin)
//咨询界面 //咨询界面
engine.GET("/chat_page", tmpl.PageChat) engine.GET("/chat_page",middleware.SetLanguage, tmpl.PageChat)
//登陆验证 //登陆验证
engine.POST("/check", controller.LoginCheckPass) engine.POST("/check", controller.LoginCheckPass)
//框架界面 //框架界面
@ -82,7 +82,7 @@ func main() {
engine.GET("/setting_kefu_list",tmpl.PageKefuList) engine.GET("/setting_kefu_list",tmpl.PageKefuList)
//前台接口 //前台接口
engine.GET("/notice", controller.GetNotice) engine.GET("/notice",middleware.SetLanguage, controller.GetNotice)
//前台引入js接口 //前台引入js接口
engine.GET("/webjs", tmpl.PageWebJs) engine.GET("/webjs", tmpl.PageWebJs)
//前台引入css接口 //前台引入css接口

@ -0,0 +1,14 @@
package middleware
import (
"github.com/gin-gonic/gin"
)
func SetLanguage(c *gin.Context){
lang := c.Query("lang")
if lang == "" ||lang!="cn"{
lang = "en"
}
c.Set("lang",lang)
}

@ -109,7 +109,7 @@
</div> </div>
<div class="chatBoxSend"> <div class="chatBoxSend">
<el-input type="textarea" class="chatArea" v-model="messageContent" v-on:keyup.enter.native="chatToUser"></el-input> <el-input type="textarea" class="chatArea" v-model="messageContent" v-on:keyup.enter.native="chatToUser"></el-input>
<el-button type="primary" class="chatBoxSendBtn" size="small" v-on:click="chatToUser">发送</el-button> <el-button type="primary" class="chatBoxSendBtn" size="small" v-on:click="chatToUser">{{.SendBtn}}</el-button>
</div> </div>
<!--//客服代码--> <!--//客服代码-->
@ -294,7 +294,7 @@
//获取自动欢迎语句 //获取自动欢迎语句
getNotice : function (){ getNotice : function (){
let _this=this; let _this=this;
$.get("/notice?kefu_id="+guest.to_id,function(res) { $.get("/notice?kefu_id="+guest.to_id+"&lang={{.Lang}}",function(res) {
console.log(res); console.log(res);
if (res.result != null) { if (res.result != null) {
let msg = res.result; let msg = res.result;

@ -115,7 +115,11 @@
<p>{{.SubIntro}}</p> <p>{{.SubIntro}}</p>
</div> </div>
<div class="jumbotron"> <div class="jumbotron">
{{if eq .Lang "en"}}
<img src="/static/images/intro3.png"/>
{{else}}
<img src="/static/images/intro1.jpg"/> <img src="/static/images/intro1.jpg"/>
{{end}}
</div> </div>
<footer class="footer"> <footer class="footer">
@ -132,12 +136,12 @@
$("#visitorBtn").click(function(){ $("#visitorBtn").click(function(){
layer.open({ layer.open({
type: 2, type: 2,
title: '在线咨询', title: '{{.OnlineChat}}',
shadeClose: true, shadeClose: true,
shade: false, shade: false,
maxmin: true, //开启最大化最小化按钮 maxmin: true, //开启最大化最小化按钮
area: ['550px', '520px'], area: ['550px', '520px'],
content: ['/chat_page','no'], content: ['/chat_page?lang={{.Lang}}','no'],
end: function(){ end: function(){
$(".chatBtn").show(); $(".chatBtn").show();
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

@ -55,6 +55,8 @@ func PageIndex(c *gin.Context) {
"Document":language.IndexDocument, "Document":language.IndexDocument,
"VisitorBtn":language.IndexVisitors, "VisitorBtn":language.IndexVisitors,
"AgentBtn":language.IndexAgent, "AgentBtn":language.IndexAgent,
"OnlineChat":language.IndexOnlineChat,
"IndexSend":language.Send,
"Lang":lang, "Lang":lang,
}) })
} }

@ -2,6 +2,7 @@ package tmpl
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/taoshihan1991/imaptool/config"
"net/http" "net/http"
) )
@ -13,8 +14,12 @@ func PageLogin(c *gin.Context) {
//咨询界面 //咨询界面
func PageChat(c *gin.Context) { func PageChat(c *gin.Context) {
kefuId := c.Query("kefu_id") kefuId := c.Query("kefu_id")
lang,_ := c.Get("lang")
language:=config.CreateLanguage(lang.(string))
c.HTML(http.StatusOK, "chat_page.html", gin.H{ c.HTML(http.StatusOK, "chat_page.html", gin.H{
"KEFU_ID":kefuId, "KEFU_ID":kefuId,
"SendBtn":language.Send,
"Lang":lang.(string),
}) })
} }

Loading…
Cancel
Save