From a238dc5eed7dbb6dcb6a5b427cacbf29a1f140de Mon Sep 17 00:00:00 2001 From: BTMuli Date: Sun, 9 Apr 2023 23:09:13 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20fix(types):=20=E7=B2=BE?= =?UTF-8?q?=E7=AE=80=20types=EF=BC=8C=E6=B8=85=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/t-calendar.vue | 12 +-- src/core/types/TGCalendar.d.ts | 56 ++++++++++++++ src/core/types/TGTypes.d.ts | 10 ++- src/data/app/index.ts | 5 +- src/interface/Base.ts | 25 ------ src/interface/Calendar.ts | 53 ------------- src/plugins/Mys/index.ts | 9 +-- src/plugins/Mys/interface/calendar.ts | 107 -------------------------- src/plugins/Mys/request/calendar.ts | 31 -------- src/plugins/Mys/utils/calendar.ts | 31 -------- 10 files changed, 72 insertions(+), 267 deletions(-) create mode 100644 src/core/types/TGCalendar.d.ts delete mode 100644 src/interface/Base.ts delete mode 100644 src/interface/Calendar.ts delete mode 100644 src/plugins/Mys/interface/calendar.ts delete mode 100644 src/plugins/Mys/request/calendar.ts delete mode 100644 src/plugins/Mys/utils/calendar.ts diff --git a/src/components/t-calendar.vue b/src/components/t-calendar.vue index 26c295c9..3a9c8264 100644 --- a/src/components/t-calendar.vue +++ b/src/components/t-calendar.vue @@ -102,7 +102,7 @@ import { ref, onMounted } from "vue"; // data import { TGAppData } from "../data/index"; // interface -import { CalendarData, CalendarItem, MiniMaterial } from "../interface/Calendar"; +import type TGTypes from "../core/types/TGTypes"; import { OBC_CONTENT_API } from "../plugins/Mys/interface/utils"; import { createTGWindow } from "../utils/TGWindow"; @@ -110,13 +110,13 @@ import { createTGWindow } from "../utils/TGWindow"; const loading = ref(true as boolean); // data -const calendarData = ref(TGAppData.calendar as Record); +const calendarData = ref(TGAppData.calendar as Record); const weekNow = ref(0 as number); const btnNow = ref(0 as number); const dateNow = ref(new Date().toLocaleDateString()); -const calendarNow = ref({} as CalendarData); -const characterCards = ref({} as Record); -const weaponCards = ref({} as Record); +const calendarNow = ref({} as TGTypes.CalendarData); +const characterCards = ref({} as Record); +const weaponCards = ref({} as Record); const btnText = [ { @@ -172,7 +172,7 @@ function getCalendar (day: number) { return calendarData.value[week]; } -function showContent (material: MiniMaterial) { +function showContent (material: TGTypes.CalendarMaterial) { const url = OBC_CONTENT_API.replace("{content_id}", material.content_id.toString()); createTGWindow(url, "素材详情", material.name, 1200, 800, true); } diff --git a/src/core/types/TGCalendar.d.ts b/src/core/types/TGCalendar.d.ts new file mode 100644 index 00000000..59ec7fef --- /dev/null +++ b/src/core/types/TGCalendar.d.ts @@ -0,0 +1,56 @@ +/** + * @file core types TGCalendar.d.ts + * @description 本应用的素材日历类型定义 + * @author BTMuli + * @since Alpha v0.1.2 + */ + +namespace TGCalendar { + /** + * @description 素材日历接口 + * @interface CalendarData + * @since Alpha v0.1.2 + * @property {Record} characters - 该天的角色相关数据 + * @property {Record} weapons - 该天的武器相关数据 + * @returns {CalendarData} + */ + export interface CalendarData { + characters: Record + weapons: Record + } + + /** + * @description 单日单秘境的素材日历接口 + * @interface CalendarItem + * @since Alpha v0.1.2 + * @property {string} title - 地区 秘境名称 + * @property {CalendarMaterial[]} materials - 素材 url + * @property {CalendarMaterial[]} contents - 角色/武器 url + * @returns {CalendarItem} + */ + export interface CalendarItem { + title: string + materials: CalendarMaterial[] + contents: CalendarMaterial[] + } + + /** + * @description 材料类型 + * @interface MiniMaterial + * @since Alpha v0.1.2 + * @property {number} id - 角色/武器的 id + * @property {number} star - 角色/武器的星级 + * @property {number} content_id - 观测枢的 content_id + * @property {string} name - 名称 + * @property {string} icon - 图标 url + */ + export interface CalendarMaterial { + id?: number + star: number + content_id: number + name: string + icon: string + } +} + +export default TGCalendar; diff --git a/src/core/types/TGTypes.d.ts b/src/core/types/TGTypes.d.ts index 5a8523ce..ae17b0fb 100644 --- a/src/core/types/TGTypes.d.ts +++ b/src/core/types/TGTypes.d.ts @@ -5,15 +5,19 @@ * @since Alpha v0.1.2 */ -import type TGBase from "./TGBase"; import type TGAchievement from "./TGAchievement"; +import type TGBase from "./TGBase"; +import type TGCalendar from "./TGCalendar"; import type TGNameCard from "./TGNameCard"; namespace TGTypes { - export type DBConfig = TGBase.DBConfig; - export type NameCard = TGNameCard.NameCard; export type Achievement = TGAchievement.Achievement; export type AchievementSeries = TGAchievement.AchievementSeries; + export type CalendarData = TGCalendar.CalendarData; + export type CalendarItem = TGCalendar.CalendarItem; + export type CalendarMaterial = TGCalendar.CalendarMaterial; + export type DBConfig = TGBase.DBConfig; + export type NameCard = TGNameCard.NameCard; } export default TGTypes; diff --git a/src/data/app/index.ts b/src/data/app/index.ts index 2b13fa68..61efb09b 100644 --- a/src/data/app/index.ts +++ b/src/data/app/index.ts @@ -14,7 +14,6 @@ import calendar from "./calendar.json"; // Interface import type TGAppTypes from "../../core/types/TGTypes"; import { type BaseCard } from "../../interface/GCG"; -import { type CalendarData } from "../../interface/Calendar"; export const AppDataList = [ { @@ -35,7 +34,7 @@ export const AppDataList = [ }, { name: "calendar.json", - data: calendar as Record, + data: calendar as Record, }, ]; @@ -44,5 +43,5 @@ export const AppData = { achievementSeries: achievementSeries as Record, GCG: GCG as BaseCard[], nameCards: nameCards as Record, - calendar: calendar as Record, + calendar: calendar as Record, }; diff --git a/src/interface/Base.ts b/src/interface/Base.ts deleted file mode 100644 index b9009eaf..00000000 --- a/src/interface/Base.ts +++ /dev/null @@ -1,25 +0,0 @@ -/** - * @file interface Base - * @description interface Base - * @author BTMuli - * @since Alpha v0.1.2 - */ - -/** - * @description 地区的枚举 - * @enum GameCountry - * @since Alpha v0.1.2 - * @property {string} Mondstadt - 蒙德 - * @property {string} Liyue - 璃月 - * @property {string} Inazuma - 稻妻 - * @property {string} Sumaru - 须弥 - * @property {string} Unknown - 未知 - * @returns {GameCountry} - */ -export enum GameCountry { - Mondstadt = "Mondstadt", - Liyue = "Liyue", - Inazuma = "Inazuma", - Sumaru = "Sumaru", - Unknown = "Unknown", -} diff --git a/src/interface/Calendar.ts b/src/interface/Calendar.ts deleted file mode 100644 index bd810f93..00000000 --- a/src/interface/Calendar.ts +++ /dev/null @@ -1,53 +0,0 @@ -/** - * @file interface Calendar.ts - * @description 素材日历接口 - * @author BTMuli - * @since Alpha v0.1.2 - */ - -/** - * @description 素材日历接口 - * @interface CalendarData - * @since Alpha v0.1.2 - * @example Map - * @property {Map} characters - 该天的角色相关数据 - * @property {Map} weapons - 该天的武器相关数据 - * @returns {CalendarData} - */ -export interface CalendarData { - characters: Record - weapons: Record -} - -/** - * @description 单日单秘境的素材日历接口 - * @interface CalendarItem - * @since Alpha v0.1.2 - * @property {string} title - 地区 秘境名称 - * @property {MiniMaterial[]} materials - 素材 url - * @property {MiniMaterial[]} contents - 角色/武器 url - * @returns {CalendarItem} - */ -export interface CalendarItem { - title: string - materials: MiniMaterial[] - contents: MiniMaterial[] -} - -/** - * @description 材料类型 - * @interface MiniMaterial - * @since Alpha v0.1.2 - * @property {number} id - 角色/武器的 id - * @property {number} star - 角色/武器的星级 - * @property {number} content_id - 观测枢的 content_id - * @property {string} name - 名称 - * @property {string} icon - 图标 url - */ -export interface MiniMaterial { - id?: number - star: number - content_id: number - name: string - icon: string -} diff --git a/src/plugins/Mys/index.ts b/src/plugins/Mys/index.ts index 6fbc4f39..9cdcf1d9 100644 --- a/src/plugins/Mys/index.ts +++ b/src/plugins/Mys/index.ts @@ -2,7 +2,7 @@ * @file plugins Mys index.ts * @description Mys plugin index * @author BTMuli - * @since Alpha v0.1.1 + * @since Alpha v0.1.2 */ // Post @@ -20,9 +20,6 @@ import { getNoticeCard, getActivityCard, getNewsCard } from "./utils/news"; // Lottery import { getLotteryData } from "./request/lottery"; import { getLotteryCard, getLotteryRewardCard } from "./utils/lottery"; -// Calendar -import { getCalendarData } from "./request/calendar"; -import { getCalendarCard } from "./utils/calendar"; const MysOper = { Post: { @@ -56,10 +53,6 @@ const MysOper = { reward: getLotteryRewardCard, }, }, - Calendar: { - get: getCalendarData, - card: getCalendarCard, - }, }; export default MysOper; diff --git a/src/plugins/Mys/interface/calendar.ts b/src/plugins/Mys/interface/calendar.ts deleted file mode 100644 index a8056b9f..00000000 --- a/src/plugins/Mys/interface/calendar.ts +++ /dev/null @@ -1,107 +0,0 @@ -/** - * @file plugins Mys interface calendar.ts - * @description Mys 插件日历接口 - * @author BTMuli - * @since Alpha v0.1.2 - */ - -import { type MysResponse } from "./base"; - -/** - * @description 日历返回数据 - * @since Alpha v0.1.1 - * @interface CalendarResponse - * @extends {MysResponse} - * @property {CalendarData[]} data.list 日历数据 - * @returns {CalendarResponse} - */ -export interface CalendarResponse extends MysResponse { - data: { - list: CalendarData[] - } -} - -/** - * @description 日历数据 - * @since Alpha v0.1.1 - * @interface CalendarData - * @property {string} id 日历 ID - * @property {string} title 日历标题 - * @property {string} kind 日历数据类型,1 为活动,2 为角色/武器,4 为角色生日 - * @property {string} img_url 日历图片 URL - * @property {string} jump_type 日历跳转类型,1 为帖子链接,2 为观测枢链接 - * @property {string} jump_url 日历跳转 URL,jump_type 为 1 时不为空 - * @property {string} content_id 日历内容 ID,jump_type 为 2 时不为空 - * @property {string} style 日历样式,// TODO: 未知 - * @property {string} start_time 开始时间,kind 为 2 时为 0 - * @property {string} end_time 结束时间,kind 为 2 时为 0 - * @property {string} font_color 日历字体颜色,kind 为 2 时为空 - * @property {string} padding_color 日历背景颜色,kind 为 2 时为空 - * @property {string[]} drop_day 掉落日,kind 为 2 时不为空 - * @property {string} break_type 日历分割类型,0 为活动/生日,1 为武器, 2 为角色 - * @property {CalendarContent[]} contentInfos 材料内容,kind 为 2 时不为空 - * @property {string} sort 排序,kind 为 2 时不为空,反序列化后为 Map,前者为星期,后者为排序 - * @property {CalendarContent[]} contentSource 材料来源,kind 为 2 时不为空 - * @returns {CalendarData} - */ -export interface CalendarData { - id: string - title: string - kind: string - img_url: string - jump_type: string - jump_url: string - content_id: string - style: string - start_time: string - end_time: string - font_color: string - padding_color: string - drop_day: string[] - break_type: string - contentInfos: CalendarContent[] - sort: string - contentSource: CalendarContent[] -} - -/** - * @description 日历内容 - * @since Alpha v0.1.1 - * @interface CalendarContent - * @property {string} id 内容 ID,对应的是观测枢的 content_id - * @property {string} title 材料/秘境 名称 - * @property {string} icon 材料/秘境 图片 URL - * @property {string} bbs_url 链接,一般为空 - * @returns {CalendarContent} - */ -export interface CalendarContent { - id: string - title: string - icon: string - bbs_url: string -} - -/** - * @description 渲染用的日历数据 - * @since Alpha v0.1.2 - * @interface CalendarCard - * @property {number} id 角色/武器 ID - * @property {number} type 角色/武器,角色为 2,武器为 1 - * @property {string} title 角色/武器 名称 - * @property {string} cover 角色/武器 封面 - * @property {string} url 跳转链接,一般为 content_id - * @property {string[]} drop_day 掉落日 - * @property {Record} sort_day 排序 - * @property {CalendarContent[]} contentInfos 材料内容 - * @returns {CalendarCard} - */ -export interface CalendarCard { - id: number - type: number - title: string - cover: string - url: string - drop_day: string[] - sort_day: Record - contentInfos: CalendarContent[] -} diff --git a/src/plugins/Mys/request/calendar.ts b/src/plugins/Mys/request/calendar.ts deleted file mode 100644 index 1c5c40cc..00000000 --- a/src/plugins/Mys/request/calendar.ts +++ /dev/null @@ -1,31 +0,0 @@ -/** - * @file plugins Mys request calendar.ts - * @description Mys 插件日历请求 - * @author BTMuli - * @since Alpha v0.1.1 - */ - -import { http } from "@tauri-apps/api"; -import { type CalendarResponse, type CalendarData } from "../interface/calendar"; - -// 日历 API -const CALENDAR_API = "https://api-static.mihoyo.com/common/blackboard/ys_obc/v1/get_activity_calendar?app_sn=ys_obc"; - -/** - * @description 日历请求 - * @since Alpha v0.1.1 - * @return {Promise} - */ -export async function getCalendarData (): Promise { - const res = await http - .fetch(CALENDAR_API, { - method: "GET", - headers: { - "Content-Type": "application/json", - }, - }) - .then((res) => { - return res.data.data.list; - }); - return res.filter((item) => item.kind === "2"); -} diff --git a/src/plugins/Mys/utils/calendar.ts b/src/plugins/Mys/utils/calendar.ts deleted file mode 100644 index 9087f65b..00000000 --- a/src/plugins/Mys/utils/calendar.ts +++ /dev/null @@ -1,31 +0,0 @@ -/** - * @file plugins Mys utils calendar.ts - * @description Mys 插件日历工具 - * @author BTMuli - * @since Alpha v0.1.1 - */ - -import { type CalendarData, type CalendarCard } from "../interface/calendar"; - -/** - * @description 将日历数据转换为卡片数据 - * @since Alpha v0.1.1 - * @param {CalendarData[]} calendarData 日历数据 - * @returns {CalendarCard[]} - */ -export function getCalendarCard (calendarData: CalendarData[]): CalendarCard[] { - const calendarCard: CalendarCard[] = []; - calendarData.forEach((data: CalendarData) => { - return calendarCard.push({ - id: Number(data.id), - type: Number(data.break_type), - title: data.title, - cover: data.img_url, - url: data.jump_type === "1" ? data.jump_url : data.content_id, - drop_day: data.drop_day, - sort_day: JSON.parse(data.sort), - contentInfos: data.contentInfos, - }); - }); - return calendarCard; -}