diff --git a/src/pages/common/PageAnno.vue b/src/pages/common/PageAnno.vue index 08f8aad3..50c37cad 100644 --- a/src/pages/common/PageAnno.vue +++ b/src/pages/common/PageAnno.vue @@ -64,11 +64,20 @@ import { useAppStore } from "@/store/modules/app.js"; import TGLogger from "@/utils/TGLogger.js"; import { decodeRegExp } from "@/utils/toolFunc.js"; import Hk4eApi, { type AnnoLang, AnnoServer } from "@/web/request/hk4eReq.js"; -import { getAnnoCard } from "@/web/utils/getAnnoCard.js"; type AnnoSelect = { text: string; value: string }; type AnnoKey = keyof typeof AnnoType; -type AnnoCard = { [key in AnnoKey]: Array }; +type AnnoCard = { + id: number; + title: string; + subtitle: string; + banner: string; + typeLabel: string; + tagIcon: string; + tagLabel: string; + timeStr: string; +}; +type AnnoList = { [key in AnnoKey]: Array }; const annoServerList: Array = [ { text: "国服-官方服", value: AnnoServer.CN_ISLAND }, @@ -94,7 +103,7 @@ const { server, lang } = storeToRefs(useAppStore()); const router = useRouter(); const tabValues: Readonly> = ["activity", "game"]; const tab = ref("activity"); -const annoCards = shallowRef({ activity: [], game: [] }); +const annoCards = shallowRef({ activity: [], game: [] }); const isReq = ref(false); watch( @@ -130,7 +139,7 @@ async function loadData(): Promise { `服务器:${getRegionName(server.value)},语言:${getLangName(lang.value)}`, ); const annoData = await Hk4eApi.anno.list(server.value, lang.value); - const listCards = getAnnoCard(annoData); + const listCards = annoData.list.map((list) => list.list.map((anno) => getAnnoCard(anno))).flat(); await showLoading.update("", { title: "正在解析游戏内公告时间" }); for (const item of listCards) { if (item.typeLabel === AnnoType.game) continue; @@ -147,6 +156,38 @@ async function loadData(): Promise { isReq.value = false; } +function getAnnoTag(tag: string): string { + switch (tag) { + case "1": + case "11": + case "重要": + return "公告"; + case "2": + case "扭蛋": + return "祈愿"; + case "3": + return "活动"; + default: + return tag; + } +} + +function getAnnoCard(anno: TGApp.BBS.Announcement.AnnoSingle): AnnoCard { + const timeStart = anno.start_time.split(" ")[0]; + const timeEnd = anno.end_time.split(" ")[0]; + const time = `${timeStart} ~ ${timeEnd}`; + return { + id: anno.ann_id, + title: anno.title, + subtitle: anno.subtitle.replace(/
/g, " "), + banner: anno.banner, + typeLabel: anno.type === 2 ? "游戏公告" : "活动公告", + tagIcon: anno.tag_icon, + tagLabel: getAnnoTag(anno.tag_label), + timeStr: time, + }; +} + function getRegionName(value: AnnoServer): string { return annoServerList.find((item) => item.value === value)?.text ?? annoServerList[0].text; } diff --git a/src/types/App/Announcement.d.ts b/src/types/App/Announcement.d.ts deleted file mode 100644 index ea812598..00000000 --- a/src/types/App/Announcement.d.ts +++ /dev/null @@ -1,32 +0,0 @@ -/** - * @file types App Announcement.d.ts - * @description 应用公告相关类型定义文件 - * @since Beta v0.3.3 - */ - -declare namespace TGApp.App.Announcement { - /** - * @description 渲染用的公告列表数据类型 - * @since Beta v0.3.3 - * @interface ListCard - * @property {number} id - 公告 ID - * @property {string} title - 公告标题 - * @property {string} subtitle - 公告副标题 - * @property {string} banner - 公告横幅 - * @property {string} typeLabel - 公告类型标签 - * @property {string} tagIcon - 公告标签图标 - * @property {string} tagLabel - 公告标签文字 - * @property {string} timeStr - 公告时间字符串 - * @return ListCard - */ - interface ListCard { - id: number; - title: string; - subtitle: string; - banner: string; - typeLabel: string; - tagIcon: string; - tagLabel: string; - timeStr: string; - } -} diff --git a/src/web/utils/getAnnoCard.ts b/src/web/utils/getAnnoCard.ts deleted file mode 100644 index 7dece391..00000000 --- a/src/web/utils/getAnnoCard.ts +++ /dev/null @@ -1,57 +0,0 @@ -/** - * @file web utils transAnno.ts - * @description 公告数据转换工具 - * @since Beta v0.6.1 - */ - -/** - * @description 获取公告标签 - * @since Beta v0.4.4 - * @param {string} tag 标签 - * @returns {string} 标签 - */ -function getAnnoTag(tag: string): string { - switch (tag) { - case "1": - case "11": - case "重要": - return "公告"; - case "2": - case "扭蛋": - return "祈愿"; - case "3": - return "活动"; - default: - return tag; - } -} - -/** - * @description 将获取到的数据转为渲染用的卡片 - * @since Beta v0.6.1 - * @param {TGApp.BBS.Announcement.ListData[]} data 公告数据 - * @returns {TGApp.App.Announcement.ListCard[]} 渲染用的卡片 - */ -export function getAnnoCard( - data: TGApp.BBS.Announcement.ListData, -): Array { - const cards: Array = []; - for (const annoList of data.list) { - for (const anno of annoList.list) { - const timeStart = anno.start_time.split(" ")[0]; - const timeEnd = anno.end_time.split(" ")[0]; - const time = `${timeStart} ~ ${timeEnd}`; - cards.push({ - id: anno.ann_id, - title: anno.title, - subtitle: anno.subtitle.replace(/
/g, " "), - banner: anno.banner, - typeLabel: anno.type === 2 ? "游戏公告" : "活动公告", - tagIcon: anno.tag_icon, - tagLabel: getAnnoTag(anno.tag_label), - timeStr: time, - }); - } - } - return cards; -}