🏷️ fix(types): 精简 types,清除无用文件

This commit is contained in:
BTMuli
2023-04-09 23:09:13 +08:00
parent 20f3c8d00f
commit a238dc5eed
10 changed files with 72 additions and 267 deletions

View File

@@ -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<number, CalendarData>);
const calendarData = ref(TGAppData.calendar as Record<number, TGTypes.CalendarData>);
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<number, CalendarItem>);
const weaponCards = ref({} as Record<number, CalendarItem>);
const calendarNow = ref({} as TGTypes.CalendarData);
const characterCards = ref({} as Record<number, TGTypes.CalendarItem>);
const weaponCards = ref({} as Record<number, TGTypes.CalendarItem>);
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);
}

56
src/core/types/TGCalendar.d.ts vendored Normal file
View File

@@ -0,0 +1,56 @@
/**
* @file core types TGCalendar.d.ts
* @description 本应用的素材日历类型定义
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.1.2
*/
namespace TGCalendar {
/**
* @description 素材日历接口
* @interface CalendarData
* @since Alpha v0.1.2
* @property {Record<number, CalendarItem>} characters - 该天的角色相关数据
* @property {Record<number, CalendarItem>} weapons - 该天的武器相关数据
* @returns {CalendarData}
*/
export interface CalendarData {
characters: Record<number, CalendarItem>
weapons: Record<number, CalendarItem>
}
/**
* @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;

View File

@@ -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;

View File

@@ -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<number, CalendarData>,
data: calendar as Record<number, TGAppTypes.CalendarData>,
},
];
@@ -44,5 +43,5 @@ export const AppData = {
achievementSeries: achievementSeries as Record<number, TGAppTypes.AchievementSeries>,
GCG: GCG as BaseCard[],
nameCards: nameCards as Record<number, TGAppTypes.NameCard[]>,
calendar: calendar as Record<number, CalendarData>,
calendar: calendar as Record<number, TGAppTypes.CalendarData>,
};

View File

@@ -1,25 +0,0 @@
/**
* @file interface Base
* @description interface Base
* @author BTMuli<bt-muli@outlook.com>
* @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",
}

View File

@@ -1,53 +0,0 @@
/**
* @file interface Calendar.ts
* @description 素材日历接口
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.1.2
*/
/**
* @description 素材日历接口
* @interface CalendarData
* @since Alpha v0.1.2
* @example Map<Calendar>
* @property {Map<CalendarItem>} characters - 该天的角色相关数据
* @property {Map<CalendarItem>} weapons - 该天的武器相关数据
* @returns {CalendarData}
*/
export interface CalendarData {
characters: Record<number, CalendarItem>
weapons: Record<number, CalendarItem>
}
/**
* @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
}

View File

@@ -2,7 +2,7 @@
* @file plugins Mys index.ts
* @description Mys plugin index
* @author BTMuli<bt-muli@outlook.com>
* @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;

View File

@@ -1,107 +0,0 @@
/**
* @file plugins Mys interface calendar.ts
* @description Mys 插件日历接口
* @author BTMuli<bt-muli@outlook.com>
* @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 日历跳转 URLjump_type 为 1 时不为空
* @property {string} content_id 日历内容 IDjump_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<number, number>,前者为星期,后者为排序
* @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<number, number>} 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<number, number>
contentInfos: CalendarContent[]
}

View File

@@ -1,31 +0,0 @@
/**
* @file plugins Mys request calendar.ts
* @description Mys 插件日历请求
* @author BTMuli<bt-muli@outlook.com>
* @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<CalendarData[]>}
*/
export async function getCalendarData (): Promise<CalendarData[]> {
const res = await http
.fetch<CalendarResponse>(CALENDAR_API, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
})
.then((res) => {
return res.data.data.list;
});
return res.filter((item) => item.kind === "2");
}

View File

@@ -1,31 +0,0 @@
/**
* @file plugins Mys utils calendar.ts
* @description Mys 插件日历工具
* @author BTMuli<bt-muli@outlook.com>
* @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;
}