mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-13 09:28:14 +08:00
🎨 refractor(genshin): 将 genshin 插件转移到 core 目录下
This commit is contained in:
13
src/core/api/Hk4e.ts
Normal file
13
src/core/api/Hk4e.ts
Normal 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®ion=cn_gf01&level=60&uid=500299765"; // 公告 Query
|
||||
17
src/core/api/TGApi.ts
Normal file
17
src/core/api/TGApi.ts
Normal 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;
|
||||
17
src/core/request/TGRequest.ts
Normal file
17
src/core/request/TGRequest.ts
Normal 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;
|
||||
37
src/core/request/getAnno.ts
Normal file
37
src/core/request/getAnno.ts
Normal 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("公告内容不存在");
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
15
src/core/types/TGBase.d.ts
vendored
15
src/core/types/TGBase.d.ts
vendored
@@ -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;
|
||||
|
||||
10
src/core/types/TGTypes.d.ts
vendored
10
src/core/types/TGTypes.d.ts
vendored
@@ -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
18
src/core/utils/TGUtils.ts
Normal 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;
|
||||
33
src/core/utils/getAnnoCard.ts
Normal file
33
src/core/utils/getAnnoCard.ts
Normal 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;
|
||||
}
|
||||
@@ -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(/</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;
|
||||
}
|
||||
25
src/core/utils/tools.ts
Normal file
25
src/core/utils/tools.ts
Normal 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(/</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;
|
||||
}
|
||||
@@ -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: {
|
||||
|
||||
@@ -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;
|
||||
@@ -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
|
||||
}
|
||||
@@ -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®ion=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("公告内容不存在");
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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 = "公告不存在或解析失败";
|
||||
|
||||
Reference in New Issue
Block a user