mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-13 09:28:14 +08:00
feat(position): 添加近期活动信息
This commit is contained in:
@@ -11,6 +11,9 @@ import { PostParser } from "./utils/parser";
|
||||
// Gacha
|
||||
import { getGachaData } from "./request/gacha";
|
||||
import { getGachaCard } from "./utils/gacha";
|
||||
// Position
|
||||
import { getPositionData } from "./request/position";
|
||||
import { getPositionCard } from "./utils/position";
|
||||
// News
|
||||
import { getNoticeList, getActivityList, getNewsList } from "./request/news";
|
||||
import { getNoticeCard, getActivityCard, getNewsCard } from "./utils/news";
|
||||
@@ -27,6 +30,10 @@ const MysOper = {
|
||||
get: getGachaData,
|
||||
card: getGachaCard,
|
||||
},
|
||||
Position: {
|
||||
get: getPositionData,
|
||||
card: getPositionCard,
|
||||
},
|
||||
News: {
|
||||
get: {
|
||||
notice: getNoticeList,
|
||||
|
||||
@@ -19,3 +19,40 @@ export interface MysResponse {
|
||||
message: string;
|
||||
data: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Mys obc 返回数据
|
||||
* @since Alpha v0.1.1
|
||||
* @interface MysObcResponse
|
||||
* @extends MysResponse
|
||||
* @property {MysObc[]} data.list obc 列表
|
||||
* @return {MysObcResponse}
|
||||
*/
|
||||
export interface MysObcResponse extends MysResponse {
|
||||
data: {
|
||||
list: MysObc[];
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Mys obc 层级结构
|
||||
* @since Alpha v0.1.1
|
||||
* @interface MysObc
|
||||
* @property {number} id ID
|
||||
* @property {string} name 名称
|
||||
* @property {number} parent_id 父ID
|
||||
* @property {number} depth 深度
|
||||
* @property {string} ch_ext 结构化扩展信息
|
||||
* @property {any[]} children 子节点
|
||||
* @property {unknown[]} list 列表
|
||||
* @return {MysObc}
|
||||
*/
|
||||
export interface MysObc {
|
||||
id: number;
|
||||
name: string;
|
||||
parent_id: number;
|
||||
depth: number;
|
||||
ch_ext: string;
|
||||
children: MysObc[];
|
||||
list: unknown[];
|
||||
}
|
||||
|
||||
90
src/plugins/Mys/interface/position.ts
Normal file
90
src/plugins/Mys/interface/position.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* @file plugins Mys interface position.ts
|
||||
* @description Mys 插件热点追踪接口
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.1.1
|
||||
*/
|
||||
|
||||
import { MysObcResponse, MysObc } from "./base";
|
||||
|
||||
/**
|
||||
* @description 获取热点追踪信息的返回类型
|
||||
* @since Alpha v0.1.1
|
||||
* @interface PositionResponse
|
||||
* @extends MysObcResponse
|
||||
* @property {PositionObc[]} data.list obc 列表
|
||||
* @return {PositionResponse}
|
||||
*/
|
||||
export interface PositionResponse extends MysObcResponse {
|
||||
data: {
|
||||
list: PositionObc[];
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 热点追踪层级结构
|
||||
* @since Alpha v0.1.1
|
||||
* @interface PositionObc
|
||||
* @extends MysObc
|
||||
* @property {PositionData[]} list 列表
|
||||
* @return {PositionObc}
|
||||
*/
|
||||
export interface PositionObc extends MysObc {
|
||||
list: PositionData[];
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 热点追踪信息
|
||||
* @since Alpha v0.1.1
|
||||
* @interface PositionData
|
||||
* @property {number} recommend_id 推荐ID
|
||||
* @property {number} content_id 内容ID
|
||||
* @property {string} title 标题
|
||||
* @property {string} ext 扩展信息
|
||||
* @property {number} type 类型
|
||||
* @property {string} url 链接
|
||||
* @property {string} icon 图标
|
||||
* @property {string} abstract 摘要
|
||||
* @property {string} article_user_name 作者
|
||||
* @property {string} avatar_url 头像
|
||||
* @property {string} article_time 时间
|
||||
* @property {string} create_time 创建时间 // 2023-03-31 11:16:57
|
||||
* @property {string} end_time 结束时间 // 1680465599000
|
||||
* @return {PositionData}
|
||||
*/
|
||||
export interface PositionData {
|
||||
recommend_id: number;
|
||||
content_id: number;
|
||||
title: string;
|
||||
ext: string;
|
||||
type: number;
|
||||
url: string;
|
||||
icon: string;
|
||||
abstract: string;
|
||||
article_user_name: string;
|
||||
avatar_url: string;
|
||||
article_time: string;
|
||||
create_time: string;
|
||||
end_time: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 渲染用的热点追踪信息
|
||||
* @since Alpha v0.1.1
|
||||
* @interface PositionCard
|
||||
* @property {string} title 标题
|
||||
* @property {string} url 链接
|
||||
* @property {string} icon 图标
|
||||
* @property {string} abstract 摘要
|
||||
* @property {string} create_time 创建时间
|
||||
* @property {string} end_time 结束时间
|
||||
* @return {PositionCard}
|
||||
*/
|
||||
export interface PositionCard {
|
||||
title: string;
|
||||
url: string;
|
||||
icon: string;
|
||||
abstract: string;
|
||||
create_time: string;
|
||||
end_time: string;
|
||||
}
|
||||
33
src/plugins/Mys/request/position.ts
Normal file
33
src/plugins/Mys/request/position.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* @file plugins Mys request position.ts
|
||||
* @description Mys 插件热点追踪请求
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.1.1
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
import { PositionResponse, PositionData, PositionObc } from "../interface/position";
|
||||
import { dfs } from "../utils/position";
|
||||
|
||||
// 热点追踪 API
|
||||
const POSITION_API =
|
||||
"https://api-static.mihoyo.com/common/blackboard/ys_obc/v1/home/position?app_sn=ys_obc";
|
||||
|
||||
/**
|
||||
* @description 获取热点追踪信息
|
||||
* @since Alpha v0.1.1
|
||||
* @return {Promise<PositionData[]>}
|
||||
*/
|
||||
export async function getPositionData(): Promise<PositionData[]> {
|
||||
const res = await http
|
||||
.fetch<PositionResponse>(POSITION_API, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
})
|
||||
.then(res => {
|
||||
return res.data.data.list;
|
||||
});
|
||||
return dfs(res as PositionObc[]);
|
||||
}
|
||||
48
src/plugins/Mys/utils/position.ts
Normal file
48
src/plugins/Mys/utils/position.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @file plugins Mys utils position.ts
|
||||
* @description Mys 插件热点追踪工具
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.1.1
|
||||
*/
|
||||
|
||||
import { PositionObc, PositionData, PositionCard } from "../interface/position";
|
||||
|
||||
/**
|
||||
* @description 深度优先遍历
|
||||
* @since Alpha v0.1.1
|
||||
* @param {PositionObc[]} list 列表
|
||||
* @return {PositionData[]} 返回列表
|
||||
*/
|
||||
export function dfs(list: PositionObc[]): PositionData[] {
|
||||
const res: PositionData[] = [];
|
||||
for (const item of list) {
|
||||
if (item.name === "近期活动") {
|
||||
res.push(...item.list);
|
||||
}
|
||||
if (item.children) {
|
||||
res.push(...dfs(item.children as PositionObc[]));
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 根据热点追踪信息转为渲染用的数据
|
||||
* @since Alpha v0.1.1
|
||||
* @param {PositionData[]} positionData 列表
|
||||
* @return {PositionCard[]} 返回列表
|
||||
*/
|
||||
export function getPositionCard(positionData: PositionData[]): PositionCard[] {
|
||||
const res: PositionCard[] = [];
|
||||
positionData.map(position => {
|
||||
res.push({
|
||||
title: position.title,
|
||||
url: position.url,
|
||||
icon: position.icon,
|
||||
abstract: position.abstract,
|
||||
create_time: position.create_time,
|
||||
end_time: position.end_time,
|
||||
});
|
||||
});
|
||||
return res;
|
||||
}
|
||||
Reference in New Issue
Block a user