选中文字自动搜索快捷回复

pull/23/head
taoshihan1991 4 years ago
parent 271973dd1a
commit eae22546b6

@ -76,3 +76,20 @@ func DelReplyGroup(c *gin.Context) {
"msg": "ok",
})
}
func PostReplySearch(c *gin.Context) {
kefuId, _ := c.Get("kefu_name")
search := c.PostForm("search")
if search == "" {
c.JSON(400, gin.H{
"code": 200,
"msg": "参数错误",
})
return
}
res := models.FindReplyBySearcch(kefuId, search)
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
"result": res,
})
}

@ -53,3 +53,24 @@ func DeleteReplyGroup(id string, userId string) {
DB.Where("user_id = ? and id = ?", userId, id).Delete(ReplyGroup{})
DB.Where("user_id = ? and group_id = ?", userId, id).Delete(ReplyItem{})
}
func FindReplyBySearcch(userId interface{}, search string) []*ReplyGroup {
var replyGroups []*ReplyGroup
var replyItems []*ReplyItem
DB.Where("user_id = ?", userId).Find(&replyGroups)
DB.Where("user_id = ? and content like ?", userId, "%"+search+"%").Find(&replyItems)
temp := make(map[string]*ReplyGroup)
for _, replyGroup := range replyGroups {
replyGroup.Items = make([]*ReplyItem, 0)
temp[replyGroup.Id] = replyGroup
}
for _, replyItem := range replyItems {
temp[replyItem.GroupId].Items = append(temp[replyItem.GroupId].Items, replyItem)
}
var newReplyGroups []*ReplyGroup = make([]*ReplyGroup, 0)
for _, replyGroup := range replyGroups {
if len(replyGroup.Items) != 0 {
newReplyGroups = append(newReplyGroups, replyGroup)
}
}
return newReplyGroups
}

@ -88,8 +88,9 @@ func InitApiRouter(engine *gin.Engine) {
engine.GET("/replys", middleware.JwtApiMiddleware, controller.GetReplys)
engine.POST("/reply", middleware.JwtApiMiddleware, controller.PostReply)
engine.POST("/reply_content", middleware.JwtApiMiddleware, controller.PostReplyContent)
engine.DELETE("/reply_content", middleware.JwtApiMiddleware, controller.DelReplyContent)
engine.DELETE("/reply", middleware.JwtApiMiddleware, controller.DelReplyGroup)
engine.DELETE("/reply_content", middleware.JwtApiMiddleware, middleware.RbacAuth, controller.DelReplyContent)
engine.DELETE("/reply", middleware.JwtApiMiddleware, middleware.RbacAuth, controller.DelReplyGroup)
engine.POST("/reply_search", middleware.JwtApiMiddleware, controller.PostReplySearch)
//微信接口
engine.GET("/micro_program", middleware.JwtApiMiddleware, controller.GetCheckWeixinSign)
}

@ -380,6 +380,10 @@
.replyContent{
padding: 0 10px;
}
.replySearch{
margin: 5px 7px;
width: 96% !important;
}
.iconBtnsBox{
position: relative;
margin-top: 4px;

@ -201,6 +201,9 @@
<div class="chatRightTitle">快捷回复
<a href="javascript:void(0);" @click="replyGroupDialog = true">+添加分组</a>
</div>
<el-input placeholder="选中文字自动搜索" v-model="replySearch" class="replySearch" @keyup.enter="searchReply">
<el-button slot="append" icon="el-icon-search" @click="searchReply"></el-button>
</el-input>
<div class="replyContent">
<el-collapse>
<el-collapse-item v-for="reply in replys" :key="reply.group_id" :title="reply.group_name" :name="reply.group_id">

@ -39,6 +39,7 @@ var app=new Vue({
otherKefus:[],
replyGroupDialog:false,
replyContentDialog:false,
replySearch:"",
groupName:"",
groupId:"",
replys:[],
@ -662,6 +663,13 @@ var app=new Vue({
_this.getReplys();
});
},
//搜索回复
searchReply(){
var _this=this;
this.sendAjax("/reply_search","post",{search:this.replySearch},function(result){
_this.replys=result;
});
},
//获取黑名单
getIpblacks(){
var _this=this;
@ -678,6 +686,30 @@ var app=new Vue({
});
});
},
//划词搜索
selectText(){
var _this=this;
$('body').click(function(){
try{
var selecter = window.getSelection().toString();
if (selecter != null && selecter.trim() != ""){
_this.replySearch=selecter.trim();
_this.searchReply();
}else{
_this.replySearch="";
}
} catch (err){
var selecter = document.selection.createRange();
var s = selecter.text;
if (s != null && s.trim() != ""){
_this.replySearch=s.trim();
_this.searchReply();
}else{
_this.replySearch="";
}
}
});
},
sendAjax(url,method,params,callback){
let _this=this;
$.ajax({
@ -722,6 +754,7 @@ var app=new Vue({
this.getOnlineVisitors();
this.getReplys();
this.getIpblacks();
this.selectText();
//心跳
this.ping();
}

Loading…
Cancel
Save