🌱 公告解析重构

This commit is contained in:
目棃
2024-08-13 20:07:55 +08:00
parent 46214a6d64
commit 9fb95c6ade
7 changed files with 398 additions and 32 deletions

View File

@@ -1 +1,30 @@
<!-- todo 公告解析 -->
<template>
<component
v-for="(ta, index) in parseAnnoContent(props.data)"
:key="index"
:is="getTaName(ta)"
:data="ta"
/>
</template>
<script lang="ts" setup>
import { parseAnnoContent } from "../../web/utils/annoParser.js";
import TpBackupText from "../post/tp-backupText.vue";
import TpImage from "../post/tp-image.vue";
import TpText from "../post/tp-text.vue";
import TpTexts from "../post/tp-texts.vue";
import TpUnknown from "../post/tp-unknown.vue";
interface TaParserProps {
data: TGApp.BBS.Announcement.ContentItem;
}
const props = defineProps<TaParserProps>();
function getTaName(ta: TGApp.Plugins.Mys.SctPost.Base) {
if (ta.children) return TpTexts;
if (typeof ta.insert === "string") return TpText;
if ("image" in ta.insert) return TpImage;
if ("backup_text" in ta.insert) return TpBackupText;
return TpUnknown;
}
</script>

View File

@@ -28,6 +28,7 @@ export interface TpImage {
align?: "center"; // 待补充
};
}
interface TpImageProps {
data: TpImage;
}
@@ -66,6 +67,7 @@ function getImageTitle(): string {
function getImageUrl(): string {
const img = props.data.insert.image;
const append = "?x-oss-process=image/format,png";
console.log("getImageUrl", img, append);
if (img.endsWith(".gif")) return img;
return img + append;
}

View File

@@ -89,25 +89,15 @@ function getParsedText(data: TpTextType): TpTextType[] {
function getTpName(tp: TGApp.Plugins.Mys.SctPost.Base) {
if (tp.children) return TpTexts;
if (typeof tp.insert === "string") {
return TpText;
} else if ("image" in tp.insert) {
return TpImage;
} else if ("vod" in tp.insert) {
return TpVod;
} else if ("video" in tp.insert) {
return TpVideo;
} else if ("backup_text" in tp.insert) {
return TpBackupText;
} else if ("link_card" in tp.insert) {
return TpLinkCard;
} else if ("divider" in tp.insert) {
return TpDivider;
} else if ("mention" in tp.insert) {
return TpMention;
} else if ("vote" in tp.insert) {
return TpVote;
}
if (typeof tp.insert === "string") return TpText;
if ("image" in tp.insert) return TpImage;
if ("vod" in tp.insert) return TpVod;
if ("video" in tp.insert) return TpVideo;
if ("backup_text" in tp.insert) return TpBackupText;
if ("link_card" in tp.insert) return TpLinkCard;
if ("divider" in tp.insert) return TpDivider;
if ("mention" in tp.insert) return TpMention;
if ("vote" in tp.insert) return TpVote;
return TpUnknown;
}
</script>