From cba947ffc8b3d2c95c5863163f2c182d17032086 Mon Sep 17 00:00:00 2001 From: BTMuli Date: Sat, 16 Dec 2023 00:03:29 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E8=A1=A8?= =?UTF-8?q?=E6=83=85=E5=8C=85=E8=A7=A3=E6=9E=90=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit *PostID: 46566582 --- src/components/post/tp-text.vue | 42 ++++++++++----------------------- 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/src/components/post/tp-text.vue b/src/components/post/tp-text.vue index fe4734e7..c3f1bab5 100644 --- a/src/components/post/tp-text.vue +++ b/src/components/post/tp-text.vue @@ -54,38 +54,20 @@ onMounted(async () => { mode.value = "link"; return; } - const count = countEmoji(props.data.insert); - if (count == 1) { - mode.value = "emoji"; - } else if (count > 1) { - mode.value = "emojis"; - emojis.value = parseEmojis(props.data); - } else { - mode.value = "text"; - } -}); - -// 获取可能的 emoji 数量 -function countEmoji(text: string): number { - const reg = /_\((.*?)\)/g; - const res = text.match(reg); - if (res) { - return res.length; - } - return 0; -} - -// 解析表情 -function parseEmojis(text: TpText): TpText[] { // thanks, @Lightczx & webstorm const reg = /(?<=\n|.+?|^)(_\(.+?\)(?=\n|.+?|$))/g; - return text.insert.split(reg).map((item) => { - return { - insert: item, - attributes: text.attributes, - }; - }); -} + const res = props.data.insert.split(reg); + if (res.length > 2) { + if (res.length === 3 && res[0] === "" && res[2] === "") { + mode.value = "emoji"; + return; + } + mode.value = "emojis"; + emojis.value = res.map((i) => ({ insert: i, attributes: props.data.attributes })); + return; + } + mode.value = "text"; +}); // 解析文本样式 function getTextStyle(): StyleValue {