diff --git a/resources/assets/js/functions/common.js b/resources/assets/js/functions/common.js index db45cb4b3..39af603cf 100755 --- a/resources/assets/js/functions/common.js +++ b/resources/assets/js/functions/common.js @@ -1122,6 +1122,39 @@ return {width, height}; }, + /** + * 阻止滑动穿透 + * @param el + */ + scrollPreventThrough(el) { + if (!el) { + return; + } + if (el.getAttribute("data-prevent-through") === "yes") { + return; + } + el.setAttribute("data-prevent-through", "yes") + // + let targetY = null; + el.addEventListener('touchstart', function (e) { + targetY = Math.floor(e.targetTouches[0].clientY); + }); + el.addEventListener('touchmove', function (e) { + // 检测可滚动区域的滚动事件,如果滑到了顶部或底部,阻止默认事件 + let NewTargetY = Math.floor(e.targetTouches[0].clientY), //本次移动时鼠标的位置,用于计算 + sTop = el.scrollTop, //当前滚动的距离 + sH = el.scrollHeight, //可滚动区域的高度 + lyBoxH = el.clientHeight; //可视区域的高度 + if (sTop <= 0 && NewTargetY - targetY > 0) { + // 下拉页面到顶 + e.preventDefault(); + } else if (sTop >= sH - lyBoxH && NewTargetY - targetY < 0) { + // 上翻页面到底 + e.preventDefault(); + } + }, false); + }, + /** * 获取元素属性 * @param el diff --git a/resources/assets/js/functions/utils.js b/resources/assets/js/functions/utils.js deleted file mode 100755 index 8faeb4182..000000000 --- a/resources/assets/js/functions/utils.js +++ /dev/null @@ -1,141 +0,0 @@ -const assetsFunctionUtils = { - /** - * 消息格式化处理 - * @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; - }, - - /** - * 获取文本消息图片 - * @param text - * @returns {*[]} - */ - textImagesInfo(text) { - const baseUrl = $A.apiUrl('../'); - const array = text.match(new RegExp(`]*?>`, "g")); - const list = []; - if (array) { - const srcReg = new RegExp("src=([\"'])([^'\"]*)\\1"), - widthReg = new RegExp("(original-)?width=\"(\\d+)\""), - heightReg = new RegExp("(original-)?height=\"(\\d+)\"") - array.some(res => { - const srcMatch = res.match(srcReg), - widthMatch = res.match(widthReg), - heightMatch = res.match(heightReg); - if (srcMatch) { - list.push({ - src: srcMatch[2].replace(/\{\{RemoteURL\}\}/g, baseUrl), - width: widthMatch ? widthMatch[2] : -1, - height: heightMatch ? heightMatch[2] : -1, - }) - } - }) - } - return list; - }, - - /** - * 消息简单描述 - * @param data - * @returns {string|*} - */ - msgSimpleDesc(data) { - if ($A.isJson(data)) { - switch (data.type) { - case 'text': - return $A.getMsgTextPreview(data.msg.text) - case 'record': - return `[${$A.L('语音')}]` - case 'meeting': - return `[${$A.L('会议')}] ${data.msg.name}` - case 'file': - if (data.msg.type == 'img') { - return `[${$A.L('图片')}]` - } - return `[${$A.L('文件')}] ${data.msg.name}` - case 'tag': - return `[${$A.L(data.msg.action === 'remove' ? '取消标注' : '标注')}] ${assetsFunctionUtils.msgSimpleDesc(data.msg.data)}` - default: - return `[${$A.L('未知的消息')}]` - } - } - return ''; - }, - - /** - * 阻止滑动穿透 - * @param el - */ - scrollPreventThrough(el) { - if (!el) { - return; - } - if (el.getAttribute("data-prevent-through") === "yes") { - return; - } - el.setAttribute("data-prevent-through", "yes") - // - let targetY = null; - el.addEventListener('touchstart', function (e) { - targetY = Math.floor(e.targetTouches[0].clientY); - }); - el.addEventListener('touchmove', function (e) { - // 检测可滚动区域的滚动事件,如果滑到了顶部或底部,阻止默认事件 - let NewTargetY = Math.floor(e.targetTouches[0].clientY), //本次移动时鼠标的位置,用于计算 - sTop = el.scrollTop, //当前滚动的距离 - sH = el.scrollHeight, //可滚动区域的高度 - lyBoxH = el.clientHeight; //可视区域的高度 - if (sTop <= 0 && NewTargetY - targetY > 0) { - // 下拉页面到顶 - e.preventDefault(); - } else if (sTop >= sH - lyBoxH && NewTargetY - targetY < 0) { - // 上翻页面到底 - e.preventDefault(); - } - }, false); - }, -} - -module.exports = assetsFunctionUtils diff --git a/resources/assets/js/functions/web.js b/resources/assets/js/functions/web.js index 1c0e645fe..d9cc47f0d 100755 --- a/resources/assets/js/functions/web.js +++ b/resources/assets/js/functions/web.js @@ -391,6 +391,111 @@ return text.replace(/<[^>]+>/g,"") }, + /** + * 消息格式化处理 + * @param text + * @param userid + * @returns {string|*} + */ + formatTextMsg(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; + }, + + /** + * 获取文本消息图片 + * @param text + * @returns {*[]} + */ + getTextImagesInfo(text) { + const baseUrl = $A.apiUrl('../'); + const array = text.match(new RegExp(`]*?>`, "g")); + const list = []; + if (array) { + const srcReg = new RegExp("src=([\"'])([^'\"]*)\\1"), + widthReg = new RegExp("(original-)?width=\"(\\d+)\""), + heightReg = new RegExp("(original-)?height=\"(\\d+)\"") + array.some(res => { + const srcMatch = res.match(srcReg), + widthMatch = res.match(widthReg), + heightMatch = res.match(heightReg); + if (srcMatch) { + list.push({ + src: srcMatch[2].replace(/\{\{RemoteURL\}\}/g, baseUrl), + width: widthMatch ? widthMatch[2] : -1, + height: heightMatch ? heightMatch[2] : -1, + }) + } + }) + } + return list; + }, + + /** + * 消息简单描述 + * @param data + * @returns {string|*} + */ + getMsgSimpleDesc(data) { + if ($A.isJson(data)) { + switch (data.type) { + case 'text': + return $A.getMsgTextPreview(data.msg.text) + case 'record': + return `[${$A.L('语音')}]` + case 'meeting': + return `[${$A.L('会议')}] ${data.msg.name}` + case 'file': + if (data.msg.type == 'img') { + return `[${$A.L('图片')}]` + } + return `[${$A.L('文件')}] ${data.msg.name}` + case 'tag': + return `[${$A.L(data.msg.action === 'remove' ? '取消标注' : '标注')}] ${$A.getMsgSimpleDesc(data.msg.data)}` + default: + return `[${$A.L('未知的消息')}]` + } + } + return ''; + }, + /** * 获取文件标题 * @param file diff --git a/resources/assets/js/pages/manage/components/ChatInput/index.vue b/resources/assets/js/pages/manage/components/ChatInput/index.vue index 456ef22a5..e5d700d1d 100755 --- a/resources/assets/js/pages/manage/components/ChatInput/index.vue +++ b/resources/assets/js/pages/manage/components/ChatInput/index.vue @@ -4,7 +4,7 @@
-
{{formatMsgDesc(replyData)}}
+
{{$A.getMsgSimpleDesc(replyData)}}
@@ -132,7 +132,6 @@ import touchmouse from "../../../../directives/touchmouse"; import TransferDom from "../../../../directives/transfer-dom"; import clickoutside from "../../../../directives/clickoutside"; import {Store} from "le5le-store"; -import {scrollPreventThrough, msgSimpleDesc} from "../../../../functions/utils"; export default { name: 'ChatInput', @@ -526,7 +525,7 @@ export default { containers[i].classList.remove("user-mention"); containers[i].classList.remove("task-mention"); containers[i].classList.add(mentionName); - scrollPreventThrough(containers[i]); + $A.scrollPreventThrough(containers[i]); } this.getMentionSource(mentionChar, searchTerm, array => { const values = []; @@ -1146,10 +1145,6 @@ export default { this.$emit('on-file', postFiles) } }, - - formatMsgDesc(data) { - return msgSimpleDesc(data); - }, } } diff --git a/resources/assets/js/pages/manage/components/DialogItem.vue b/resources/assets/js/pages/manage/components/DialogItem.vue index 1f7a7f3cf..c22e9b914 100644 --- a/resources/assets/js/pages/manage/components/DialogItem.vue +++ b/resources/assets/js/pages/manage/components/DialogItem.vue @@ -3,7 +3,7 @@
{{$L(source.msg.action === 'remove' ? '取消标注' : '标注了')}} - "{{formatMsgDesc(source.msg.data)}}" + "{{$A.getMsgSimpleDesc(source.msg.data)}}"