diff --git a/im-uniapp/common/url.js b/im-uniapp/common/url.js index ff04275..c95d834 100644 --- a/im-uniapp/common/url.js +++ b/im-uniapp/common/url.js @@ -1,7 +1,14 @@ + +// 使用正则表达式匹配更广泛的URL格式(此正则由deepseek生成) +const regex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]|\bwww\.[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; + +let containUrl = (content) => { + return regex.test(content) +} + + let replaceURLWithHTMLLinks = (content, color) => { - // 使用正则表达式匹配更广泛的URL格式(此正则由deepseek生成) - const urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]|\bwww\.[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; - return content.replace(urlRegex, (url) => { + return content.replace(regex, (url) => { // 如果URL不以http(s)://开头,则添加http://前缀 if (!url.startsWith("http")) { url = "http://" + url; @@ -11,5 +18,6 @@ let replaceURLWithHTMLLinks = (content, color) => { } export default { + containUrl, replaceURLWithHTMLLinks } \ No newline at end of file diff --git a/im-uniapp/components/chat-message-item/chat-message-item.vue b/im-uniapp/components/chat-message-item/chat-message-item.vue index aa7441c..060ac0a 100644 --- a/im-uniapp/components/chat-message-item/chat-message-item.vue +++ b/im-uniapp/components/chat-message-item/chat-message-item.vue @@ -16,11 +16,11 @@ - - - - + + + + @@ -39,8 +39,8 @@ - + {{ fileSize }} diff --git a/im-uniapp/pages/chat/chat-box.vue b/im-uniapp/pages/chat/chat-box.vue index d2bd260..958fa3f 100644 --- a/im-uniapp/pages/chat/chat-box.vue +++ b/im-uniapp/pages/chat/chat-box.vue @@ -288,7 +288,9 @@ export default { sendText += op.insert ) }) - if (!sendText.trim() && this.atUserIds.length == 0) { + // 去除最后的换行符 + sendText = sendText.trim(); + if (!sendText && this.atUserIds.length == 0) { return uni.showToast({ title: "不能发送空白信息", icon: "none" @@ -610,7 +612,7 @@ export default { query.select('.chat-wrap').boundingClientRect(); query.exec(data => { this.scrollTop = data[0].height - scrollViewHeight; - if(this.scrollTop < 10){ + if (this.scrollTop < 10) { // 未渲染完成,重试一次 this.holdingScrollBar(); }