perf: 优化预览消息

This commit is contained in:
kuaifan 2023-12-28 20:48:00 +08:00
parent ccb31a81f8
commit fbd662e400
3 changed files with 13 additions and 2 deletions

View File

@ -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':

View File

@ -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' ? '图片信息' : '文件信息') + ']'

View File

@ -8,6 +8,7 @@ import mdKatex from "@traptitech/markdown-it-katex";
*/
const MarkdownUtils = {
mdi: null,
mds: null,
formatMsg: (text) => {
const array = text.match(/<img\s+[^>]*?>/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)
}