🐛 修复 mention 类型渲染异常

This commit is contained in:
目棃
2024-04-26 15:06:40 +08:00
parent c89dfae2f7
commit abb0a6e751
3 changed files with 21 additions and 3 deletions

View File

@@ -11,7 +11,7 @@ import TGClient from "../../utils/TGClient";
import showConfirm from "../func/confirm";
import showSnackbar from "../func/snackbar";
interface TpMention {
export interface TpMention {
insert: {
mention: {
uid: string;

View File

@@ -31,6 +31,11 @@ function getParsedData(data: TGApp.Plugins.Mys.SctPost.Base[]): TGApp.Plugins.My
let cur: TGApp.Plugins.Mys.SctPost.Base | undefined;
for (const tp of data) {
const tpName = getTpName(tp);
// 单独处理 TpMention
if (tpName === TpMention) {
child.push(tp);
continue;
}
if (tpName !== TpText) {
cur = tp;
child = [];

View File

@@ -1,15 +1,21 @@
<template>
<div :style="getLineStyle()" class="tp-texts">
<TpText v-for="(text, index) in props.data.children" :data="text" :key="index" />
<component
:is="getComp(text)"
v-for="(text, index) in props.data.children"
:data="text"
:key="index"
/>
</div>
</template>
<script lang="ts" setup>
import { StyleValue } from "vue";
import TpMention, { type TpMention as TpMentionType } from "./tp-mention.vue";
import TpText, { type TpText as TpTextType } from "./tp-text.vue";
interface TpTexts extends TpTextType {
children: TpTextType[];
children: (TpTextType | TpMentionType)[];
}
interface TpTextsProps {
@@ -18,6 +24,13 @@ interface TpTextsProps {
const props = defineProps<TpTextsProps>();
function getComp(text: TpTextType | TpMentionType): string {
if (typeof text.insert === "string") {
return TpText;
}
return TpMention;
}
function getLineStyle(): StyleValue {
const style = <Array<StyleValue>>[];
if (props.data.attributes === undefined) {