From 727704ab145a9067bb79a12be06a0e5c70dba4eb Mon Sep 17 00:00:00 2001 From: taoshihan <630892807@qq.com> Date: Wed, 10 May 2023 16:54:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E9=99=84=E4=BB=B6=E5=B9=B6?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E5=87=BA=E6=89=A9=E5=B1=95=E5=9B=BE=E6=A0=87?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/message.go | 11 ++-- static/css/common.css | 23 +++++++++ static/js/chat-page.js | 8 ++- static/js/functions.js | 111 +++++++++++++++++++++++++++++++++-------- 4 files changed, 124 insertions(+), 29 deletions(-) diff --git a/controller/message.go b/controller/message.go index bb16b42..5ac9fe2 100644 --- a/controller/message.go +++ b/controller/message.go @@ -211,14 +211,6 @@ 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 - } f, err := c.FormFile("realfile") if err != nil { c.JSON(200, gin.H{ @@ -250,6 +242,9 @@ func UploadFile(c *gin.Context) { "msg": "上传成功!", "result": gin.H{ "path": filepath, + "ext": fileExt, + "size": f.Size, + "name": f.Filename, }, }) } diff --git a/static/css/common.css b/static/css/common.css index a4252c2..4a8daa4 100644 --- a/static/css/common.css +++ b/static/css/common.css @@ -378,6 +378,29 @@ a{color: #07a9fe;text-decoration: none;} margin-right: 10px; cursor: pointer; } +.productCard{ + cursor: pointer; + padding: 5px; + border-radius: 2px; + width: auto; + max-width: 730px; + display: flex; + border-radius: 5px; +} +.productCard img{ + width: 100px; + height: 100px; + margin-right: 15px; +} +.productCard .productCardPrice{ + color: #ff7736; + font-weight: bold; + font-size: 16px; + margin-top: 10px; +} +.productCard .productCardTitle{ + color: #333; +} @media screen and (min-width: 900px) { .chatCenter { max-height: 650px; diff --git a/static/js/chat-page.js b/static/js/chat-page.js index 4827807..a4d488e 100644 --- a/static/js/chat-page.js +++ b/static/js/chat-page.js @@ -430,7 +430,13 @@ new Vue({ type: 'error' }); }else{ - _this.messageContent+='file[/' + res.result.path + ']'; + var data=JSON.stringify({ + name:res.result.name, + ext:res.result.ext, + size:res.result.size, + path:'/' + res.result.path, + }) + _this.messageContent+='attachment['+data+']'; _this.chatToUser(); } }, diff --git a/static/js/functions.js b/static/js/functions.js index d9a3196..263041d 100644 --- a/static/js/functions.js +++ b/static/js/functions.js @@ -103,33 +103,104 @@ function replaceContent (content,baseUrl) {// 转义聊天内容中的特殊字 baseUrl=""; } var faces=placeFace(); - var html = function (end) { - return new RegExp('\\n*\\[' + (end || '') + '(pre|div|span|p|table|thead|th|tbody|tr|td|ul|li|ol|li|dl|dt|dd|h2|h3|h4|h5)([\\s\\S]*?)\\]\\n*', 'g'); - }; - content = (content || '').replace(/&(?!#?[a-zA-Z0-9]+;)/g, '&') - .replace(//g, '>').replace(/'/g, ''').replace(/"/g, '"') // XSS - .replace(/face\[([^\s\[\]]+?)\]/g, function (face) { // 转义表情 + content = (content || '') + .replace(/face\[(.*?)\]/g, function (face) { // 转义表情 var alt = face.replace(/^face/g, ''); return '' + alt + ''; }) - .replace(/img\[([^\s\[\]]+?)\]/g, function (face) { // 转义图片 + .replace(/img\[(.*?)\]/g, function (face) { // 转义图片 var src = face.replace(/^img\[/g, '').replace(/\]/g, '');; - return ''; + 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, ''); - return '【'+text+'】'; - }) - .replace(html(), '\<$1 $2\>').replace(html('/'), '\') // 转移HTML代码 - .replace(/\n/g, '
') // 转义换行 - + .replace(/\n/g, '
'); // 转义换行 + content=replaceAttachment(content); return content; } +//替换附件展示 +function replaceAttachment(str){ + return str.replace(/attachment\[(.*?)\]/g, function (result) { + var mutiFiles=result.match(/attachment\[(.*?)\]/) + if (mutiFiles.length<2){ + return result; + } + //return result; + + var info=JSON.parse(mutiFiles[1]) + var imgSrc=""; + switch(info.ext){ + case ".mp3": + imgSrc="/static/images/ext/MP3.png"; + break; + case ".zip": + imgSrc="/static/images/ext/ZIP.png"; + break; + case ".txt": + imgSrc="/static/images/ext/TXT.png"; + break; + case ".7z": + imgSrc="/static/images/ext/7z.png"; + break; + case ".bpm": + imgSrc="/static/images/ext/BMP.png"; + break; + case ".png": + imgSrc="/static/images/ext/PNG.png"; + break; + case ".jpg": + imgSrc="/static/images/ext/JPG.png"; + break; + case ".jpeg": + imgSrc="/static/images/ext/JPEG.png"; + break; + case ".pdf": + imgSrc="/static/images/ext/PDF.png"; + break; + case ".doc": + imgSrc="/static/images/ext/DOC.png"; + break; + case ".docx": + imgSrc="/static/images/ext/DOCX.png"; + break; + case ".rar": + imgSrc="/static/images/ext/RAR.png"; + break; + case ".xlsx": + imgSrc="/static/images/ext/XLSX.png"; + break; + case ".csv": + imgSrc="/static/images/ext/XLSX.png"; + break; + default: + imgSrc="/static/images/ext/default.png"; + break; + } + var html= `
+
+
+
`+info.name+`
+
`+formatFileSize(info.size)+`
+
+
`; + return html; + }) +} +function formatFileSize(fileSize) { + if (fileSize < 1024) { + return fileSize + 'B'; + } else if (fileSize < (1024*1024)) { + var temp = fileSize / 1024; + temp = temp.toFixed(2); + return temp + 'KB'; + } else if (fileSize < (1024*1024*1024)) { + var temp = fileSize / (1024*1024); + temp = temp.toFixed(2); + return temp + 'MB'; + } else { + var temp = fileSize / (1024*1024*1024); + temp = temp.toFixed(2); + return temp + 'GB'; + } +} function bigPic(src,isVisitor){ if (isVisitor) { window.open(src);