diff --git a/resources/assets/js/functions/utils.js b/resources/assets/js/functions/utils.js new file mode 100755 index 000000000..092d3e684 --- /dev/null +++ b/resources/assets/js/functions/utils.js @@ -0,0 +1,49 @@ +module.exports = { + /** + * 消息格式化处理 + * @param text + * @param userid + * @returns {string|*} + */ + textMsgFormat(text, userid) { + if (!text) { + return "" + } + const atReg = new RegExp(``, "g") + text = text.trim().replace(/(\n\x20*){3,}/g, "\n\n"); + text = text.replace(/ /g, ' ') + text = text.replace(/

<\/p>/g, '


') + text = text.replace(/\{\{RemoteURL\}\}/g, $A.apiUrl('../')) + text = text.replace(atReg, ``) + // 处理内容连接 + if (/https*:\/\//.test(text)) { + text = text.split(/(<[^>]*>)/g).map(string => { + if (string && !/<[^>]*>/.test(string)) { + string = string.replace(/(https*:\/\/)((\w|=|\?|\.|\/|&|-|:|\+|%|;)+)/g, "$1$2") + } + return string; + }).join("") + } + // 处理图片显示尺寸 + const array = text.match(/]*?>/g); + if (array) { + const widthReg = new RegExp("width=\"(\\d+)\""), + heightReg = new RegExp("height=\"(\\d+)\"") + array.some(res => { + const widthMatch = res.match(widthReg), + heightMatch = res.match(heightReg); + if (widthMatch && heightMatch) { + const width = parseInt(widthMatch[1]), + height = parseInt(heightMatch[1]), + maxSize = res.indexOf("emoticon") > -1 ? 150 : 220; + const scale = $A.scaleToScale(width, height, maxSize, maxSize); + const value = res + .replace(widthReg, `original-width="${width}" width="${scale.width}"`) + .replace(heightReg, `original-height="${height}" height="${scale.height}"`) + text = text.replace(res, value) + } + }) + } + return text; + } +} diff --git a/resources/assets/js/pages/manage/components/DialogView.vue b/resources/assets/js/pages/manage/components/DialogView.vue index 3f1c401c3..beb93cf2d 100644 --- a/resources/assets/js/pages/manage/components/DialogView.vue +++ b/resources/assets/js/pages/manage/components/DialogView.vue @@ -124,6 +124,7 @@ import WCircle from "../../../components/WCircle"; import {mapState} from "vuex"; import {Store} from "le5le-store"; import longpress from "../../../directives/longpress"; +import {textMsgFormat} from "../../../functions/utils"; export default { name: "DialogView", @@ -224,10 +225,6 @@ export default { } } return classArray; - }, - - atUserReg() { - return new RegExp(``, "g") } }, @@ -292,44 +289,7 @@ export default { }, textMsg(text) { - if (!text) { - return "" - } - text = text.trim().replace(/(\n\x20*){3,}/g, "\n\n"); - text = text.replace(/ /g, ' ') - text = text.replace(/

<\/p>/g, '


') - text = text.replace(/\{\{RemoteURL\}\}/g, $A.apiUrl('../')) - text = text.replace(this.atUserReg, ``) - // 处理内容连接 - if (/https*:\/\//.test(text)) { - text = text.split(/(<[^>]*>)/g).map(string => { - if (string && !/<[^>]*>/.test(string)) { - string = string.replace(/(https*:\/\/)((\w|=|\?|\.|\/|&|-|:|\+|%|;)+)/g, "$1$2") - } - return string; - }).join("") - } - // 处理图片显示尺寸 - const array = text.match(/]*?>/g); - if (array) { - const widthReg = new RegExp("width=\"(\\d+)\""), - heightReg = new RegExp("height=\"(\\d+)\"") - array.some(res => { - const widthMatch = res.match(widthReg), - heightMatch = res.match(heightReg); - if (widthMatch && heightMatch) { - const width = parseInt(widthMatch[1]), - height = parseInt(heightMatch[1]), - maxSize = res.indexOf("emoticon") > -1 ? 150 : 220; - const scale = $A.scaleToScale(width, height, maxSize, maxSize); - const value = res - .replace(widthReg, `original-width="${width}" width="${scale.width}"`) - .replace(heightReg, `original-height="${height}" height="${scale.height}"`) - text = text.replace(res, value) - } - }) - } - return text; + return textMsgFormat(text, this.userId); }, recordStyle(info) { diff --git a/resources/assets/js/pages/manage/components/DialogWrapper.vue b/resources/assets/js/pages/manage/components/DialogWrapper.vue index 4832d2f2d..9c4c26982 100644 --- a/resources/assets/js/pages/manage/components/DialogWrapper.vue +++ b/resources/assets/js/pages/manage/components/DialogWrapper.vue @@ -570,15 +570,20 @@ export default { this.onActive(); // let tempId = $A.randomString(16); - this.tempMsgs.push({ + let tempMsg = { id: tempId, dialog_id: this.dialogData.id, type: 'text', userid: this.userId, msg: { - text: msgText, + text: $A.stringLength(msgText) > 2000 ? '' : msgText, }, - }); + }; + if (msgText.length > 2000) { + tempMsg.type = 'loading'; + tempMsg.msg = { }; + } + this.tempMsgs.push(tempMsg); // this.$store.dispatch("call", { url: 'dialog/msg/sendtext', diff --git a/resources/assets/js/pages/single/fileMsg.vue b/resources/assets/js/pages/single/fileMsg.vue index 6c6fed0ce..6774aa162 100644 --- a/resources/assets/js/pages/single/fileMsg.vue +++ b/resources/assets/js/pages/single/fileMsg.vue @@ -7,7 +7,10 @@ - +