mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-13 09:28:14 +08:00
@@ -5,9 +5,7 @@
|
||||
*/
|
||||
import { http } from "@tauri-apps/api";
|
||||
|
||||
import type { AnnoLang } from "../../pages/common/Announcements.vue";
|
||||
|
||||
export enum SERVER {
|
||||
export enum AnnoServer {
|
||||
CN_ISLAND = "cn_gf01",
|
||||
CN_TREE = "cn_qd01",
|
||||
OS_USA = "os_usa",
|
||||
@@ -16,14 +14,19 @@ export enum SERVER {
|
||||
OS_CHT = "os_cht",
|
||||
}
|
||||
|
||||
export type AnnoLang = "zh-cn" | "zh-tw" | "en" | "ja";
|
||||
|
||||
/**
|
||||
* @description 获取游戏内公告参数
|
||||
* @since Beta v0.4.4
|
||||
* @param {SERVER} region 服务器
|
||||
* @param {AnnoServer} region 服务器
|
||||
* @param {string} lang 语言
|
||||
* @returns {TGApp.BBS.Announcement.Params}
|
||||
*/
|
||||
function getAnnoParams(region: SERVER, lang: AnnoLang = "zh-cn"): TGApp.BBS.Announcement.Params {
|
||||
function getAnnoParams(
|
||||
region: AnnoServer = AnnoServer.CN_ISLAND,
|
||||
lang: AnnoLang = "zh-cn",
|
||||
): TGApp.BBS.Announcement.Params {
|
||||
const params: TGApp.BBS.Announcement.Params = {
|
||||
game: "hk4e",
|
||||
game_biz: "hk4e_cn",
|
||||
@@ -34,7 +37,7 @@ function getAnnoParams(region: SERVER, lang: AnnoLang = "zh-cn"): TGApp.BBS.Anno
|
||||
level: "55",
|
||||
uid: "100000000",
|
||||
};
|
||||
if (region === SERVER.CN_ISLAND || region === SERVER.CN_TREE) {
|
||||
if (region === AnnoServer.CN_ISLAND || region === AnnoServer.CN_TREE) {
|
||||
return params;
|
||||
}
|
||||
params.game_biz = "hk4e_global";
|
||||
@@ -50,12 +53,12 @@ function getAnnoParams(region: SERVER, lang: AnnoLang = "zh-cn"): TGApp.BBS.Anno
|
||||
* @returns {Promise<TGApp.BBS.Announcement.ListData>}
|
||||
*/
|
||||
export async function getAnnoList(
|
||||
region: SERVER = SERVER.CN_ISLAND,
|
||||
region: AnnoServer = AnnoServer.CN_ISLAND,
|
||||
lang: AnnoLang = "zh-cn",
|
||||
): Promise<TGApp.BBS.Announcement.ListData> {
|
||||
const params: TGApp.BBS.Announcement.Params = getAnnoParams(region, lang);
|
||||
let url = "https://hk4e-api.mihoyo.com/common/hk4e_cn/announcement/api/getAnnList";
|
||||
if (region !== SERVER.CN_ISLAND && region !== SERVER.CN_TREE) {
|
||||
if (region !== AnnoServer.CN_ISLAND && region !== AnnoServer.CN_TREE) {
|
||||
url = "https://hk4e-api-os.hoyoverse.com/common/hk4e_global/announcement/api/getAnnList";
|
||||
}
|
||||
return await http
|
||||
@@ -70,18 +73,18 @@ export async function getAnnoList(
|
||||
* @description 获取游戏内公告内容
|
||||
* @since Beta v0.4.3
|
||||
* @param {number} annId 公告 ID
|
||||
* @param {SERVER} region 服务器
|
||||
* @param {AnnoServer} region 服务器
|
||||
* @param {AnnoLang} lang 语言
|
||||
* @returns {Promise<TGApp.BBS.Announcement.ContentItem>}
|
||||
*/
|
||||
export async function getAnnoContent(
|
||||
annId: number,
|
||||
region: SERVER,
|
||||
region: AnnoServer = AnnoServer.CN_ISLAND,
|
||||
lang: AnnoLang = "zh-cn",
|
||||
): Promise<TGApp.BBS.Announcement.ContentItem> {
|
||||
const params: TGApp.BBS.Announcement.Params = getAnnoParams(region, lang);
|
||||
let url = "https://hk4e-api.mihoyo.com/common/hk4e_cn/announcement/api/getAnnContent";
|
||||
if (region !== SERVER.CN_ISLAND && region !== SERVER.CN_TREE) {
|
||||
if (region !== AnnoServer.CN_ISLAND && region !== AnnoServer.CN_TREE) {
|
||||
url = "https://hk4e-api-os.hoyoverse.com/common/hk4e_global/announcement/api/getAnnContent";
|
||||
}
|
||||
const annoContents: TGApp.BBS.Announcement.ContentItem[] = await http
|
||||
|
||||
@@ -1,12 +1,34 @@
|
||||
/**
|
||||
* @file web utils transAnno.ts
|
||||
* @description 公告数据转换工具
|
||||
* @since Beta v0.3.3
|
||||
* @since Beta v0.4.4
|
||||
*/
|
||||
|
||||
// 默认封面图
|
||||
const defaultCover = "/source/UI/defaultCover.webp";
|
||||
|
||||
/**
|
||||
* @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.4.3
|
||||
@@ -25,11 +47,11 @@ export function getAnnoCard(
|
||||
return cards.push({
|
||||
id: anno.ann_id,
|
||||
title: anno.title,
|
||||
subtitle: anno.subtitle,
|
||||
subtitle: anno.subtitle.replace(/<br \/>/g, " "),
|
||||
banner: anno.banner || defaultCover,
|
||||
typeLabel: anno.type === 2 ? "游戏公告" : "活动公告",
|
||||
tagIcon: anno.tag_icon,
|
||||
tagLabel: anno.tag_label,
|
||||
tagLabel: getAnnoTag(anno.tag_label),
|
||||
timeStr: time,
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user