From fbd662e400cb497e094d55f96638471b24b3bcb7 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Thu, 28 Dec 2023 20:48:00 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E9=A2=84=E8=A7=88?= =?UTF-8?q?=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/assets/js/functions/web.js | 4 +++- resources/assets/js/pages/manage.vue | 3 ++- resources/assets/js/store/markdown.js | 8 ++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/resources/assets/js/functions/web.js b/resources/assets/js/functions/web.js index 59d271296..f44efae6f 100755 --- a/resources/assets/js/functions/web.js +++ b/resources/assets/js/functions/web.js @@ -1,3 +1,5 @@ +import {MarkdownPreview} from "../store/markdown"; + /** * 页面专用 */ @@ -819,7 +821,7 @@ if ($A.isJson(data)) { switch (data.type) { case 'text': - return $A.getMsgTextPreview(data.msg.text, imgClassName) + return $A.getMsgTextPreview(data.msg.type === 'md' ? MarkdownPreview(data.msg.text) : data.msg.text, imgClassName) case 'word-chain': return `[${$A.L('接龙')}]` + $A.getMsgTextPreview(data.msg.text, imgClassName) case 'vote': diff --git a/resources/assets/js/pages/manage.vue b/resources/assets/js/pages/manage.vue index f3d81a850..67b2ae482 100644 --- a/resources/assets/js/pages/manage.vue +++ b/resources/assets/js/pages/manage.vue @@ -326,6 +326,7 @@ import ApproveExport from "./manage/components/ApproveExport"; import notificationKoro from "notification-koro1"; import {Store} from "le5le-store"; import MicroApps from "../components/MicroApps.vue"; +import {MarkdownPreview} from "../store/markdown"; export default { components: { @@ -986,7 +987,7 @@ export default { let body; switch (type) { case 'text': - body = $A.getMsgTextPreview(msg.text) + body = $A.getMsgTextPreview(msg.type === 'md' ? MarkdownPreview(msg.text) : msg.text) break; case 'file': body = '[' + this.$L(msg.type == 'img' ? '图片信息' : '文件信息') + ']' diff --git a/resources/assets/js/store/markdown.js b/resources/assets/js/store/markdown.js index 84239e41c..ca178e0f3 100644 --- a/resources/assets/js/store/markdown.js +++ b/resources/assets/js/store/markdown.js @@ -8,6 +8,7 @@ import mdKatex from "@traptitech/markdown-it-katex"; */ const MarkdownUtils = { mdi: null, + mds: null, formatMsg: (text) => { const array = text.match(/]*?>/g); if (array) { @@ -43,3 +44,10 @@ export function MarkdownConver(text) { } return MarkdownUtils.formatMsg(MarkdownUtils.mdi.render(text)) } + +export function MarkdownPreview(text) { + if (MarkdownUtils.mds === null) { + MarkdownUtils.mds = MarkdownIt() + } + return MarkdownUtils.mds.render(text) +}