clean and setting

master
taoshihan 1 month ago
parent 107e7fda74
commit 1b7de01e69

@ -78,8 +78,6 @@ func GetKefuInfo(c *gin.Context) {
kefuName, _ := c.Get("kefu_name")
user := models.FindUser(kefuName.(string))
info := make(map[string]interface{})
info["name"] = user.Nickname
info["id"] = user.Name
info["avator"] = user.Avator
info["username"] = user.Name
info["nickname"] = user.Nickname
@ -162,6 +160,7 @@ func GetKefuInfoSetting(c *gin.Context) {
func PostKefuRegister(c *gin.Context) {
name := c.PostForm("username")
password := c.PostForm("password")
nickname := c.PostForm("nickname")
avatar := "/static/images/4.jpg"
if name == "" || password == "" {
@ -183,7 +182,7 @@ func PostKefuRegister(c *gin.Context) {
return
}
userID := models.CreateUser(name, tools.Md5(password), avatar, "")
userID := models.CreateUser(name, tools.Md5(password), avatar, nickname)
if userID == 0 {
c.JSON(http.StatusInternalServerError, gin.H{
"code": 500,

@ -22,11 +22,11 @@ func GetNotice(c *gin.Context) {
"code": 200,
"msg": "ok",
"result": gin.H{
"welcome": welcomeMessage,
"offline": offlineMessage,
"welcome": welcomeMessage.ConfValue,
"offline": offlineMessage.ConfValue,
"avatar": user.Avator,
"nickname": user.Nickname,
"allNotice": allNotice,
"allNotice": allNotice.ConfValue,
},
})
}

@ -6,7 +6,8 @@ import (
)
func GetConfigs(c *gin.Context) {
configs := models.FindConfigs()
kefuName, _ := c.Get("kefu_name")
configs := models.FindConfigsByUserId(kefuName)
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
@ -25,6 +26,7 @@ func GetConfig(c *gin.Context) {
func PostConfig(c *gin.Context) {
key := c.PostForm("key")
value := c.PostForm("value")
kefuName, _ := c.Get("kefu_name")
if key == "" || value == "" {
c.JSON(200, gin.H{
"code": 400,
@ -32,7 +34,7 @@ func PostConfig(c *gin.Context) {
})
return
}
models.UpdateConfig(key, value)
models.UpdateConfig(kefuName, key, value)
c.JSON(200, gin.H{
"code": 200,

@ -147,7 +147,7 @@ func getGetuiToken() string {
json.Unmarshal([]byte(res), &pushRes)
if pushRes.Code == 0 {
token := pushRes.Data["token"].(string)
models.UpdateConfig("GetuiToken", token)
//models.UpdateConfig("GetuiToken", token)
return token
}
}

@ -139,7 +139,7 @@ func PostVisitorLogin(c *gin.Context) {
//各种通知
go SendNoticeEmail(visitor.Name, " incoming!")
go SendAppGetuiPush(kefuInfo.Name, visitor.Name, visitor.Name+" incoming!")
//go SendAppGetuiPush(kefuInfo.Name, visitor.Name, visitor.Name+" incoming!")
go SendVisitorLoginNotice(kefuInfo.Name, visitor.Name, visitor.Avator, visitor.Name+" incoming!", visitor.VisitorId)
go ws.VisitorOnline(kefuInfo.Name, visitor)
//go SendServerJiang(visitor.Name, "来了", c.Request.Host)

@ -71,7 +71,8 @@ CREATE TABLE `config` (
`conf_value` varchar(255) NOT NULL DEFAULT '',
`user_id` varchar(500) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
UNIQUE KEY `conf_key` (`conf_key`)
KEY `conf_key` (`conf_key`),
KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`, `user_id`) VALUES
(NULL, 'Announcement', 'AllNotice', 'Open source customer support system at your service','agent');

@ -50,5 +50,4 @@ func UpdateAbout(page string, title_cn string, title_en string, keywords_cn stri
HtmlEn: html_en,
}
DB.Model(c).Where("page = ?", page).Update(c)
InitConfig()
}

@ -10,21 +10,34 @@ type Config struct {
UserId string `json:"user_id"`
}
func UpdateConfig(key string, value string) {
c := &Config{
ConfValue: value,
func UpdateConfig(userid interface{}, key string, value string) {
config := FindConfigByUserId(userid, key)
if config.ID != 0 {
config.ConfValue = value
DB.Where("user_id = ? and conf_key = ?", userid, key).Update(config)
} else {
newConfig := &Config{
ID: 0,
ConfName: "",
ConfKey: key,
ConfValue: value,
UserId: userid.(string),
}
DB.Create(newConfig)
}
DB.Model(c).Where("conf_key = ?", key).Update(c)
InitConfig()
}
func FindConfigs() []Config {
var config []Config
DB.Find(&config)
return config
}
func InitConfig() {
CustomConfigs = FindConfigs()
func FindConfigsByUserId(userid interface{}) []Config {
var config []Config
DB.Where("user_id = ?", userid).Find(&config)
return config
}
func FindConfig(key string) string {
for _, config := range CustomConfigs {
if key == config.ConfKey {
@ -33,11 +46,8 @@ func FindConfig(key string) string {
}
return ""
}
func FindConfigByUserId(userId, key string) string {
for _, config := range CustomConfigs {
if key == config.ConfKey && config.UserId == userId {
return config.ConfValue
}
}
return ""
func FindConfigByUserId(userId interface{}, key string) Config {
var config Config
DB.Where("user_id = ? and conf_key = ?", userId, key).Find(&config)
return config
}

@ -35,7 +35,6 @@ func Connect() error {
DB.DB().SetMaxIdleConns(10)
DB.DB().SetMaxOpenConns(100)
DB.DB().SetConnMaxLifetime(59 * time.Second)
InitConfig()
return nil
}
func Execute(sql string) error {

@ -72,6 +72,9 @@
<el-form-item prop="account">
<el-input v-model="form.account" placeholder="Choose a username"></el-input>
</el-form-item>
<el-form-item prop="nickname">
<el-input v-model="form.nickname" placeholder="Create a display name"></el-input>
</el-form-item>
<el-form-item prop="password">
<el-input show-password v-model="form.password" placeholder="Create a password"></el-input>
</el-form-item>
@ -99,13 +102,18 @@
form: {
account: "",
password: "",
rePassword: ""
rePassword: "",
nickname:"",
},
rules: {
account: [
{ required: true, message: 'Username is required', trigger: 'blur' },
{ min: 2, max: 20, message: 'Username must be 2-20 characters', trigger: 'blur' }
],
nickname: [
{ required: true, message: 'DisplayName is required', trigger: 'blur' },
{ min: 1, max: 60, message: 'DisplayName must be 1-60 characters', trigger: 'blur' }
],
password: [
{ required: true, message: 'Password is required', trigger: 'blur' },
{ min: 2, message: 'Password must be at least 2 characters', trigger: 'blur' }
@ -182,6 +190,7 @@
let data = {
"username": this.form.account,
"password": this.form.password,
"nickname": this.form.nickname,
};
$.post("/register", data, (response) => {

@ -79,7 +79,7 @@
</div>
</body>
<script src="/static/js/echarts.min.js?v=1.0.0"></script>
<script>
const ACTION="pannel";
</script>

@ -73,7 +73,7 @@
<div class="profile-form">
<h3 class="form-title">Profile Settings</h3>
<el-form :model="modifyPass" label-width="180px" label-position="left">
<el-form label-width="180px" label-position="left">
<el-form-item label="Username">
<el-input v-model="kefuInfo.username" placeholder="Enter your username"></el-input>
</el-form-item>
@ -126,11 +126,7 @@
prop="conf_name"
label="Parameter Name">
</el-table-column>
<el-table-column
prop="conf_key"
label="Configuration Key"
width="180">
</el-table-column>
<el-table-column
prop="id"
label="Value">

@ -10,58 +10,12 @@
delimiters:["<{","}>"],
data: {
host:getBaseUrl(),
iframeUrl:"/setting_statistics",
fullscreenLoading:false,
kefuInfo:{},
openIndex:[1],
account: {
username: "",
password: "",
},
mysql: {
server: "",
port: "",
database: "",
username: "",
password: "",
},
rules: {
server: [
{ required: true, message: '请输入服务地址', trigger: 'blur' },
],
port: [
{ required: true, message: '请输入端口号', trigger: 'blur' },
],
database: [
{ required: true, message: '请输入数据库名', trigger: 'blur' },
],
username: [
{ required: true, message: '请输入用户名', trigger: 'blur' },
],
name: [
{ required: true, message: '请输入用户名', trigger: 'blur' },
],
avator: [
{ required: true, message: '请选择头像', trigger: 'blur' },
],
role_id: [
{ required: true, message: '请选择角色', trigger: 'blur' },
],
password: [
{ required: true, message: '请输入密码', trigger: 'blur' },
],
nickname: [
{ required: true, message: '请输入昵称', trigger: 'blur' },
],
method: [
{ required: true, message: '请输入允许的方法', trigger: 'blur' },
],
path: [
{ required: true, message: '请输入允许的路径', trigger: 'blur' },
],
},
kefuList:[],
kefuDialog:false,
kefuForm:{
id:"",
name:"",
@ -71,175 +25,58 @@
role_name:"",
role_id:"",
},
roleList:[],
configList:[],
roleDialog:false,
noticeList:[],
welcomeDialog:false,
ipblackList:[],
welcomeForm: {
content: "",
},
roleForm:{
id:"",
name:"",
method:"",
path:"",
},
statistics:{},
pageindex: {
title_cn: "",
title_en: "",
keywords_cn: "",
keywords_en: "",
desc_cn: "",
desc_en: "",
css_js: "",
html_cn: "",
html_en: "",
},
aboutpages:[],
modifyPass:{
old_pass:"",
new_pass:"",
confirm_new_pass:""
},
avatarUrl:"",
chatEndpoint: "",
configList:[
{
"conf_name": "Announcement",
"conf_key": "AllNotice",
"conf_value":"",
},
{
"conf_name": "Offline Message",
"conf_key": "OfflineMessage",
"conf_value":"",
},
{
"conf_name": "Welcome Message",
"conf_key": "WelcomeMessage",
"conf_value":"",
},
{
"conf_name": "Email Address (SMTP)",
"conf_key": "NoticeEmailSmtp",
"conf_value":"",
},
{
"conf_name": "Email Account",
"conf_key": "NoticeEmailAddress",
"conf_value":"",
},
{
"conf_name": "Email Password (SMTP)",
"conf_key": "NoticeEmailPassword",
"conf_value":"",
}
],
},
methods: {
//提交表单
setAccount(formName){
let _this=this;
this.$refs[formName].validate((valid) => {
if (valid) {
$.post("/setting_account",_this.account,function(data){
if(data.code==200){
_this.$message({
message: data.msg,
type: 'success'
});
}else{
_this.$message({
message: data.msg,
type: 'error'
});
}
});
} else {
return false;
}
});
},
//设置mysql
setMysql(formName){
let _this=this;
this.$refs[formName].validate((valid) => {
if (valid) {
$.ajax({
type:"POST",
url:"/mysql",
data:_this.mysql,
headers:{
"token":localStorage.getItem("token")
},
success: function(data) {
if(data.code==200){
_this.$message({
message: data.msg,
type: 'success'
});
}else{
_this.$message({
message: data.msg,
type: 'error'
});
}
}
});
} else {
return false;
}
});
},
//重置表单
resetForm(formName) {
this.loading=false;
this.$refs[formName].resetFields();
},
//跳转
openUrl(url){
//window.location.href=url;
this.iframeUrl=url;
},
//展示提示
showNotice(){
this.fullscreenLoading=false;
this.$message({
message: '配置信息写入同级config目录目录不存在会自动创建',
type: 'warning',
duration:'8000',
showClose:true,
});
},
addWelcome(){
this.welcomeForm.content="";
this.welcomeDialog=true;
},
//初始化数据
initInfo(){
let _this=this;
if(ACTION=="setting_kefu_list"){
this.sendAjax("/kefulist","get",{},function(result){
_this.kefuList=result;
});
this.sendAjax("/roles","get",{},function(result){
_this.roleList=result;
});
}
if(ACTION=="roles_list"){
this.sendAjax("/roles","get",{},function(result){
_this.roleList=result;
});
}
if(ACTION=="setting_statistics"){
this.sendAjax("/statistics","get",{},function(result) {
_this.statistics = result;
});
}
if(ACTION=="setting_welcome"){
this.sendAjax("/notices","get",{},function(result){
_this.noticeList=result;
});
}
if(ACTION=="setting_ipblack"){
this.sendAjax("/ipblacks_all","get",{},function(result){
_this.ipblackList=result.list;
});
}
this.sendAjax("/configs","get",{},function(result){
_this.configList=result;
});
if(ACTION=="setting_pageindex"){
this.sendAjax("/about","get",{},function(result){
_this.pageindex=result;
});
}
if(ACTION=="setting_indexpages"){
this.sendAjax("/aboutpages","get",{},function(result){
_this.aboutpages=result;
});
}
if(ACTION=="setting_avator"){
this.sendAjax("/kefuinfo","get",{},function(result){
_this.kefuInfo=result;
});
}
if(ACTION=="pannel"){
this.showStatistics();
}
this.getConfigList();
},
sendAjax(url,method,params,callback){
let _this=this;
@ -266,175 +103,30 @@
}
});
},
//添加客服的dialog
addKefu(){
this.kefuForm={
id:"",
name:"",
password:"",
avator:"",
};
this.kefuDialog=true;
},
//提交客服表单
submitKefuForm(formName){
let _this=this;
this.$refs[formName].validate((valid) => {
if (valid) {
this.sendAjax("/kefuinfo","POST",_this.kefuForm,function(result){
_this.kefuDialog=false;
_this.$message({
message: "修改后台账户名后,后台需重新登录",
type: 'success'
});
_this.sendAjax("/kefulist","get",{},function(result){
_this.kefuList=result;
});
});
} else {
return false;
}
});
},
//提交欢迎表单
submitWelcomeForm(formName){
getConfigList(){
let _this=this;
this.$refs[formName].validate((valid) => {
if (valid) {
this.sendAjax("/notice","POST",_this.welcomeForm,function(result){
_this.welcomeDialog=false;
_this.sendAjax("/notices","get",{},function(result){
_this.noticeList=result;
});
});
} else {
return false;
}
});
},
//编辑客服表单
editKefuForm(formName){
let _this=this;
this.$refs[formName].validate((valid) => {
if (valid) {
_this.sendAjax("/kefulist","PUT",_this.kefuForm,function(result){
_this.kefuList=result;
});
} else {
return false;
this.sendAjax("/configs","get",{},function(result){
for(let index in _this.configList){
for(let item of result){
if(_this.configList[index]['conf_key']==item['conf_key']){
_this.configList[index]["conf_value"]=item["conf_value"];
}
}
}
});
},
//获取客服
getKefu(kefuId){
let _this=this;
this.sendAjax("/kefuinfo_setting","GET",{kefu_id:kefuId},function(result){
_this.kefuDialog=true;
_this.kefuForm=result;
_this.kefuForm.password="";
});
},
//删除客服
deleteKefu(kefuId){
let _this=this;
this.sendAjax("/kefuinfo?id="+kefuId,"DELETE",{id:kefuId},function(result){
_this.kefuDialog=false;
_this.sendAjax("/kefulist","get",{},function(result){
_this.kefuList=result;
});
});
},
//删除欢迎
deleteWelcome(id){
let _this=this;
this.sendAjax("/notice?id="+id,"DELETE",{id:id},function(result){
_this.kefuDialog=false;
_this.sendAjax("/notices","get",{},function(result){
_this.noticeList=result;
});
});
},
//删除ip
deleteIpblack(ip){
let _this=this;
this.sendAjax("/ipblack?ip="+ip,"DELETE",{ip:ip},function(result){
_this.sendAjax("/ipblacks_all","get",{},function(result){
_this.ipblackList=result.list;
});
});
},
//配置角色权限
showAuthDialog(id,name,method,path){
this.roleForm.id=id
this.roleForm.name=name
this.roleForm.method=method
this.roleForm.path=path
this.roleDialog=true;
},
//设置配置项
setConfigItem(key,value){
let _this=this;
this.sendAjax("/config","POST",{key:key,value:value},function(result){
_this.sendAjax("/configs","get",{},function(result){
_this.configList=result;
_this.$message({
message: "配置成功!",
type: 'success'
});
});
});
},
//设置配置项
setWelcomeItem(id,content){
let _this=this;
this.sendAjax("/notice_save","POST",{id:id,content:content},function(result){
_this.sendAjax("/notices","get",{},function(result){
_this.noticeList=result;
});
});
},
//提交角色表单
submitRoleForm(formName){
let _this=this;
this.$refs[formName].validate((valid) => {
if (valid) {
this.sendAjax("/role","POST",_this.roleForm,function(result){
_this.roleDialog=false;
_this.sendAjax("/roles","get",{},function(result){
_this.roleList=result;
});
_this.$message({
message: result.msg,
type: 'success'
});
});
} else {
return false;
}
});
},
//提交首页表单
setPageIndex(){
let _this=this;
this.sendAjax("/about","POST",this.pageindex,function(result){
_this.getConfigList();
_this.$message({
message: "编辑成功",
message: "success",
type: 'success'
});
});
},
//修改密码
setModifyPass(){
let _this=this;
this.sendAjax("/modifypass","POST",_this.modifyPass,function(result){
_this.$message({
message: "修改成功",
type: 'success'
});
_this.modifyPass.new_pass=_this.modifyPass.old_pass=_this.modifyPass.confirm_new_pass=""
});
},
//修改密码
setUser(){
let _this=this;
this.sendAjax("/kefuinfo","POST",{
@ -468,53 +160,6 @@
}
return isLt2M;
},
//展示图表
showStatistics(){
let _this=this;
this.sendAjax("/kefu/chartStatistics","get",{},function(data) {
var result=data;
var days=[];
var nums=[];
if(result.length<=0){
return;
}
for(var i=result.length-1;i>=0;i--){
days.push(result[i].day);
nums.push(result[i].num)
}
// 基于准备好的dom初始化echarts实例
$(function () {
var myChart = echarts.init($('#visitorNums')[0],null, {
width: document.documentElement.clientWidth,
height: 500
});
// 指定图表的配置项和数据
var option = {
title: {
text: "每日访客接待情况"
},
tooltip: {},
legend: {
data: ['数量']
},
xAxis: {
data: days
},
yAxis: {},
series: [
{
name: 'nums',
type: 'line',
data: nums,
barCategoryGap: '40%',
}
]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
});
});
},
GetRequest() {
var str = location.href
var num = str.indexOf("#");
@ -541,16 +186,14 @@
"token":localStorage.getItem("token")
},
success: function(data) {
if(data.result.username==""){
window.location.href="/login";
}
if(data.code==200 && data.result!=null){
_this.kefuInfo=data.result;
_this.chatEndpoint=window.location.origin + '/livechat?kefu_id='+_this.kefuInfo.username;
}
if(data.code!=200){
_this.$message({
message: data.msg,
type: 'error'
});
}
}
});
},
@ -561,10 +204,12 @@
if(urlParam!=""){
this.iframeUrl=urlParam;
}
},
created: function () {
this.getKefuInfo();
this.initInfo();
},
created: function () {
}
})

@ -1,21 +0,0 @@
{{template "header" }}
<style>
.el-table .cell{
color: #666;
}
</style>
<div id="app" style="width:100%;">
<template>
<el-container v-loading.fullscreen.lock="fullscreenLoading">
<el-main class="mainMain">
</el-table>
</el-main>
</el-container>
</template>
</div>
</body>
{{template "setting_bottom" .}}

@ -171,12 +171,12 @@ func VisitorAutoReply(vistorInfo models.Visitor, kefuInfo models.User, content s
}
if !ok || kefu == nil {
time.Sleep(1 * time.Second)
welcome := models.FindConfigByUserId(kefuInfo.Name, "OfflineMessage")
if welcome == "" || reply.Content != "" {
config := models.FindConfigByUserId(kefuInfo.Name, "OfflineMessage")
if config.ConfValue == "" || reply.Content != "" {
return
}
VisitorMessage(vistorInfo.VisitorId, welcome, kefuInfo)
models.CreateMessage(kefuInfo.Name, vistorInfo.VisitorId, welcome, "kefu")
VisitorMessage(vistorInfo.VisitorId, config.ConfValue, kefuInfo)
models.CreateMessage(kefuInfo.Name, vistorInfo.VisitorId, config.ConfValue, "kefu")
}
}
func CleanVisitorExpire() {

Loading…
Cancel
Save