feat(calendar): 材料日历请求

This commit is contained in:
BTMuli
2023-04-02 21:49:51 +08:00
parent ed5ddbb0b8
commit 3d3ac83d2a
4 changed files with 173 additions and 0 deletions

View File

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

View 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 日历跳转 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 时不为空
* @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>;
}

View 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");
}

View 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;
}