From d56a438662361273cb4a1c0cf3e0c208840f8b38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9B=AE=E6=A3=83?= Date: Sun, 25 Feb 2024 15:40:10 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E5=AE=8C=E6=88=90=E6=B4=BB?= =?UTF-8?q?=E5=8A=A8=E6=97=B6=E9=97=B4=E6=AD=A3=E5=88=99=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close #94 --- src/pages/WIKI/Weapon.vue | 4 +- src/pages/common/Announcements.vue | 100 +++++++++++++++-------------- src/store/modules/app.ts | 7 +- src/views/t-anno-json.vue | 5 +- src/views/t-anno.vue | 7 +- src/web/request/getAnno.ts | 25 ++++---- src/web/utils/getAnnoCard.ts | 28 +++++++- 7 files changed, 102 insertions(+), 74 deletions(-) diff --git a/src/pages/WIKI/Weapon.vue b/src/pages/WIKI/Weapon.vue index 631f345b..344c06a5 100644 --- a/src/pages/WIKI/Weapon.vue +++ b/src/pages/WIKI/Weapon.vue @@ -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({ diff --git a/src/pages/common/Announcements.vue b/src/pages/common/Announcements.vue index 318eb656..43a80af3 100644 --- a/src/pages/common/Announcements.vue +++ b/src/pages/common/Announcements.vue @@ -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 = { 简体中文: "zh-cn", @@ -115,7 +115,7 @@ const appStore = useAppStore(); // 路由 const router = useRouter(); -const curRegion = ref(appStore.server); +const curRegion = ref(appStore.server); const curRegionName = ref(annoServerList[0]); const curLang = ref(appStore.lang); const curLangName = ref(langList[0]); @@ -127,11 +127,10 @@ const annoCards = ref({ activity: [], game: [], }); -const annoData = ref({}); 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 { 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 { }); } -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>/, - // 〓更新时间〓.+?&lt;t class=\"t_(?:gl|lc)\".*?&gt;(.*?)&lt;/t&gt; - verUpdateTime: /〓更新时间〓.+?(.*?)<\/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 { diff --git a/src/store/modules/app.ts b/src/store/modules/app.ts index d0e2c4d2..53554e75 100644 --- a/src/store/modules/app.ts +++ b/src/store/modules/app.ts @@ -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(getInitDeviceInfo()); // 服务器 - const server = ref(SERVER.CN_ISLAND); + const server = ref(AnnoServer.CN_ISLAND); // 语言 const lang = ref("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(); diff --git a/src/views/t-anno-json.vue b/src/views/t-anno-json.vue index 93df6b22..214a4496 100644 --- a/src/views/t-anno-json.vue +++ b/src/views/t-anno-json.vue @@ -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(false); // 数据 const route = useRoute(); const annoId = Number(route.params.anno_id); -const region = route.params.region; +const region = route.params.region; const lang = route.params.lang; let jsonList = reactive({}); let jsonContent = reactive({}); diff --git a/src/views/t-anno.vue b/src/views/t-anno.vue index 768294bf..9fb11ba9 100644 --- a/src/views/t-anno.vue +++ b/src/views/t-anno.vue @@ -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(""); // 数据 const route = useRoute(); const annoId = Number(route.params.anno_id); -const region = route.params.region; +const region = route.params.region; const lang = route.params.lang; const annoData = ref({}); const annoHtml = ref(); @@ -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); diff --git a/src/web/request/getAnno.ts b/src/web/request/getAnno.ts index c8c5d25e..04953fae 100644 --- a/src/web/request/getAnno.ts +++ b/src/web/request/getAnno.ts @@ -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} */ export async function getAnnoList( - region: SERVER = SERVER.CN_ISLAND, + region: AnnoServer = AnnoServer.CN_ISLAND, lang: AnnoLang = "zh-cn", ): Promise { 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} */ export async function getAnnoContent( annId: number, - region: SERVER, + region: AnnoServer = AnnoServer.CN_ISLAND, lang: AnnoLang = "zh-cn", ): Promise { 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 diff --git a/src/web/utils/getAnnoCard.ts b/src/web/utils/getAnnoCard.ts index c9f5ab3f..4d0a39ef 100644 --- a/src/web/utils/getAnnoCard.ts +++ b/src/web/utils/getAnnoCard.ts @@ -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(/
/g, " "), banner: anno.banner || defaultCover, typeLabel: anno.type === 2 ? "游戏公告" : "活动公告", tagIcon: anno.tag_icon, - tagLabel: anno.tag_label, + tagLabel: getAnnoTag(anno.tag_label), timeStr: time, }); });