From add0f5b92cd302db05090c407b8f7ad88690f052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B6=E5=A3=AB=E6=B6=B5?= <630892807@qq.com> Date: Sat, 19 Dec 2020 21:45:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E8=AE=BF=E5=AE=A2=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E9=99=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/go-fly.sql | 1 + controller/ip.go | 9 ++++++++ controller/message.go | 45 ++++++++++++++++++++++++++++++++++++++ models/ipblacks.go | 5 +++++ router/api.go | 3 +++ static/css/common.css | 31 ++++++++++++++++++++++++++ static/html/chat_main.html | 10 +++++---- static/html/chat_page.html | 5 +++-- static/js/chat-main.js | 19 +++++++++++++++- static/js/chat-page.js | 36 ++++++++++++++++++++++++++++++ static/js/functions.js | 4 ++++ 11 files changed, 161 insertions(+), 7 deletions(-) diff --git a/config/go-fly.sql b/config/go-fly.sql index 1078243..235aeb0 100644 --- a/config/go-fly.sql +++ b/config/go-fly.sql @@ -110,6 +110,7 @@ INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES (NULL, INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES (NULL, 'Server酱API', 'ServerJiangAPI', '')| INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES (NULL, '微信小程序Token', 'WeixinToken', '')| INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES (NULL, '当前小程序审核状态', 'MiniAppAudit', 'yes')| +INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES (NULL, '是否允许上传附件', 'SendAttachment', 'ture')| DROP TABLE IF EXISTS `about`| CREATE TABLE `about` ( diff --git a/controller/ip.go b/controller/ip.go index f2de0be..2330344 100644 --- a/controller/ip.go +++ b/controller/ip.go @@ -55,3 +55,12 @@ func GetIpblacks(c *gin.Context) { }, }) } +func GetIpblacksByKefuId(c *gin.Context) { + kefuId, _ := c.Get("kefu_name") + list := models.FindIpsByKefuId(kefuId.(string)) + c.JSON(200, gin.H{ + "code": 200, + "msg": "ok", + "result": list, + }) +} diff --git a/controller/message.go b/controller/message.go index 793e358..d45a340 100644 --- a/controller/message.go +++ b/controller/message.go @@ -11,6 +11,7 @@ import ( "github.com/taoshihan1991/imaptool/ws" "os" "path" + "strconv" "strings" "time" ) @@ -322,7 +323,51 @@ func UploadImg(c *gin.Context) { }) } } +func UploadFile(c *gin.Context) { + SendAttachment, err := strconv.ParseBool(models.FindConfig("SendAttachment")) + if !SendAttachment || err != nil { + c.JSON(200, gin.H{ + "code": 400, + "msg": "禁止上传附件!", + }) + return + } + config := config.CreateConfig() + f, err := c.FormFile("realfile") + if err != nil { + c.JSON(200, gin.H{ + "code": 400, + "msg": "上传失败!", + }) + return + } else { + fileExt := strings.ToLower(path.Ext(f.Filename)) + if f.Size >= 90*1024*1024 { + c.JSON(200, gin.H{ + "code": 400, + "msg": "上传失败!不允许超过90M", + }) + return + } + + fileName := tools.Md5(fmt.Sprintf("%s%s", f.Filename, time.Now().String())) + fildDir := fmt.Sprintf("%s%d%s/", config.Upload, time.Now().Year(), time.Now().Month().String()) + isExist, _ := tools.IsFileExist(fildDir) + if !isExist { + os.Mkdir(fildDir, os.ModePerm) + } + filepath := fmt.Sprintf("%s%s%s", fildDir, fileName, fileExt) + c.SaveUploadedFile(f, filepath) + c.JSON(200, gin.H{ + "code": 200, + "msg": "上传成功!", + "result": gin.H{ + "path": filepath, + }, + }) + } +} func GetMessagesV2(c *gin.Context) { visitorId := c.Query("visitor_id") messages := models.FindMessageByVisitorId(visitorId) diff --git a/models/ipblacks.go b/models/ipblacks.go index 0fb0f6e..5116151 100644 --- a/models/ipblacks.go +++ b/models/ipblacks.go @@ -26,6 +26,11 @@ func FindIp(ip string) Ipblack { DB.Where("ip = ?", ip).First(&ipblack) return ipblack } +func FindIpsByKefuId(id string) []Ipblack { + var ipblack []Ipblack + DB.Where("kefu_id = ?", id).Find(&ipblack) + return ipblack +} func FindIps(query interface{}, args []interface{}, page uint, pagesize uint) []Ipblack { offset := (page - 1) * pagesize if offset < 0 { diff --git a/router/api.go b/router/api.go index 24fbad2..faeef62 100644 --- a/router/api.go +++ b/router/api.go @@ -38,6 +38,8 @@ func InitApiRouter(engine *gin.Engine) { engine.GET("/message_close", controller.SendCloseMessage) //上传文件 engine.POST("/uploadimg", middleware.Ipblack, controller.UploadImg) + //上传文件 + engine.POST("/uploadfile", middleware.Ipblack, controller.UploadFile) //获取未读消息数 engine.GET("/message_status", controller.GetVisitorMessage) //设置消息已读 @@ -78,6 +80,7 @@ func InitApiRouter(engine *gin.Engine) { engine.POST("/ipblack", middleware.JwtApiMiddleware, controller.PostIpblack) engine.DELETE("/ipblack", middleware.JwtApiMiddleware, middleware.RbacAuth, controller.DelIpblack) engine.GET("/ipblacks_all", middleware.JwtApiMiddleware, controller.GetIpblacks) + engine.GET("/ipblacks", middleware.JwtApiMiddleware, controller.GetIpblacksByKefuId) engine.GET("/configs", middleware.JwtApiMiddleware, middleware.RbacAuth, controller.GetConfigs) engine.POST("/config", middleware.JwtApiMiddleware, middleware.RbacAuth, controller.PostConfig) engine.GET("/config", controller.GetConfig) diff --git a/static/css/common.css b/static/css/common.css index b7d489a..00a13b8 100644 --- a/static/css/common.css +++ b/static/css/common.css @@ -130,6 +130,37 @@ top: 5px; right: 5px } +.visitorFolderBtn{ + float: left; + margin-left: 20px; +} +.folderBtn { + display: inline-block; + background-color: transparent; + overflow: hidden; + font-size: 1px; +} +.folderBtn:before { + content: ''; + float: left; + background-color: #9da0a0; + width: 1.5em; + height: 0.45em; + margin-left: 0.07em; + margin-bottom: -0.07em; + border-top-left-radius: 0.1em; + border-top-right-radius: 0.1em; + box-shadow: 1.25em 0.25em 0 0em #9da0a0; +} +.folderBtn:after { + content: ''; + float: left; + clear: left; + background-color: #d4d6d6; + width: 2.5em; + height: 1.8em; + border-radius: 0.1em; +} .visitorImageBtn{ float: left; margin-left: 20px; diff --git a/static/html/chat_main.html b/static/html/chat_main.html index 31ea960..acd77a7 100644 --- a/static/html/chat_main.html +++ b/static/html/chat_main.html @@ -187,10 +187,12 @@ - -
- 待开发 + + +
+ <{item.ip}>
+
@@ -285,5 +287,5 @@
- + \ No newline at end of file diff --git a/static/html/chat_page.html b/static/html/chat_page.html index e3295be..9712463 100644 --- a/static/html/chat_page.html +++ b/static/html/chat_page.html @@ -13,7 +13,7 @@ - +
@@ -47,6 +47,7 @@
+
@@ -78,5 +79,5 @@ var KEFU_ID='{{.KEFU_ID}}'; var REFER='{{.Refer}}'; - + diff --git a/static/js/chat-main.js b/static/js/chat-main.js index c6dc3b7..e047c8b 100644 --- a/static/js/chat-main.js +++ b/static/js/chat-main.js @@ -43,7 +43,7 @@ var app=new Vue({ groupId:"", replys:[], replyContent:"", - + ipBlacks:[], }, methods: { //跳转 @@ -659,6 +659,22 @@ var app=new Vue({ _this.getReplys(); }); }, + //获取黑名单 + getIpblacks(){ + var _this=this; + this.sendAjax("/ipblacks","get",{},function(result){ + _this.ipBlacks=result; + }); + }, + //删除黑名单 + delIpblack(ip){ + let _this=this; + this.sendAjax("/ipblack?ip="+ip,"DELETE",{ip:ip},function(result){ + _this.sendAjax("/ipblacks","get",{},function(result){ + _this.ipBlacks=result; + }); + }); + }, sendAjax(url,method,params,callback){ let _this=this; $.ajax({ @@ -702,6 +718,7 @@ var app=new Vue({ this.getKefuInfo(); this.getOnlineVisitors(); this.getReplys(); + this.getIpblacks(); //心跳 this.ping(); } diff --git a/static/js/chat-page.js b/static/js/chat-page.js index 6b0daa8..499acfe 100644 --- a/static/js/chat-page.js +++ b/static/js/chat-page.js @@ -344,6 +344,42 @@ new Vue({ }); }); }, + //上传文件 + uploadFile (url){ + let _this=this; + $('#uploadFile').after(''); + $("#uploadRealFile").click(); + $("#uploadRealFile").change(function (e) { + var formData = new FormData(); + var file = $("#uploadRealFile")[0].files[0]; + formData.append("realfile",file); //传给后台的file的key值是可以自己定义的 + console.log(formData); + $.ajax({ + url: url || '', + type: "post", + data: formData, + contentType: false, + processData: false, + dataType: 'JSON', + mimeType: "multipart/form-data", + success: function (res) { + + if(res.code!=200){ + _this.$message({ + message: res.msg, + type: 'error' + }); + }else{ + _this.messageContent+='file[/' + res.result.path + ']'; + _this.chatToUser(); + } + }, + error: function (data) { + console.log(data); + } + }); + }); + }, //粘贴上传图片 onPasteUpload(event){ let items = event.clipboardData && event.clipboardData.items; diff --git a/static/js/functions.js b/static/js/functions.js index 5863591..e11146e 100644 --- a/static/js/functions.js +++ b/static/js/functions.js @@ -77,6 +77,10 @@ function replaceContent (content) {// 转义聊天内容中的特殊字符 var src = face.replace(/^img\[/g, '').replace(/\]/g, '');; return '
'; }) + .replace(/file\[([^\s\[\]]+?)\]/g, function (face) { // 转义图片 + var src = face.replace(/^file\[/g, '').replace(/\]/g, '');; + return '
'; + }) .replace(/\[([^\s\[\]]+?)\]+link\[([^\s\[\]]+?)\]/g, function (face) { // 转义超链接 var text = face.replace(/link\[.*?\]/g, '').replace(/\[|\]/g, ''); var src = face.replace(/^\[([^\s\[\]]+?)\]+link\[/g, '').replace(/\]/g, '');