Skip to content

Commit

Permalink
🐛 修复 mention 类型渲染异常
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Apr 26, 2024
1 parent c89dfae commit abb0a6e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/post/tp-mention.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/components/post/tp-parser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
17 changes: 15 additions & 2 deletions src/components/post/tp-texts.vue
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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) {
Expand Down

0 comments on commit abb0a6e

Please sign in to comment.