🎨 refractor(genshin): 将 genshin 插件转移到 core 目录下

This commit is contained in:
BTMuli
2023-04-10 00:16:45 +08:00
parent a238dc5eed
commit d7494739f6
19 changed files with 337 additions and 302 deletions

13
src/core/api/Hk4e.ts Normal file
View File

@@ -0,0 +1,13 @@
/**
* @file core api Hk4e.ts
* @description 定义 Hk4e API
* @author BTMuli<bt-muli@outlook.com>
* @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&region=cn_gf01&level=60&uid=500299765"; // 公告 Query

17
src/core/api/TGApi.ts Normal file
View File

@@ -0,0 +1,17 @@
/**
* @file core api TGApi.ts
* @description 应用用到的 API
* @author BTMuli<bt-muli@outlook.com>
* @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;

View File

@@ -0,0 +1,17 @@
/**
* @file core request TGRequest.ts
* @description 应用用到的请求函数
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.1.2
*/
import { getAnnoList, getAnnoContent } from "./getAnno";
const TGRequest = {
Anno: {
getList: getAnnoList,
getContent: getAnnoContent,
},
};
export default TGRequest;

View File

@@ -0,0 +1,37 @@
/**
* @file core request getAnnouncement.ts
* @description 获取游戏内公告
* @author BTMuli<bt-muli@outlook.com>
* @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<TGTypes.AnnoListData>}
*/
export async function getAnnoList (): Promise<TGTypes.AnnoListData> {
return await http.fetch<TGTypes.AnnoListResponse>(`${TGApi.GameAnnoList}${TGApi.GameAnnoQuery}`).then((res) => res.data.data);
}
/**
* @description 获取游戏内公告内容
* @since Alpha v0.1.2
* @param {number} annId 公告 ID
* @returns {Promise<AnnoContentItem>}
*/
export async function getAnnoContent (annId: number): Promise<TGTypes.AnnoContentItem> {
const annoContents: TGTypes.AnnoContentItem[] = await http
.fetch<TGTypes.AnnoContentResponse>(`${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("公告内容不存在");
}
}

View File

@@ -1,41 +1,42 @@
/**
* @file plugins Genshin annoList.ts
* @description
* @file core types TGAnnouncement.d.ts
* @description
* @author BTMuli<bt-muli@outlook.com>
* @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;

View File

@@ -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;

View File

@@ -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;

18
src/core/utils/TGUtils.ts Normal file
View File

@@ -0,0 +1,18 @@
/**
* @file core utils TGUtils.ts
* @description 应用用到的工具函数
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.1.2
*/
import { parseAnnoContent } from "./parseAnno";
import { getAnnoCard } from "./getAnnoCard";
const TGUtils = {
Anno: {
getCard: getAnnoCard,
parseContent: parseAnnoContent,
},
};
export default TGUtils;

View File

@@ -0,0 +1,33 @@
/**
* @file core utils transAnno.ts
* @description 公告数据转换工具
* @author BTMuli<bt-muli@outlook.com>
* @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;
}

View File

@@ -1,19 +1,20 @@
/**
* @file plugins Genshin utils annoParser.ts
* @description
* @file core utils parseAnno.ts
* @description
* @author BTMuli<bt-muli@outlook.com>
* @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(/&lt;/g, "<");
res = res.replace(/&gt;/g, ">");
res = res.replace(/&nbsp;/g, " ");
res = res.replace(/&#39;/g, "'");
res = res.replace(/&quot;/g, "\"");
res = res.replace(/&apos;/g, "'");
res = res.replace(/&amp;/g, "&");
return res;
}

25
src/core/utils/tools.ts Normal file
View File

@@ -0,0 +1,25 @@
/**
* @file core utils tools.ts
* @description 应用用到的工具函数
* @author BTMuli<bt-muli@outlook.com>
* @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(/&lt;/g, "<");
res = res.replace(/&gt;/g, ">");
res = res.replace(/&nbsp;/g, " ");
res = res.replace(/&#39;/g, "'");
res = res.replace(/&quot;/g, "\"");
res = res.replace(/&apos;/g, "'");
res = res.replace(/&amp;/g, "&");
return res;
}

View File

@@ -28,14 +28,14 @@
<v-card-actions>
<v-btn class="anno-btn" @click="toPost(item)">
<template #prepend>
<img :src="item.tag_icon || '../assets/icons/arrow-right.svg'" alt="right">
<img :src="item.tagIcon || '../assets/icons/arrow-right.svg'" alt="right">
</template>
查看
</v-btn>
<v-card-subtitle v-show="!appStore.devMode">
<v-icon>mdi-calendar</v-icon>
{{ item.start_time.split(" ")[0] }} -
{{ item.end_time.split(" ")[0] }}
{{ item.startTime.split(" ")[0] }} -
{{ item.endTime.split(" ")[0] }}
</v-card-subtitle>
<v-card-subtitle v-show="appStore.devMode">
id: {{ item.id }}
@@ -61,14 +61,14 @@
<v-card-actions>
<v-btn class="anno-btn" @click="toPost(item)">
<template #prepend>
<img :src="item.tag_icon || '../assets/icons/arrow-right.svg'" alt="right">
<img :src="item.tagIcon || '../assets/icons/arrow-right.svg'" alt="right">
</template>
查看
</v-btn>
<v-card-subtitle v-show="!appStore.devMode">
<v-icon>mdi-calendar</v-icon>
{{ item.start_time.split(" ")[0] }} -
{{ item.end_time.split(" ")[0] }}
{{ item.startTime.split(" ")[0] }} -
{{ item.endTime.split(" ")[0] }}
</v-card-subtitle>
<v-card-subtitle v-show="appStore.devMode">
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: {

View File

@@ -1,22 +0,0 @@
/**
* @file plugins Genshin index.ts
* @description Genshin plugin index
* @author BTMuli<bt-muli@outlook.com>
* @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;

View File

@@ -1,21 +0,0 @@
/**
* @file plugins Genshin interface base.ts
* @description 原神插件基础接口
* @author BTMuli<bt-muli@outlook.com>
* @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
}

View File

@@ -1,49 +0,0 @@
/**
* @file plugins Genshin request announcements.ts
* @description 原神游戏内公告请求
* @author BTMuli<bt-muli@outlook.com>
* @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&region=cn_gf01&level=60&uid=500299765";
/**
* @description 获取游戏内公告列表
* @since Alpha v0.1.1
* @returns {Promise<AnnoListData>}
*/
export async function getAnnouncementList (): Promise<AnnoListData> {
return await http.fetch<AnnoListResponse>(`${ANNO_LIST_API}${ANNO_QUERY}`).then((res) => res.data.data);
}
/**
* @description 获取游戏内公告内容
* @since Alpha v0.1.2
* @param {number} annId 公告 ID
* @returns {Promise<AnnoContentItem>}
*/
export async function getAnnouncementContent (annId: number): Promise<AnnoContentItem> {
const annoContents: AnnoContentItem[] = await http
.fetch<AnnoContentResponse>(`${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("公告内容不存在");
}
}

View File

@@ -1,11 +0,0 @@
/**
* @file plugins Genshin request base.ts
* @description 游戏内数据请求的基础类
* @author BTMuli<bt-muli@outlook.com>
* @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

View File

@@ -1,33 +0,0 @@
/**
* @file plugins Genshin utils announcements.ts
* @description 原神游戏内公告工具
* @author BTMuli<bt-muli@outlook.com>
* @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;
}

View File

@@ -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);

View File

@@ -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 = "公告不存在或解析失败";