mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-13 09:28:14 +08:00
feat(calendar): 材料日历请求
This commit is contained in:
@@ -20,6 +20,9 @@ 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: {
|
||||
@@ -53,6 +56,10 @@ const MysOper = {
|
||||
reward: getLotteryRewardCard,
|
||||
},
|
||||
},
|
||||
Calendar: {
|
||||
get: getCalendarData,
|
||||
card: getCalendarCard,
|
||||
},
|
||||
};
|
||||
|
||||
export default MysOper;
|
||||
|
||||
105
src/plugins/Mys/interface/calendar.ts
Normal file
105
src/plugins/Mys/interface/calendar.ts
Normal file
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* @file plugins Mys interface calendar.ts
|
||||
* @description Mys 插件日历接口
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.1.1
|
||||
*/
|
||||
|
||||
import { MysResponse } from "./base";
|
||||
import { Map } from "../../../interface/Base";
|
||||
|
||||
/**
|
||||
* @description 日历返回数据
|
||||
* @since Alpha v0.1.1
|
||||
* @interface CalendarResponse
|
||||
* @extends {MysResponse}
|
||||
* @property {CalendarData[]} data.list 日历数据
|
||||
* @return {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<number, number>,前者为星期,后者为排序
|
||||
* @property {CalendarContent[]} contentSource 材料来源,kind 为 2 时不为空
|
||||
* @return {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 链接,一般为空
|
||||
* @return {CalendarContent}
|
||||
*/
|
||||
export interface CalendarContent {
|
||||
id: string;
|
||||
title: string;
|
||||
icon: string;
|
||||
bbs_url: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 渲染用的日历数据
|
||||
* @since Alpha v0.1.1
|
||||
* @interface CalendarCard
|
||||
* @property {number} id 角色/武器 ID
|
||||
* @property {string} title 角色/武器 名称
|
||||
* @property {string} cover 角色/武器 封面
|
||||
* @property {string} url 跳转链接
|
||||
* @property {string[]} drop_day 掉落日
|
||||
* @property {Map<number>} sort 排序
|
||||
* @property {CalendarContent[]} contentInfos 材料内容
|
||||
* @return {CalendarCard}
|
||||
*/
|
||||
export interface CalendarCard {
|
||||
id: number;
|
||||
title: string;
|
||||
cover: string;
|
||||
url: string;
|
||||
drop_day: string[];
|
||||
sort: Map<number>;
|
||||
}
|
||||
32
src/plugins/Mys/request/calendar.ts
Normal file
32
src/plugins/Mys/request/calendar.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @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 { CalendarResponse, 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");
|
||||
}
|
||||
29
src/plugins/Mys/utils/calendar.ts
Normal file
29
src/plugins/Mys/utils/calendar.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* @file plugins Mys utils calendar.ts
|
||||
* @description Mys 插件日历工具
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.1.1
|
||||
*/
|
||||
|
||||
import { CalendarData, CalendarCard } from "../interface/calendar";
|
||||
|
||||
/**
|
||||
* @description 将日历数据转换为卡片数据
|
||||
* @since Alpha v0.1.1
|
||||
* @param {CalendarData[]} calendarData 日历数据
|
||||
* @return {CalendarCard[]}
|
||||
*/
|
||||
export function getCalendarCard(calendarData: CalendarData[]): CalendarCard[] {
|
||||
const calendarCard: CalendarCard[] = [];
|
||||
calendarData.forEach((data: CalendarData) => {
|
||||
return calendarCard.push({
|
||||
id: Number(data.id),
|
||||
title: data.title,
|
||||
cover: data.img_url,
|
||||
url: data.jump_type === "1" ? data.jump_url : data.content_id,
|
||||
drop_day: data.drop_day,
|
||||
sort: JSON.parse(data.sort),
|
||||
});
|
||||
});
|
||||
return calendarCard;
|
||||
}
|
||||
Reference in New Issue
Block a user