mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-11 09:08:14 +08:00
@@ -66,7 +66,9 @@ function handleSelectW(val: SelectedWValue) {
|
||||
const reg = /\/icon\/weapon\/(.+?)\.webp/;
|
||||
const filterW = AppWeaponData.filter((item) => {
|
||||
if (!val.star.includes(item.star)) return false;
|
||||
return val.weapon.includes(item.weaponIcon.match(reg)![1]);
|
||||
const match = item.weaponIcon.match(reg);
|
||||
if (match === null) return false;
|
||||
return val.weapon.includes(match[1]);
|
||||
});
|
||||
if (filterW.length === 0) {
|
||||
showSnackbar({
|
||||
|
||||
@@ -61,13 +61,13 @@ import ToLoading from "../../components/overlay/to-loading.vue";
|
||||
import { useAppStore } from "../../store/modules/app";
|
||||
import TGLogger from "../../utils/TGLogger";
|
||||
import { createTGWindow } from "../../utils/TGWindow";
|
||||
import { SERVER } from "../../web/request/getAnno";
|
||||
import { AnnoLang, AnnoServer } from "../../web/request/getAnno";
|
||||
import TGRequest from "../../web/request/TGRequest";
|
||||
import TGUtils from "../../web/utils/TGUtils";
|
||||
|
||||
// 服务器名称-服务器对应
|
||||
type AnnoServerMap = {
|
||||
[key: string]: SERVER;
|
||||
[key: string]: AnnoServer;
|
||||
};
|
||||
|
||||
const annoServerList: string[] = [
|
||||
@@ -79,15 +79,15 @@ const annoServerList: string[] = [
|
||||
"国际服-港澳台服",
|
||||
];
|
||||
const langList: string[] = ["简体中文", "繁体中文", "English", "日本語"];
|
||||
export type AnnoLang = "zh-cn" | "zh-tw" | "en" | "ja";
|
||||
|
||||
// 服务器列表
|
||||
const annoServerMap: AnnoServerMap = {
|
||||
"国服-官方服": SERVER.CN_ISLAND,
|
||||
"国服-渠道服": SERVER.CN_TREE,
|
||||
"国际服-亚服": SERVER.OS_ASIA,
|
||||
"国际服-欧服": SERVER.OS_EURO,
|
||||
"国际服-美服": SERVER.OS_USA,
|
||||
"国际服-港澳台服": SERVER.OS_CHT,
|
||||
"国服-官方服": AnnoServer.CN_ISLAND,
|
||||
"国服-渠道服": AnnoServer.CN_TREE,
|
||||
"国际服-亚服": AnnoServer.OS_ASIA,
|
||||
"国际服-欧服": AnnoServer.OS_EURO,
|
||||
"国际服-美服": AnnoServer.OS_USA,
|
||||
"国际服-港澳台服": AnnoServer.OS_CHT,
|
||||
};
|
||||
const langMap: Record<string, AnnoLang> = {
|
||||
简体中文: "zh-cn",
|
||||
@@ -115,7 +115,7 @@ const appStore = useAppStore();
|
||||
|
||||
// 路由
|
||||
const router = useRouter();
|
||||
const curRegion = ref<SERVER>(appStore.server);
|
||||
const curRegion = ref<AnnoServer>(appStore.server);
|
||||
const curRegionName = ref<string>(annoServerList[0]);
|
||||
const curLang = ref<AnnoLang>(appStore.lang);
|
||||
const curLangName = ref<string>(langList[0]);
|
||||
@@ -127,11 +127,10 @@ const annoCards = ref<AnnoCard>({
|
||||
activity: [],
|
||||
game: [],
|
||||
});
|
||||
const annoData = ref<TGApp.BBS.Announcement.ListData>(<TGApp.BBS.Announcement.ListData>{});
|
||||
|
||||
watch(curRegionName, async (value) => {
|
||||
appStore.server = annoServerMap[value] || SERVER.CN_ISLAND;
|
||||
curRegion.value = annoServerMap[value] || SERVER.CN_ISLAND;
|
||||
appStore.server = annoServerMap[value] || AnnoServer.CN_ISLAND;
|
||||
curRegion.value = annoServerMap[value] || AnnoServer.CN_ISLAND;
|
||||
await TGLogger.Info(`[Announcements][watch][curRegionName] 切换服务器:${value}`);
|
||||
await loadData();
|
||||
});
|
||||
@@ -163,13 +162,14 @@ onMounted(async () => {
|
||||
async function loadData(): Promise<void> {
|
||||
loadingTitle.value = "正在获取公告数据";
|
||||
loading.value = true;
|
||||
annoData.value = await TGRequest.Anno.getList(curRegion.value, curLang.value);
|
||||
const listCards = TGUtils.Anno.getCard(annoData.value);
|
||||
const annoData = await TGRequest.Anno.getList(curRegion.value, curLang.value);
|
||||
const listCards = TGUtils.Anno.getCard(annoData);
|
||||
await Promise.all(
|
||||
listCards.map(async (item) => {
|
||||
// if (item.typeLabel === AnnoType.game) return;
|
||||
if (item.typeLabel === AnnoType.game) return;
|
||||
const detail = await TGRequest.Anno.getContent(item.id, curRegion.value, "zh-cn");
|
||||
item.timeStr = getAnnoTime(detail.content);
|
||||
const timeStr = getAnnoTime(detail.content);
|
||||
if (timeStr !== false) item.timeStr = timeStr;
|
||||
}),
|
||||
);
|
||||
annoCards.value = {
|
||||
@@ -182,42 +182,46 @@ async function loadData(): Promise<void> {
|
||||
});
|
||||
}
|
||||
|
||||
interface AnnoTimeRegex {
|
||||
actPermanent: RegExp;
|
||||
actPersistent: RegExp;
|
||||
actTransient: RegExp;
|
||||
verUpdateTime: RegExp;
|
||||
}
|
||||
|
||||
const regexMap: AnnoTimeRegex = {
|
||||
actPermanent: /(?:〓活动时间〓|〓任务开放时间〓).*?\d\.\d版本更新(?:完成|)后永久开放/,
|
||||
actPersistent: /〓活动时间〓.*?\d\.\d版本期间持续开放/,
|
||||
// (?:〓活动时间〓|祈愿时间|【上架时间】).*?(\d\.\d版本更新后).*?~.*?&lt;t class="t_(?:gl|lc)".*?&gt;(.*?)&lt;/t&gt;
|
||||
actTransient:
|
||||
/(?:〓活动时间〓|祈愿时间|【上架时间】).*?(\d\.\d版本更新后).*?~.*?<t class="t_(?:gl|lc)".*?>(.*?)<\/t>/,
|
||||
// 〓更新时间〓.+?&lt;t class=\"t_(?:gl|lc)\".*?&gt;(.*?)&lt;/t&gt;
|
||||
verUpdateTime: /〓更新时间〓.+?<t class="t_(?:gl|lc)".*?>(.*?)<\/t>gt;/,
|
||||
};
|
||||
|
||||
function getAnnoTime(content: string): string {
|
||||
if (content.match(regexMap.actPermanent)) {
|
||||
console.log("actPermanent");
|
||||
return "永久开放";
|
||||
function getAnnoTime(content: string): string | false {
|
||||
const regexes = [
|
||||
/〓活动时间〓.*?\d\.\d版本期间持续开放/,
|
||||
/(?:〓活动时间〓|〓任务开放时间〓).*?\d\.\d版本更新(?:完成|)后永久开放/,
|
||||
/(?:〓(?:活动|折扣)时间〓|祈愿时间|【上架时间】).*?(\d\.\d版本更新后).*?~.*?<t class="t_(?:gl|lc)".*?>(.*?)<\/t>/,
|
||||
/(?:〓(?:活动|折扣)时间〓|祈愿时间|【上架时间】).*?<t class="t_(?:gl|lc)".*?>(.*?)<\/t>.*?~.*?<t class="t_(?:gl|lc)".*?>(.*?)<\/t>/,
|
||||
/〓活动时间〓.*?(\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2}).*?(\d\.\d版本结束)/,
|
||||
/〓更新时间〓.+?<t class=\"t_(?:gl|lc)\".*?>(.*?)&;lt;\/t>/,
|
||||
];
|
||||
if (content.match(regexes[0])) {
|
||||
const res = content.match(regexes[0]);
|
||||
return res?.[0].replace(/.*?(\d\.\d版本期间持续开放)/, "$1") ?? false;
|
||||
}
|
||||
if (content.match(regexMap.actPersistent)) {
|
||||
const res = content.match(regexMap.actPersistent);
|
||||
console.log("actPersistent", res?.[0]);
|
||||
return res?.[0].replace(/.*?(\d\.\d版本期间持续开放)/, "$1") ?? "持续开放";
|
||||
if (content.match(regexes[1])) {
|
||||
console.log("actPermanently");
|
||||
// todo 待处理
|
||||
return false;
|
||||
}
|
||||
if (content.match(regexMap.actTransient)) {
|
||||
console.log("actTransient");
|
||||
return "临时开放";
|
||||
if (content.match(regexes[2])) {
|
||||
const res = content.match(regexes[2]);
|
||||
return `${res?.[1]} ~ ${res?.[2]}`;
|
||||
}
|
||||
if (content.match(regexMap.verUpdateTime)) {
|
||||
if (content.match(regexes[3])) {
|
||||
const res = content.match(regexes[3]);
|
||||
return `${res?.[1].split(" ")[0]} ~ ${res?.[2].split(" ")[0]}`;
|
||||
}
|
||||
if (content.match(regexes[4])) {
|
||||
const res = content.match(regexes[4]);
|
||||
if (res != null) {
|
||||
const cnt = res[0].match(/〓/g);
|
||||
if (cnt && cnt.length > 2) return false;
|
||||
}
|
||||
return `${res?.[1]} ~ ${res?.[2]}`;
|
||||
}
|
||||
if (content.match(regexes[5])) {
|
||||
console.log("verUpdateTime");
|
||||
return "版本更新";
|
||||
// todo 待处理
|
||||
return false;
|
||||
}
|
||||
return "未知时间";
|
||||
return false;
|
||||
}
|
||||
|
||||
function parseTitle(title: string): string {
|
||||
|
||||
@@ -8,9 +8,8 @@ import { path } from "@tauri-apps/api";
|
||||
import { defineStore } from "pinia";
|
||||
import { reactive, ref } from "vue";
|
||||
|
||||
import type { AnnoLang } from "../../pages/common/Announcements.vue";
|
||||
import { getInitDeviceInfo } from "../../utils/toolFunc";
|
||||
import { SERVER } from "../../web/request/getAnno";
|
||||
import { type AnnoLang, AnnoServer } from "../../web/request/getAnno";
|
||||
|
||||
// 用于存储用户数据的路径
|
||||
const userDataDir = `${await path.appLocalDataDir()}userData`;
|
||||
@@ -46,7 +45,7 @@ export const useAppStore = defineStore(
|
||||
// 设备信息
|
||||
const deviceInfo = ref<TGApp.App.Device.DeviceInfo>(getInitDeviceInfo());
|
||||
// 服务器
|
||||
const server = ref<SERVER>(SERVER.CN_ISLAND);
|
||||
const server = ref<AnnoServer>(AnnoServer.CN_ISLAND);
|
||||
// 语言
|
||||
const lang = ref<AnnoLang>("zh-cn");
|
||||
// 最近的咨讯类型
|
||||
@@ -59,7 +58,7 @@ export const useAppStore = defineStore(
|
||||
theme.value = "default";
|
||||
isLogin.value = false;
|
||||
sidebar.collapse = true;
|
||||
server.value = SERVER.CN_ISLAND;
|
||||
server.value = AnnoServer.CN_ISLAND;
|
||||
lang.value = "zh-cn";
|
||||
recentNewsType.value = "notice";
|
||||
initDevice();
|
||||
|
||||
@@ -16,8 +16,7 @@ import { useRoute } from "vue-router";
|
||||
|
||||
import TSwitchTheme from "../components/app/t-switchTheme.vue";
|
||||
import ToLoading from "../components/overlay/to-loading.vue";
|
||||
import { AnnoLang } from "../pages/common/Announcements.vue";
|
||||
import { SERVER } from "../web/request/getAnno";
|
||||
import { AnnoLang, AnnoServer } from "../web/request/getAnno";
|
||||
import TGRequest from "../web/request/TGRequest";
|
||||
|
||||
// loading
|
||||
@@ -28,7 +27,7 @@ const loadingEmpty = ref<boolean>(false);
|
||||
// 数据
|
||||
const route = useRoute();
|
||||
const annoId = Number(route.params.anno_id);
|
||||
const region = <SERVER>route.params.region;
|
||||
const region = <AnnoServer>route.params.region;
|
||||
const lang = <AnnoLang>route.params.lang;
|
||||
let jsonList = reactive({});
|
||||
let jsonContent = reactive({});
|
||||
|
||||
@@ -28,12 +28,11 @@ import { useRoute } from "vue-router";
|
||||
import TSwitchTheme from "../components/app/t-switchTheme.vue";
|
||||
import TShareBtn from "../components/main/t-shareBtn.vue";
|
||||
import ToLoading from "../components/overlay/to-loading.vue";
|
||||
import { AnnoLang } from "../pages/common/Announcements.vue";
|
||||
import { useAppStore } from "../store/modules/app";
|
||||
import TGLogger from "../utils/TGLogger";
|
||||
import { saveImgLocal } from "../utils/TGShare";
|
||||
import { createTGWindow } from "../utils/TGWindow";
|
||||
import { SERVER } from "../web/request/getAnno";
|
||||
import { AnnoLang, AnnoServer } from "../web/request/getAnno";
|
||||
import TGRequest from "../web/request/TGRequest";
|
||||
import TGUtils from "../web/utils/TGUtils";
|
||||
|
||||
@@ -51,7 +50,7 @@ const annoTitle = ref<string>("");
|
||||
// 数据
|
||||
const route = useRoute();
|
||||
const annoId = Number(route.params.anno_id);
|
||||
const region = <SERVER>route.params.region;
|
||||
const region = <AnnoServer>route.params.region;
|
||||
const lang = <AnnoLang>route.params.lang;
|
||||
const annoData = ref<TGApp.BBS.Announcement.ContentItem>(<TGApp.BBS.Announcement.ContentItem>{});
|
||||
const annoHtml = ref<string>();
|
||||
@@ -104,7 +103,7 @@ watch(loadShare, (value) => {
|
||||
}
|
||||
});
|
||||
|
||||
function createAnnoJson(annoId: number, region: SERVER, lang: AnnoLang) {
|
||||
function createAnnoJson(annoId: number, region: AnnoServer, lang: AnnoLang) {
|
||||
const jsonPath = `/anno_detail_json/${region}/${annoId}/${lang}`;
|
||||
const jsonTitle = `Anno_${region}_${annoId}_${lang}_JSON`;
|
||||
createTGWindow(jsonPath, "Dev_JSON", jsonTitle, 960, 720, false, false);
|
||||
|
||||
@@ -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