From eae22546b6de3877607a220c22ffab0e23b898db Mon Sep 17 00:00:00 2001 From: taoshihan1991 <630892807@qq.com> Date: Tue, 12 Jan 2021 13:51:53 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=89=E4=B8=AD=E6=96=87=E5=AD=97=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=90=9C=E7=B4=A2=E5=BF=AB=E6=8D=B7=E5=9B=9E=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/reply.go | 17 +++++++++++++++++ models/replys.go | 21 +++++++++++++++++++++ router/api.go | 5 +++-- static/css/common.css | 4 ++++ static/html/chat_main.html | 3 +++ static/js/chat-main.js | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 81 insertions(+), 2 deletions(-) diff --git a/controller/reply.go b/controller/reply.go index fe7625e..c742a92 100644 --- a/controller/reply.go +++ b/controller/reply.go @@ -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, + }) +} diff --git a/models/replys.go b/models/replys.go index 9dd98bc..103e76b 100644 --- a/models/replys.go +++ b/models/replys.go @@ -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 +} diff --git a/router/api.go b/router/api.go index 78a7534..20c7a7b 100644 --- a/router/api.go +++ b/router/api.go @@ -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) } diff --git a/static/css/common.css b/static/css/common.css index 6171eb8..259129a 100644 --- a/static/css/common.css +++ b/static/css/common.css @@ -380,6 +380,10 @@ .replyContent{ padding: 0 10px; } +.replySearch{ + margin: 5px 7px; + width: 96% !important; +} .iconBtnsBox{ position: relative; margin-top: 4px; diff --git a/static/html/chat_main.html b/static/html/chat_main.html index ea1d38f..483b62f 100644 --- a/static/html/chat_main.html +++ b/static/html/chat_main.html @@ -201,6 +201,9 @@
快捷回复 +添加分组
+ + +
diff --git a/static/js/chat-main.js b/static/js/chat-main.js index 85de210..2a191c3 100644 --- a/static/js/chat-main.js +++ b/static/js/chat-main.js @@ -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(); }