diff --git a/src/core/api/Hk4e.ts b/src/core/api/Hk4e.ts new file mode 100644 index 00000000..52467068 --- /dev/null +++ b/src/core/api/Hk4e.ts @@ -0,0 +1,13 @@ +/** + * @file core api Hk4e.ts + * @description 定义 Hk4e API + * @author BTMuli + * @since Alpha v0.1.2 + */ + +const Hk4eApi = "https://hk4e-api.mihoyo.com"; // 基础 API +const Hk4eAnnoApi = `${Hk4eApi}/common/hk4e_cn/announcement/api`; // 公告 API +export const Hk4eAnnoListApi = `${Hk4eAnnoApi}/getAnnList?`; // 公告列表 API +export const Hk4eAnnoContentApi = `${Hk4eAnnoApi}/getAnnContent?`; // 公告内容 API +export const Hk4eAnnoQuery = + "game=hk4e&game_biz=hk4e_cn&lang=zh-cn&bundle_id=hk4e_cn&platform=pc®ion=cn_gf01&level=60&uid=500299765"; // 公告 Query diff --git a/src/core/api/TGApi.ts b/src/core/api/TGApi.ts new file mode 100644 index 00000000..31d3e332 --- /dev/null +++ b/src/core/api/TGApi.ts @@ -0,0 +1,17 @@ +/** + * @file core api TGApi.ts + * @description 应用用到的 API + * @author BTMuli + * @since Alpha v0.1.2 + */ + +import { Hk4eAnnoListApi, Hk4eAnnoContentApi, Hk4eAnnoQuery } from "./Hk4e"; + +// 应用 API +const TGApi = { + GameAnnoList: Hk4eAnnoListApi, // 游戏公告 API + GameAnnoContent: Hk4eAnnoContentApi, // 游戏公告内容 API + GameAnnoQuery: Hk4eAnnoQuery, // 游戏公告 Query +}; + +export default TGApi; diff --git a/src/core/request/TGRequest.ts b/src/core/request/TGRequest.ts new file mode 100644 index 00000000..bc867218 --- /dev/null +++ b/src/core/request/TGRequest.ts @@ -0,0 +1,17 @@ +/** + * @file core request TGRequest.ts + * @description 应用用到的请求函数 + * @author BTMuli + * @since Alpha v0.1.2 + */ + +import { getAnnoList, getAnnoContent } from "./getAnno"; + +const TGRequest = { + Anno: { + getList: getAnnoList, + getContent: getAnnoContent, + }, +}; + +export default TGRequest; diff --git a/src/core/request/getAnno.ts b/src/core/request/getAnno.ts new file mode 100644 index 00000000..9a7a0be9 --- /dev/null +++ b/src/core/request/getAnno.ts @@ -0,0 +1,37 @@ +/** + * @file core request getAnnouncement.ts + * @description 获取游戏内公告 + * @author BTMuli + * @since Alpha v0.1.2 + */ + +import { http } from "@tauri-apps/api"; +import type TGTypes from "../types/TGTypes"; +import TGApi from "../api/TGApi"; + +/** + * @description 获取游戏内公告列表 + * @since Alpha v0.1.2 + * @returns {Promise} + */ +export async function getAnnoList (): Promise { + return await http.fetch(`${TGApi.GameAnnoList}${TGApi.GameAnnoQuery}`).then((res) => res.data.data); +} + +/** + * @description 获取游戏内公告内容 + * @since Alpha v0.1.2 + * @param {number} annId 公告 ID + * @returns {Promise} + */ +export async function getAnnoContent (annId: number): Promise { + const annoContents: TGTypes.AnnoContentItem[] = await http + .fetch(`${TGApi.GameAnnoContent}${TGApi.GameAnnoQuery}`) + .then((res) => res.data.data.list); + const annoContent = annoContents.find((item) => item.ann_id === annId); + if (annoContent) { + return annoContent; + } else { + throw new Error("公告内容不存在"); + } +} diff --git a/src/plugins/Genshin/interface/announcement.ts b/src/core/types/TGAnno.d.ts similarity index 59% rename from src/plugins/Genshin/interface/announcement.ts rename to src/core/types/TGAnno.d.ts index bb53cebb..63511c34 100644 --- a/src/plugins/Genshin/interface/announcement.ts +++ b/src/core/types/TGAnno.d.ts @@ -1,41 +1,42 @@ /** - * @file plugins Genshin annoList.ts - * @description 原神游戏内公告列表接口 + * @file core types TGAnnouncement.d.ts + * @description 类型定义,用于定义原神游戏内公告相关类型 * @author BTMuli - * @since Alpha v0.1.1 + * @since Alpha v0.1.2 */ -import { type Hk4eResponse } from "./base"; +import type TGBase from "./TGBase"; -/** +namespace TGAnno { + /** * @description 原神游戏内公告列表返回 - * @since Alpha v0.1.1 - * @see ANNO_LIST_API + * @since Alpha v0.1.2 + * @see TGApi.GameAnnoList * @interface AnnoListResponse - * @extends Hk4eResponse + * @extends TGBase.BaseResponse * @property {AnnoListData} data 公告数据 * @returns {AnnoListResponse} */ -export interface AnnoListResponse extends Hk4eResponse { - data: AnnoListData -} + export interface AnnoListResponse extends TGBase.BaseResponse { + data: AnnoListData + } -/** + /** * @description 原神游戏内公告内容返回 - * @since Alpha v0.1.1 - * @see ANNO_CONTENT_API + * @since Alpha v0.1.2 + * @see TGApi.GameAnnoContent * @interface AnnoContentResponse * @extends Hk4eResponse * @property {AnnoContentData} data 公告数据 * @returns {AnnoContentResponse} */ -export interface AnnoContentResponse extends Hk4eResponse { - data: AnnoContentData -} + export interface AnnoContentResponse extends Hk4eResponse { + data: AnnoContentData + } -/** + /** * @description 公告列表数据 - * @since Alpha v0.1.1 + * @since Alpha v0.1.2 * @interface AnnoListData * @property {Announcement[]} list 公告列表 * @property {number} total 公告总数 @@ -52,25 +53,25 @@ export interface AnnoContentResponse extends Hk4eResponse { * @property {unknown} static_sign 静态签名 * @returns {AnnoListData} */ -export interface AnnoListData { - list: Announcement[] - total: number - type_list: AnnoTypeList[] - alert: boolean - alert_id: number - time_zone: number - t: string - pic_list: unknown[] - pic_total: number - pic_type_list: unknown[] - pic_alert: boolean - pic_alert_id: number - static_sign: unknown -} + export interface AnnoListData { + list: Announcement[] + total: number + type_list: AnnoTypeList[] + alert: boolean + alert_id: number + time_zone: number + t: string + pic_list: unknown[] + pic_total: number + pic_type_list: unknown[] + pic_alert: boolean + pic_alert_id: number + static_sign: unknown + } -/** + /** * @description 公告内容数据 - * @since Alpha v0.1.1 + * @since Alpha v0.1.2 * @interface AnnoContentData * @property {AnnoContentItem[]} list 公告列表 * @property {number} total 公告总数 @@ -78,46 +79,46 @@ export interface AnnoListData { * @property {number} pic_total 图片总数 * @returns {AnnoContentData} */ -export interface AnnoContentData { - list: AnnoContentItem[] - total: number - pic_list: unknown[] - pic_total: number -} + export interface AnnoContentData { + list: AnnoContentItem[] + total: number + pic_list: unknown[] + pic_total: number + } -/** + /** * @description 公告类型列表 - * @since Alpha v0.1.1 + * @since Alpha v0.1.2 * @interface AnnoTypeList * @property {number} id 类型 ID * @property {string} name 类型名称 * @property {string} mi18n_name 类型名称 * @returns {AnnoTypeList} */ -export interface AnnoTypeList { - id: number - name: string - mi18n_name: string -} + export interface AnnoTypeList { + id: number + name: string + mi18n_name: string + } -/** + /** * @description 公告 - * @since Alpha v0.1.1 + * @since Alpha v0.1.2 * @interface Announcement * @property {AnnoListItem[]} list 公告列表 * @property {number} type_id 类型 ID * @property {string} type_label 类型标签 * @returns {Announcement} */ -export interface Announcement { - list: AnnoListItem[] - type_id: number - type_label: string -} + export interface Announcement { + list: AnnoListItem[] + type_id: number + type_label: string + } -/** + /** * @description 公告列表项 - * @since Alpha v0.1.1 + * @since Alpha v0.1.2 * @interface AnnoListItem * @property {number} ann_id 公告 ID * @property {string} title 公告标题 @@ -141,32 +142,32 @@ export interface Announcement { * @property {boolean} extra_remind 是否有额外提醒 * @returns {AnnoListItem} */ -export interface AnnoListItem { - ann_id: number - title: string - subtitle: string - banner: string - content: unknown - type_label: string - tag_label: string - tag_icon: string - login_alert: number - lang: string - start_time: string - end_time: string - type: number - remind: number - alert: number - tag_start_time: string - tag_end_time: string - remind_ver: number - has_content: boolean - extra_remind: boolean -} + export interface AnnoListItem { + ann_id: number + title: string + subtitle: string + banner: string + content: unknown + type_label: string + tag_label: string + tag_icon: string + login_alert: number + lang: string + start_time: string + end_time: string + type: number + remind: number + alert: number + tag_start_time: string + tag_end_time: string + remind_ver: number + has_content: boolean + extra_remind: boolean + } -/** + /** * @description 公告内容列表 - * @since Alpha v0.1.1 + * @since Alpha v0.1.2 * @interface AnnoContentItem * @property {number} ann_id 公告 ID * @property {string} title 公告标题 @@ -176,36 +177,40 @@ export interface AnnoListItem { * @property {string} lang 公告语言 * @returns {AnnoContentItem} */ -export interface AnnoContentItem { - ann_id: number - title: string - subtitle: string - banner: string - content: string - lang: string -} + export interface AnnoContentItem { + ann_id: number + title: string + subtitle: string + banner: string + content: string + lang: string + } -/** + /** * @description 渲染用公告列表数据 - * @since Alpha v0.1.1 + * @since Alpha v0.1.2 * @interface AnnoListCard * @property {number} id 公告 ID * @property {string} title 公告标题 * @property {string} subtitle 公告副标题 * @property {string} banner 公告图片 - * @property {string} type_label 公告类型标签 - * @property {string} tag_icon 公告标签图标 - * @property {string} start_time 公告开始时间 - * @property {string} end_time 公告结束时间 + * @property {string} typeLabel 公告类型标签 + * @property {string} tagIcon 公告标签图标 + * @property {string} startTime 公告开始时间 + * @property {string} endTime 公告结束时间 * @returns {AnnoListCard} */ -export interface AnnoListCard { - id: number - title: string - subtitle: string - banner: string - type_label: string - tag_icon: string - start_time: string - end_time: string + export interface AnnoListCard { + id: number + title: string + subtitle: string + banner: string + typeLabel: string + tagIcon: string + startTime: string + endTime: string + } + } + +export default TGAnno; diff --git a/src/core/types/TGBase.d.ts b/src/core/types/TGBase.d.ts index 1fd8a036..ca929c0b 100644 --- a/src/core/types/TGBase.d.ts +++ b/src/core/types/TGBase.d.ts @@ -20,6 +20,21 @@ namespace TGBase { keyPath: string indexes: string[] } + + /** + * @description 定义基础返回数据 + * @since Alpha v0.1.2 + * @interface BaseResponse + * @property {number} retcode 状态码 + * @property {string} message 状态信息 + * @property {any} data 数据 + * @returns {BaseResponse} + */ + export interface BaseResponse { + retcode: number + message: string + data: any + } } export default TGBase; diff --git a/src/core/types/TGTypes.d.ts b/src/core/types/TGTypes.d.ts index ae17b0fb..4a1f2467 100644 --- a/src/core/types/TGTypes.d.ts +++ b/src/core/types/TGTypes.d.ts @@ -6,6 +6,7 @@ */ import type TGAchievement from "./TGAchievement"; +import type TGAnno from "./TGAnno"; import type TGBase from "./TGBase"; import type TGCalendar from "./TGCalendar"; import type TGNameCard from "./TGNameCard"; @@ -13,6 +14,15 @@ import type TGNameCard from "./TGNameCard"; namespace TGTypes { export type Achievement = TGAchievement.Achievement; export type AchievementSeries = TGAchievement.AchievementSeries; + export type AnnoListResponse = TGAnno.AnnoListResponse; + export type AnnoContentResponse = TGAnno.AnnoContentResponse; + export type AnnoContentData = TGAnno.AnnoContentData; + export type AnnoContentItem = TGAnno.AnnoContentItem; + export type AnnoListCard = TGAnno.AnnoListCard; + export type AnnoListData = TGAnno.AnnoListData; + export type AnnoListItem = TGAnno.AnnoListItem; + export type AnnoTypeList = TGAnno.AnnoTypeList; + export type Announcement = TGAnno.Announcement; export type CalendarData = TGCalendar.CalendarData; export type CalendarItem = TGCalendar.CalendarItem; export type CalendarMaterial = TGCalendar.CalendarMaterial; diff --git a/src/core/utils/TGUtils.ts b/src/core/utils/TGUtils.ts new file mode 100644 index 00000000..c4d2ead4 --- /dev/null +++ b/src/core/utils/TGUtils.ts @@ -0,0 +1,18 @@ +/** + * @file core utils TGUtils.ts + * @description 应用用到的工具函数 + * @author BTMuli + * @since Alpha v0.1.2 + */ + +import { parseAnnoContent } from "./parseAnno"; +import { getAnnoCard } from "./getAnnoCard"; + +const TGUtils = { + Anno: { + getCard: getAnnoCard, + parseContent: parseAnnoContent, + }, +}; + +export default TGUtils; diff --git a/src/core/utils/getAnnoCard.ts b/src/core/utils/getAnnoCard.ts new file mode 100644 index 00000000..43a9c9fd --- /dev/null +++ b/src/core/utils/getAnnoCard.ts @@ -0,0 +1,33 @@ +/** + * @file core utils transAnno.ts + * @description 公告数据转换工具 + * @author BTMuli + * @since Alpha v0.1.2 + */ + +import type TGTypes from "../types/TGTypes"; + +/** + * @description 将获取到的数据转为渲染用的卡片 + * @since Alpha v0.1.2 + * @param {TGTypes.AnnoListData} data 公告数据 + * @returns {AnnoListCard[]} 渲染用的卡片 + */ +export function getAnnoCard (data: TGTypes.AnnoListData): TGTypes.AnnoListCard[] { + const cards: TGTypes.AnnoListCard[] = []; + data.list.map((annoList: TGTypes.Announcement) => { + return annoList.list.map((anno: TGTypes.AnnoListItem) => { + return cards.push({ + id: anno.ann_id, + title: anno.title, + subtitle: anno.subtitle, + banner: anno.banner, + typeLabel: anno.type_label, + tagIcon: anno.tag_icon, + startTime: anno.start_time, + endTime: anno.end_time, + }); + }); + }); + return cards; +} diff --git a/src/plugins/Genshin/utils/annoParser.ts b/src/core/utils/parseAnno.ts similarity index 69% rename from src/plugins/Genshin/utils/annoParser.ts rename to src/core/utils/parseAnno.ts index 74676332..0d2f7160 100644 --- a/src/plugins/Genshin/utils/annoParser.ts +++ b/src/core/utils/parseAnno.ts @@ -1,19 +1,20 @@ /** - * @file plugins Genshin utils annoParser.ts - * @description 原神游戏内公告解析工具 + * @file core utils parseAnno.ts + * @description 解析游戏内公告数据 * @author BTMuli - * @since Alpha v0.1.1 + * @since Alpha v0.1.2 */ +import { decodeRegExp } from "./tools"; + /** * @description 解析游戏内公告数据 - * @since Alpha v0.1.1 + * @since Alpha v0.1.2 * @param {string} data 游戏内公告数据 * @returns {string} 解析后的数据 */ export function parseAnnoContent (data: string): string { const htmlBase = new DOMParser().parseFromString(data, "text/html"); - // 遍历所有 span 标签 htmlBase.querySelectorAll("span").forEach((span) => { if (span.style.fontSize) { span.style.fontSize = ""; @@ -28,9 +29,7 @@ export function parseAnnoContent (data: string): string { }); } }); - // 遍历所有 p 标签 htmlBase.querySelectorAll("p").forEach((p) => { - // 如果没有子元素 if (p.children.length === 0) { return (p.innerHTML = decodeRegExp(p.innerHTML)); } else { @@ -41,11 +40,9 @@ export function parseAnnoContent (data: string): string { }); } }); - // 遍历所有 a 标签 htmlBase.querySelectorAll("a").forEach((a) => { const span = htmlBase.createElement("i"); span.classList.add("mdi", "mdi-link-variant", "anno-link-icon"); - // 添加到 a 标签中 a.prepend(span); if (a.href.startsWith("javascript:miHoYoGameJSSDK.openInBrowser")) { a.href = a.href.replace("javascript:miHoYoGameJSSDK.openInBrowser('", "").replace("');", ""); @@ -57,22 +54,3 @@ export function parseAnnoContent (data: string): string { }); return htmlBase.body.innerHTML; } - -/** - * @description 转义正则表达式 - * @since Alpha v0.1.2 - * @param {string} data 内容 - * @returns {string} 转义后的内容 - */ -export function decodeRegExp (data: string): string { - let res = data; - if (res.length === 0) return res; - res = res.replace(/</g, "<"); - res = res.replace(/>/g, ">"); - res = res.replace(/ /g, " "); - res = res.replace(/'/g, "'"); - res = res.replace(/"/g, "\""); - res = res.replace(/'/g, "'"); - res = res.replace(/&/g, "&"); - return res; -} diff --git a/src/core/utils/tools.ts b/src/core/utils/tools.ts new file mode 100644 index 00000000..bb04d25e --- /dev/null +++ b/src/core/utils/tools.ts @@ -0,0 +1,25 @@ +/** + * @file core utils tools.ts + * @description 应用用到的工具函数 + * @author BTMuli + * @since Alpha v0.1.2 + */ + +/** + * @description 转义正则表达式 + * @since Alpha v0.1.2 + * @param {string} data 内容 + * @returns {string} 转义后的内容 + */ +export function decodeRegExp (data: string): string { + let res = data; + if (res.length === 0) return res; + res = res.replace(/</g, "<"); + res = res.replace(/>/g, ">"); + res = res.replace(/ /g, " "); + res = res.replace(/'/g, "'"); + res = res.replace(/"/g, "\""); + res = res.replace(/'/g, "'"); + res = res.replace(/&/g, "&"); + return res; +} diff --git a/src/pages/Announcements.vue b/src/pages/Announcements.vue index 9679234d..76847294 100644 --- a/src/pages/Announcements.vue +++ b/src/pages/Announcements.vue @@ -28,14 +28,14 @@ 查看 mdi-calendar - {{ item.start_time.split(" ")[0] }} - - {{ item.end_time.split(" ")[0] }} + {{ item.startTime.split(" ")[0] }} - + {{ item.endTime.split(" ")[0] }} id: {{ item.id }} @@ -61,14 +61,14 @@ 查看 mdi-calendar - {{ item.start_time.split(" ")[0] }} - - {{ item.end_time.split(" ")[0] }} + {{ item.startTime.split(" ")[0] }} - + {{ item.endTime.split(" ")[0] }} id: {{ item.id }} @@ -92,13 +92,15 @@ import { onMounted, ref } from "vue"; import { useRouter } from "vue-router"; import TLoading from "../components/t-loading.vue"; -// plugin -import GenshinOper from "../plugins/Genshin"; -// utils -import { createTGWindow } from "../utils/TGWindow"; -// interface -import { AnnoListData, AnnoListCard } from "../plugins/Genshin/interface/announcement"; +// store import { useAppStore } from "../store/modules/app"; +// utils +import TGRequest from "../core/request/TGRequest"; +import TGUtils from "../core/utils/TGUtils"; +import { createTGWindow } from "../utils/TGWindow"; + +// interface +import type TGTypes from "../core/types/TGTypes"; // store const appStore = useAppStore(); @@ -112,18 +114,18 @@ const router = useRouter(); // 数据 const tab = ref(""); const annoCards = ref({ - activity: [] as AnnoListCard[], - game: [] as AnnoListCard[], + activity: [] as TGTypes.AnnoListCard[], + game: [] as TGTypes.AnnoListCard[], }); -const annoData = ref({} as AnnoListData); +const annoData = ref({} as TGTypes.AnnoListData); onMounted(async () => { loadingTitle.value = "正在获取公告数据"; - annoData.value = await GenshinOper.Announcement.getList(); + annoData.value = await TGRequest.Anno.getList(); loadingTitle.value = "正在转换公告数据"; - const listCards = GenshinOper.Announcement.card(annoData.value); - const activityCard = listCards.filter((item) => item.type_label === "活动公告"); - const newsCard = listCards.filter((item) => item.type_label === "游戏公告"); + const listCards = TGUtils.Anno.getCard(annoData.value); + const activityCard = listCards.filter((item) => item.typeLabel === "活动公告"); + const newsCard = listCards.filter((item) => item.typeLabel === "游戏公告"); annoCards.value = { activity: activityCard, game: newsCard, @@ -136,7 +138,7 @@ async function switchNews () { await router.push("/news"); } -async function toPost (item: AnnoListCard) { +async function toPost (item: TGTypes.AnnoListCard) { const path = router.resolve({ name: "游戏内公告", params: { @@ -147,7 +149,7 @@ async function toPost (item: AnnoListCard) { createTGWindow(path, "游戏内公告", item.title, 960, 720, false, false); } -async function toJson (item: AnnoListCard) { +async function toJson (item: TGTypes.AnnoListCard) { const path = router.resolve({ name: "游戏内公告(JSON)", params: { diff --git a/src/plugins/Genshin/index.ts b/src/plugins/Genshin/index.ts deleted file mode 100644 index 58a05b72..00000000 --- a/src/plugins/Genshin/index.ts +++ /dev/null @@ -1,22 +0,0 @@ -/** - * @file plugins Genshin index.ts - * @description Genshin plugin index - * @author BTMuli - * @since Alpha v0.1.1 - */ - -// Announcement -import { getAnnouncementList, getAnnouncementContent } from "./request/announcements"; -import { getAnnoCards } from "./utils/announcements"; -import { parseAnnoContent } from "./utils/annoParser"; - -const GenshinOper = { - Announcement: { - getList: getAnnouncementList, - getContent: getAnnouncementContent, - card: getAnnoCards, - parser: parseAnnoContent, - }, -}; - -export default GenshinOper; diff --git a/src/plugins/Genshin/interface/base.ts b/src/plugins/Genshin/interface/base.ts deleted file mode 100644 index 65133405..00000000 --- a/src/plugins/Genshin/interface/base.ts +++ /dev/null @@ -1,21 +0,0 @@ -/** - * @file plugins Genshin interface base.ts - * @description 原神插件基础接口 - * @author BTMuli - * @since Alpha v0.1.1 - */ - -/** - * @description Mys Response 统一接口,负责游戏内数据获取 - * @since Alpha v0.1.1 - * @interface Hk4eResponse - * @property {number} retcode 状态码 - * @property {string} message 状态信息 - * @property {any} data 数据 - * @returns {Hk4eResponse} - */ -export interface Hk4eResponse { - retcode: number - message: string - data: any -} diff --git a/src/plugins/Genshin/request/announcements.ts b/src/plugins/Genshin/request/announcements.ts deleted file mode 100644 index 6fac0a5c..00000000 --- a/src/plugins/Genshin/request/announcements.ts +++ /dev/null @@ -1,49 +0,0 @@ -/** - * @file plugins Genshin request announcements.ts - * @description 原神游戏内公告请求 - * @author BTMuli - * @since Alpha v0.1.2 - */ - -import { http } from "@tauri-apps/api"; -import { Hk4eAnnoApi } from "./base"; -import { - type AnnoListResponse, - type AnnoContentResponse, - type AnnoListData, - type AnnoContentItem, -} from "../interface/announcement"; - -// 公告 API -const ANNO_LIST_API = `${Hk4eAnnoApi}/getAnnList?`; -const ANNO_CONTENT_API = `${Hk4eAnnoApi}/getAnnContent?`; -// 公告 Query -const ANNO_QUERY = - "game=hk4e&game_biz=hk4e_cn&lang=zh-cn&bundle_id=hk4e_cn&platform=pc®ion=cn_gf01&level=60&uid=500299765"; - -/** - * @description 获取游戏内公告列表 - * @since Alpha v0.1.1 - * @returns {Promise} - */ -export async function getAnnouncementList (): Promise { - return await http.fetch(`${ANNO_LIST_API}${ANNO_QUERY}`).then((res) => res.data.data); -} - -/** - * @description 获取游戏内公告内容 - * @since Alpha v0.1.2 - * @param {number} annId 公告 ID - * @returns {Promise} - */ -export async function getAnnouncementContent (annId: number): Promise { - const annoContents: AnnoContentItem[] = await http - .fetch(`${ANNO_CONTENT_API}${ANNO_QUERY}`) - .then((res) => res.data.data.list); - const annoContent = annoContents.find((item) => item.ann_id === annId); - if (annoContent) { - return annoContent; - } else { - throw new Error("公告内容不存在"); - } -} diff --git a/src/plugins/Genshin/request/base.ts b/src/plugins/Genshin/request/base.ts deleted file mode 100644 index 02c1a08a..00000000 --- a/src/plugins/Genshin/request/base.ts +++ /dev/null @@ -1,11 +0,0 @@ -/** - * @file plugins Genshin request base.ts - * @description 游戏内数据请求的基础类 - * @author BTMuli - * @since Alpha v0.1.2 - */ - -// Hk4e API,目前先用这几个,后续有需要再加 -const Hk4eApi = "https://hk4e-api.mihoyo.com"; // 基础 API -export const Hk4eAnnoApi = `${Hk4eApi}/common/hk4e_cn/announcement/api`; // 公告 API -export const Hk4eGachaApi = `${Hk4eApi}/event/gacha_info/api;`; // 卡池 API diff --git a/src/plugins/Genshin/utils/announcements.ts b/src/plugins/Genshin/utils/announcements.ts deleted file mode 100644 index ae4aba56..00000000 --- a/src/plugins/Genshin/utils/announcements.ts +++ /dev/null @@ -1,33 +0,0 @@ -/** - * @file plugins Genshin utils announcements.ts - * @description 原神游戏内公告工具 - * @author BTMuli - * @since Alpha v0.1.1 - */ - -import { type AnnoListData, type AnnoListCard, type Announcement, type AnnoListItem } from "../interface/announcement"; - -/** - * @description 将获取到的数据转为渲染用的卡片 - * @since Alpha v0.1.1 - * @param {AnnoListData} data 公告数据 - * @returns {AnnoListCard[]} 渲染用的卡片 - */ -export function getAnnoCards (data: AnnoListData): AnnoListCard[] { - const cards: AnnoListCard[] = []; - data.list.map((annoList: Announcement) => { - return annoList.list.map((anno: AnnoListItem) => { - return cards.push({ - id: anno.ann_id, - title: anno.title, - subtitle: anno.subtitle, - banner: anno.banner, - type_label: anno.type_label, - tag_icon: anno.tag_icon, - start_time: anno.start_time, - end_time: anno.end_time, - }); - }); - }); - return cards; -} diff --git a/src/views/t-anno-json.vue b/src/views/t-anno-json.vue index c6b756d5..ef19c556 100644 --- a/src/views/t-anno-json.vue +++ b/src/views/t-anno-json.vue @@ -21,10 +21,10 @@ import JsonViewer from "vue-json-viewer"; import TLoading from "../components/t-loading.vue"; // tauri import { appWindow } from "@tauri-apps/api/window"; -// plugins -import GenshinOper from "../plugins/Genshin"; +// utils +import TGRequest from "../core/request/TGRequest"; // interface -import { AnnoListItem, Announcement } from "../plugins/Genshin/interface/announcement"; +import type TGTypes from "../core/types/TGTypes"; // loading const loading = ref(true as boolean); @@ -46,13 +46,13 @@ onMounted(async () => { } // 获取数据 loadingTitle.value = "正在获取数据..."; - const listData = await GenshinOper.Announcement.getList(); - listData.list.map((item: Announcement) => { - return item.list.map((single: AnnoListItem) => { + const listData = await TGRequest.Anno.getList(); + listData.list.map((item: TGTypes.Announcement) => { + return item.list.map((single: TGTypes.AnnoListItem) => { return single.ann_id === annoId ? (jsonList = single) : null; }); }); - jsonContent = await GenshinOper.Announcement.getContent(annoId); + jsonContent = await TGRequest.Anno.getContent(annoId); setTimeout(() => { loading.value = false; }, 200); diff --git a/src/views/t-anno.vue b/src/views/t-anno.vue index 089f1522..f4297f3c 100644 --- a/src/views/t-anno.vue +++ b/src/views/t-anno.vue @@ -22,9 +22,10 @@ import TLoading from "../components/t-loading.vue"; // tauri import { appWindow } from "@tauri-apps/api/window"; // plugins -import GenshinOper from "../plugins/Genshin"; +import TGRequest from "../core/request/TGRequest"; +import TGUtils from "../core/utils/TGUtils"; // interface -import { AnnoContentItem } from "../plugins/Genshin/interface/announcement"; +import type TGTypes from "../core/types/TGTypes"; // loading const loading = ref(true as boolean); @@ -33,7 +34,7 @@ const loadingEmpty = ref(false as boolean); // 数据 const annoId = Number(useRoute().params.anno_id); -const annoData = ref({} as AnnoContentItem); +const annoData = ref({} as TGTypes.AnnoContentItem); const annoHtml = ref(""); onMounted(async () => { @@ -47,9 +48,9 @@ onMounted(async () => { // 获取数据 loadingTitle.value = "正在获取数据..."; try { - annoData.value = await GenshinOper.Announcement.getContent(annoId); + annoData.value = await TGRequest.Anno.getContent(annoId); loadingTitle.value = "正在渲染数据..."; - annoHtml.value = GenshinOper.Announcement.parser(annoData.value.content); + annoHtml.value = TGUtils.Anno.parseContent(annoData.value.content); } catch (error) { loadingEmpty.value = true; loadingTitle.value = "公告不存在或解析失败";