🌈 style(eslint): 第一次过 eslint

姑且先把能过的 ts 文件给过了,明天再过其余的 ts 文件跟 vue

Signed-off-by: BTMuli <BT-Muli@outlook.com>
(cherry picked from commit b7392bddea895b8b8cc1cad5ba0403d2dc738643)
This commit is contained in:
BTMuli
2023-04-06 02:23:02 +08:00
parent 3b28f57278
commit 6ec12bf664
52 changed files with 2103 additions and 2100 deletions

View File

@@ -11,33 +11,33 @@ import achievementSeries from "./achievementSeries.json";
import GCG from "./GCG.json";
import nameCards from "./nameCards.json";
// Interface
import { Achievement, AchievementSeries } from "../../interface/Achievements";
import { Map } from "../../interface/Base";
import { BaseCard } from "../../interface/GCG";
import { NameCard } from "../../interface/NameCard";
import { type Achievement, type AchievementSeries } from "../../interface/Achievements";
import { type Map } from "../../interface/Base";
import { type BaseCard } from "../../interface/GCG";
import { type NameCard } from "../../interface/NameCard";
export const AppDataList = [
{
name: "achievements.json",
data: achievements as Map<Achievement>,
},
{
name: "achievementSeries.json",
data: achievementSeries as Map<AchievementSeries>,
},
{
name: "GCG.json",
data: GCG as BaseCard[],
},
{
name: "nameCards.json",
data: nameCards as unknown as Map<NameCard[]>,
},
{
name: "achievements.json",
data: achievements as Map<Achievement>,
},
{
name: "achievementSeries.json",
data: achievementSeries as Map<AchievementSeries>,
},
{
name: "GCG.json",
data: GCG as BaseCard[],
},
{
name: "nameCards.json",
data: nameCards as unknown as Map<NameCard[]>,
},
];
export const AppData = {
achievements: achievements as Map<Achievement>,
achievementSeries: achievementSeries as Map<AchievementSeries>,
GCG: GCG as BaseCard[],
nameCards: nameCards as unknown as Map<NameCard[]>,
achievements: achievements as Map<Achievement>,
achievementSeries: achievementSeries as Map<AchievementSeries>,
GCG: GCG as BaseCard[],
nameCards: nameCards as unknown as Map<NameCard[]>,
};

View File

@@ -3,35 +3,29 @@
* @description data init GCG
* @description 分类参考:米游社卡牌图鉴
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha
* @since Alpha v0.1.2
*/
import { AppData } from "../app";
import { BaseCard } from "../../interface/GCG";
import { type BaseCard } from "../../interface/GCG";
import { type DBConfig } from "../../interface/Base";
/**
* @description 卡牌表参数
* @since Alpha
* @since Alpha v0.1.2
* @returns {DBConfig}
*/
export const Config = {
storeName: "GCG",
keyPath: "id",
// 根据 type 分类
indexes: [
"type",
"info.element",
"info.weapon",
"info.camp",
"info.actionType",
"info.actionTag",
"info.actionCost",
],
export const Config: DBConfig = {
storeName: "GCG",
keyPath: "id",
// 根据 type 分类
indexes: ["type", "info.element", "info.weapon", "info.camp", "info.actionType", "info.actionTag", "info.actionCost"],
};
/**
* @description 卡牌数据
* @since Alpha
* @since Alpha v0.1.2
* @return {BaseCard[]}
*/
export function getData() {
return AppData.GCG;
export function getData (): BaseCard[] {
return AppData.GCG;
}

View File

@@ -2,30 +2,31 @@
* @file data init achievementSeries
* @description data init achievementSeries
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha
* @since Alpha v0.1.2
*/
import { AchievementSeries } from "../../interface/Achievements";
import { Map } from "../../interface/Base";
import { type AchievementSeries } from "../../interface/Achievements";
import { type Map, type DBConfig } from "../../interface/Base";
import { AppData } from "../app";
/**
* @description 成就系列表参数
* @since Alpha
* @since Alpha v0.1.2
* @returns {DBConfig}
*/
export const Config = {
storeName: "AchievementSeries",
keyPath: "id",
indexes: ["order", "name", "card"],
export const Config: DBConfig = {
storeName: "AchievementSeries",
keyPath: "id",
indexes: ["order", "name", "card"],
};
/**
* @description 成就系列数据
* @since Alpha
* @since Alpha v0.1.2
* @return {AchievementSeries[]}
*/
export function getData() {
const data: Map<AchievementSeries> = AppData.achievementSeries;
return Object.keys(data).map(key => {
return data[Number(key)];
});
export function getData (): AchievementSeries[] {
const data: Map<AchievementSeries> = AppData.achievementSeries;
return Object.keys(data).map((key) => {
return data[Number(key)];
});
}

View File

@@ -2,30 +2,31 @@
* @file data init achievement
* @description data init achievement
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha
* @since Alpha v0.1.2
*/
import { AppData } from "../app";
import { Achievement } from "../../interface/Achievements";
import { Map } from "../../interface/Base";
import { type Achievement } from "../../interface/Achievements";
import { type Map, type DBConfig } from "../../interface/Base";
/**
* @description 成就表参数
* @since Alpha
* @since Alpha v0.1.2
* @returns {DBConfig}
*/
export const Config = {
storeName: "Achievements",
keyPath: "id",
indexes: ["name", "description", "series", "order", "reward", "version"],
export const Config: DBConfig = {
storeName: "Achievements",
keyPath: "id",
indexes: ["name", "description", "series", "order", "reward", "version"],
};
/**
* @description 成就数据
* @since Alpha
* @since Alpha v0.1.2
* @return {Achievement[]}
*/
export function getData() {
const data: Map<Achievement> = AppData.achievements;
return Object.keys(data).map(key => {
return data[Number(key)];
});
export function getData (): Achievement[] {
const data: Map<Achievement> = AppData.achievements;
return Object.keys(data).map((key) => {
return data[Number(key)];
});
}

View File

@@ -12,20 +12,20 @@ import { Config as SeriesConfig, getData as getSeriesData } from "./achievementS
export const ConfigList = [AchievementsConfig, GCGConfig, NameCardConfig, SeriesConfig];
export const getDataList = [
{
name: "Achievements",
data: getAchievementsData(),
},
{
name: "AchievementSeries",
data: getSeriesData(),
},
{
name: "GCG",
data: getGCGData(),
},
{
name: "NameCard",
data: getNameCardData(),
},
{
name: "Achievements",
data: getAchievementsData(),
},
{
name: "AchievementSeries",
data: getSeriesData(),
},
{
name: "GCG",
data: getGCGData(),
},
{
name: "NameCard",
data: getNameCardData(),
},
];

View File

@@ -2,36 +2,35 @@
* @file data init nameCard
* @description data init nameCard
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha
* @since Alpha v0.1.2
*/
import { AppData } from "../app";
import { NameCard } from "../../interface/NameCard";
import { Map } from "../../interface/Base";
import { type NameCard } from "../../interface/NameCard";
import { type Map, type DBConfig } from "../../interface/Base";
/**
* @description 名片表参数
* @since Alpha
* @since Alpha v0.1.2
* @returns {DBConfig}
*/
export const Config = {
storeName: "NameCard",
keyPath: "name",
indexes: ["type"],
export const Config: DBConfig = {
storeName: "NameCard",
keyPath: "name",
indexes: ["type"],
};
/**
* @description 名片数据
* @since Alpha
* @since Alpha v0.1.2
* @return {NameCard[]}
*/
export function getData() {
const data: Map<NameCard[]> = AppData.nameCards;
let result: NameCard[] = [];
Object.keys(data).map(key => {
const cards: NameCard[] = data[Number(key)];
cards.map(card => {
result.push(card);
});
});
return result;
export function getData (): NameCard[] {
const data: Map<NameCard[]> = AppData.nameCards;
const result: NameCard[] = [];
Object.keys(data).map((key) => {
const cards: NameCard[] = data[Number(key)];
return cards.map((card) => result.push(card));
});
return result;
}

View File

@@ -19,19 +19,19 @@
* @property {string} completed_time - 成就完成时间
* @property {number} progress - 成就进度
* @property {string} version - 成就版本
* @return Achievement
* @returns {Achievement}
*/
export interface Achievement {
id: number;
series: number;
order: number;
name: string;
description: string;
reward: number;
completed: boolean;
completed_time: string | null;
progress: number;
version: string;
id: number
series: number
order: number
name: string
description: string
reward: number
completed: boolean
completed_time: string | null
progress: number
version: string
}
/**
@@ -49,16 +49,16 @@ export interface Achievement {
* @property {string} card - 成就系列奖励,这边是名片名称
* @description 像是天地万象这种一直更新的成就系列,这边的 version 可能为 undefined
* @property {string} icon - 成就系列图标
* @return AchievementSeries
* @returns {AchievementSeries}
*/
export interface AchievementSeries {
id: number;
order: number;
name: string;
version: string;
achievements: number[];
total_count: number;
completed_count: number;
card?: string;
icon: string;
id: number
order: number
name: string
version: string
achievements: number[]
total_count: number
completed_count: number
card?: string
icon: string
}

View File

@@ -2,18 +2,31 @@
* @file interface Base
* @description interface Base
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha
* @since Alpha v0.1.2
*/
/**
* @description 定义一个 Map<T> 接口
* @since Alpha
* @since Alpha v0.1.2
* @description 该接口的方法实现在 TGMap<T> 中
* @see TGMap
* @interface Map
* @template T
* @return Map
* @returns {Map<T>}
*/
export interface Map<T> {
[key: number]: T;
export type Map<T> = Record<number, T>;
/**
* @description 定义 IndexedDB 数据库配置
* @since Alpha v0.1.2
* @interface DBConfig
* @property {string} storeName 数据库名称
* @property {string} keyPath 数据库主键
* @property {string[]} indexes 数据库索引
* @returns {DBConfig}
*/
export interface DBConfig {
storeName: string
keyPath: string
indexes: string[]
}

View File

@@ -13,12 +13,12 @@
* @property {string} characterCard 角色卡
* @property {string} actionCard 行动卡
* @property {string} monsterCard 魔物卡
* @return BaseCardType
* @returns {BaseCardType}
*/
export enum BaseCardType {
characterCard = "角色牌",
actionCard = "行动牌",
monsterCard = "魔物牌",
characterCard = "角色牌",
actionCard = "行动牌",
monsterCard = "魔物牌",
}
/**
@@ -38,16 +38,16 @@ export enum BaseCardType {
* @property {unknown} info 卡牌信息
* @property {unknown} skills 卡牌技能,仅角色卡与魔物卡有
* @property {unknown} affect 卡牌效果,仅行动卡有
* @return BaseCard
* @returns {BaseCard}
*/
export interface BaseCard {
name: string;
id: number;
type: BaseCardType;
icon: { normal: string; special?: string };
info: unknown;
skills?: unknown;
affect?: unknown;
name: string
id: number
type: BaseCardType
icon: { normal: string, special?: string }
info: unknown
skills?: unknown
affect?: unknown
}
/**
@@ -70,28 +70,28 @@ export interface BaseCard {
* @property {string} skills[].cost.value 花费值
* @description 当技能类型为 “召唤物” 时,会有以下属性
* @property {number} skills[].count 可用次数
* @return CharacterCard
* @returns {CharacterCard}
*/
export interface CharacterCard extends BaseCard {
type: BaseCardType.characterCard;
info: {
element: EnumElement;
weapon: EnumWeapon;
camp: EnumCamp;
source: string;
title: string;
description: string;
};
skills: {
name: string;
type: string;
description: string;
cost: {
type: string;
value: string;
};
count?: number;
}[];
type: BaseCardType.characterCard
info: {
element: EnumElement
weapon: EnumWeapon
camp: EnumCamp
source: string
title: string
description: string
}
skills: Array<{
name: string
type: string
description: string
cost: {
type: string
value: string
}
count?: number
}>
}
/**
@@ -109,20 +109,20 @@ export interface CharacterCard extends BaseCard {
* @description 当类型为“天赋”时,可能会有以下属性
* @property {string} info.charge 充能
* @property {string} affect 卡牌效果
* @return ActionCard
* @returns {ActionCard}
*/
export interface ActionCard extends BaseCard {
type: BaseCardType.actionCard;
info: {
actionType: EnumActionType;
actionTag: EnumActionTag;
actionCost: EnumActionCost;
source: string;
title: string;
description: string;
charge?: string;
};
affect: string;
type: BaseCardType.actionCard
info: {
actionType: EnumActionType
actionTag: EnumActionTag
actionCost: EnumActionCost
source: string
title: string
description: string
charge?: string
}
affect: string
}
/**
@@ -144,25 +144,25 @@ export interface ActionCard extends BaseCard {
* @property {string} skills[].cost.type 花费类型
* @property {string} skills[].cost.value 花费值
* @description 当技能类型为 “召唤物” 时,会有以下属性
* @return MonsterCard
* @returns {MonsterCard}
*/
export interface MonsterCard extends BaseCard {
type: BaseCardType.monsterCard;
info: {
element: EnumElement;
weapon: EnumWeapon;
camp: EnumCamp;
source: string;
};
skills: {
name: string;
type: string;
description: string;
cost: {
type: string;
value: string;
};
}[];
type: BaseCardType.monsterCard
info: {
element: EnumElement
weapon: EnumWeapon
camp: EnumCamp
source: string
}
skills: Array<{
name: string
type: string
description: string
cost: {
type: string
value: string
}
}>
}
/**
@@ -173,12 +173,12 @@ export interface MonsterCard extends BaseCard {
* @property {EnumElement} element 元素
* @property {EnumWeapon} weapon 武器
* @property {EnumCamp} camp 阵营
* @return CharacterCardType
* @returns {CharacterCardType}
*/
export interface CharacterCardType {
element: EnumElement;
weapon: EnumWeapon;
camp: EnumCamp;
element: EnumElement
weapon: EnumWeapon
camp: EnumCamp
}
/**
@@ -189,12 +189,12 @@ export interface CharacterCardType {
* @property {EnumActionType} actionType 类型
* @property {EnumActionTag} actionTag 标签
* @property {EnumActionCost} actionCost 花费
* @return ActionCardType
* @returns {ActionCardType}
*/
export interface ActionCardType {
actionType: EnumActionType;
actionTag: EnumActionTag;
actionCost: EnumActionCost;
actionType: EnumActionType
actionTag: EnumActionTag
actionCost: EnumActionCost
}
/**
@@ -209,16 +209,16 @@ export interface ActionCardType {
* @property {string} anemo 风元素
* @property {string} geo 岩元素
* @property {string} dendro 草元素
* @return EnumElement
* @returns {EnumElement}
*/
export enum EnumElement {
pyro = "火元素",
hydro = "水元素",
cryo = "冰元素",
electro = "雷元素",
anemo = "风元素",
geo = "岩元素",
dendro = "草元素",
pyro = "火元素",
hydro = "水元素",
cryo = "冰元素",
electro = "雷元素",
anemo = "风元素",
geo = "岩元素",
dendro = "草元素",
}
/**
@@ -232,20 +232,20 @@ export enum EnumElement {
* @property {string} bow 弓
* @property {string} catalyst 法器
* @property {string} other 其他武器
* @return EnumWeapon
* @returns {EnumWeapon}
*/
export enum EnumWeapon {
sword = "单手剑",
claymore = "双手剑",
pole = "长柄武器",
bow = "弓",
catalyst = "法器",
other = "其他武器",
sword = "单手剑",
claymore = "双手剑",
pole = "长柄武器",
bow = "弓",
catalyst = "法器",
other = "其他武器",
}
/**
* @description 角色牌阵营
* @enum EnumCamp
* @enum {EnumCamp}
* @since Alpha
* @see CharacterCardType
* @property {string} mondstadt 蒙德
@@ -254,15 +254,15 @@ export enum EnumWeapon {
* @property {string} sumeru 须弥
* @property {string} fatui 愚人众
* @property {string} monster 魔物
* @return EnumCamp
* @returns {EnumCamp}
*/
export enum EnumCamp {
mondstadt = "蒙德",
liyue = "璃月",
inazuma = "稻妻",
sumeru = "须弥",
fatui = "愚人众",
monster = "魔物",
mondstadt = "蒙德",
liyue = "璃月",
inazuma = "稻妻",
sumeru = "须弥",
fatui = "愚人众",
monster = "魔物",
}
/**
@@ -273,12 +273,12 @@ export enum EnumCamp {
* @property {string} equipment 装备牌
* @property {string} event 事件牌
* @property {string} support 支援牌
* @return EnumActionType
* @returns {EnumActionType}
*/
export enum EnumActionType {
equipment = "装备牌",
event = "事件牌",
support = "支援牌",
equipment = "装备牌",
event = "事件牌",
support = "支援牌",
}
/**
@@ -295,18 +295,18 @@ export enum EnumActionType {
* @property {string} filed 场地
* @property {string} elementResonance 元素共鸣
* @property {string} other 其他标签
* @return EnumActionTag
* @returns {EnumActionTag}
*/
export enum EnumActionTag {
weapon = "武器",
artifact = "圣遗物",
talent = "天赋",
food = "料理",
item = "道具",
partner = "伙伴",
filed = "场地",
elementResonance = "元素共鸣",
other = "其他标签",
weapon = "武器",
artifact = "圣遗物",
talent = "天赋",
food = "料理",
item = "道具",
partner = "伙伴",
filed = "场地",
elementResonance = "元素共鸣",
other = "其他标签",
}
/**
@@ -322,15 +322,15 @@ export enum EnumActionTag {
* @property {string} cost5 花费5
* @property {string} cost6 花费6
* @property {string} other 其他花费
* @return EnumActionCost
* @returns {EnumActionCost}
*/
export enum EnumActionCost {
cost0 = "花费0",
cost1 = "花费1",
cost2 = "花费2",
cost3 = "花费3",
cost4 = "花费4",
cost5 = "花费5",
cost6 = "花费6",
other = "其他花费",
cost0 = "花费0",
cost1 = "花费1",
cost2 = "花费2",
cost3 = "花费3",
cost4 = "花费4",
cost5 = "花费5",
cost6 = "花费6",
other = "其他花费",
}

View File

@@ -16,14 +16,14 @@
* @property {string} profile - 名片 Profile 图路径
* @property {number} type - 名片类型 (0: 其他1: 成就2角色3纪行4活动)
* @property {string} source - 名片来源
* @return NameCard
* @returns {NameCard}
*/
export interface NameCard {
name: string;
description: string;
icon: string;
bg: string;
profile: string;
type: string;
source: string;
name: string
description: string
icon: string
bg: string
profile: string
type: string
source: string
}

View File

@@ -19,13 +19,9 @@ import { createVuetify } from "vuetify";
import "./assets/index.css";
if (import.meta.env.MODE === "development") {
await import("@vue/devtools").then(i => {
await import("@vue/devtools").then((i) => {
i.default.connect(/* host, port */);
});
}
createApp(App)
.use(router)
.use(store)
.use(createVuetify())
.mount("#app");
createApp(App).use(router).use(store).use(createVuetify()).mount("#app");

View File

@@ -11,12 +11,12 @@ import { getAnnoCards } from "./utils/announcements";
import { parseAnnoContent } from "./utils/annoParser";
const GenshinOper = {
Announcement: {
getList: getAnnouncementList,
getContent: getAnnouncementContent,
card: getAnnoCards,
parser: parseAnnoContent,
},
Announcement: {
getList: getAnnouncementList,
getContent: getAnnouncementContent,
card: getAnnoCards,
parser: parseAnnoContent,
},
};
export default GenshinOper;

View File

@@ -5,7 +5,7 @@
* @since Alpha v0.1.1
*/
import { Hk4eResponse } from "./base";
import { type Hk4eResponse } from "./base";
/**
* @description 原神游戏内公告列表返回
@@ -14,10 +14,10 @@ import { Hk4eResponse } from "./base";
* @interface AnnoListResponse
* @extends Hk4eResponse
* @property {AnnoListData} data 公告数据
* @return {AnnoListResponse}
* @returns {AnnoListResponse}
*/
export interface AnnoListResponse extends Hk4eResponse {
data: AnnoListData;
data: AnnoListData
}
/**
@@ -27,10 +27,10 @@ export interface AnnoListResponse extends Hk4eResponse {
* @interface AnnoContentResponse
* @extends Hk4eResponse
* @property {AnnoContentData} data 公告数据
* @return {AnnoContentResponse}
* @returns {AnnoContentResponse}
*/
export interface AnnoContentResponse extends Hk4eResponse {
data: AnnoContentData;
data: AnnoContentData
}
/**
@@ -50,22 +50,22 @@ export interface AnnoContentResponse extends Hk4eResponse {
* @property {boolean} pic_alert 是否有紧急图片
* @property {number} pic_alert_id 紧急图片 ID
* @property {unknown} static_sign 静态签名
* @return {AnnoListData}
* @returns {AnnoListData}
*/
export interface AnnoListData {
list: Announcement[];
total: number;
type_list: AnnoTypeList[];
alert: boolean;
alert_id: number;
time_zone: number;
t: string;
pic_list: unknown[];
pic_total: number;
pic_type_list: unknown[];
pic_alert: boolean;
pic_alert_id: number;
static_sign: unknown;
list: Announcement[]
total: number
type_list: AnnoTypeList[]
alert: boolean
alert_id: number
time_zone: number
t: string
pic_list: unknown[]
pic_total: number
pic_type_list: unknown[]
pic_alert: boolean
pic_alert_id: number
static_sign: unknown
}
/**
@@ -76,13 +76,13 @@ export interface AnnoListData {
* @property {number} total 公告总数
* @property {unknown[]} pic_list 图片列表
* @property {number} pic_total 图片总数
* @return {AnnoContentData}
* @returns {AnnoContentData}
*/
export interface AnnoContentData {
list: AnnoContentItem[];
total: number;
pic_list: unknown[];
pic_total: number;
list: AnnoContentItem[]
total: number
pic_list: unknown[]
pic_total: number
}
/**
@@ -92,12 +92,12 @@ export interface AnnoContentData {
* @property {number} id 类型 ID
* @property {string} name 类型名称
* @property {string} mi18n_name 类型名称
* @return {AnnoTypeList}
* @returns {AnnoTypeList}
*/
export interface AnnoTypeList {
id: number;
name: string;
mi18n_name: string;
id: number
name: string
mi18n_name: string
}
/**
@@ -107,12 +107,12 @@ export interface AnnoTypeList {
* @property {AnnoListItem[]} list 公告列表
* @property {number} type_id 类型 ID
* @property {string} type_label 类型标签
* @return {Announcement}
* @returns {Announcement}
*/
export interface Announcement {
list: AnnoListItem[];
type_id: number;
type_label: string;
list: AnnoListItem[]
type_id: number
type_label: string
}
/**
@@ -139,29 +139,29 @@ export interface Announcement {
* @property {number} remind_ver 公告提醒版本
* @property {boolean} has_content 是否有内容
* @property {boolean} extra_remind 是否有额外提醒
* @return {AnnoListItem}
* @returns {AnnoListItem}
*/
export interface AnnoListItem {
ann_id: number;
title: string;
subtitle: string;
banner: string;
content: unknown;
type_label: string;
tag_label: string;
tag_icon: string;
login_alert: number;
lang: string;
start_time: string;
end_time: string;
type: number;
remind: number;
alert: number;
tag_start_time: string;
tag_end_time: string;
remind_ver: number;
has_content: boolean;
extra_remind: boolean;
ann_id: number
title: string
subtitle: string
banner: string
content: unknown
type_label: string
tag_label: string
tag_icon: string
login_alert: number
lang: string
start_time: string
end_time: string
type: number
remind: number
alert: number
tag_start_time: string
tag_end_time: string
remind_ver: number
has_content: boolean
extra_remind: boolean
}
/**
@@ -174,15 +174,15 @@ export interface AnnoListItem {
* @property {string} banner 公告图片
* @property {string} content 公告内容为 HTML
* @property {string} lang 公告语言
* @return {AnnoContentItem}
* @returns {AnnoContentItem}
*/
export interface AnnoContentItem {
ann_id: number;
title: string;
subtitle: string;
banner: string;
content: string;
lang: string;
ann_id: number
title: string
subtitle: string
banner: string
content: string
lang: string
}
/**
@@ -197,15 +197,15 @@ export interface AnnoContentItem {
* @property {string} tag_icon 公告标签图标
* @property {string} start_time 公告开始时间
* @property {string} end_time 公告结束时间
* @return {AnnoListCard}
* @returns {AnnoListCard}
*/
export interface AnnoListCard {
id: number;
title: string;
subtitle: string;
banner: string;
type_label: string;
tag_icon: string;
start_time: string;
end_time: string;
id: number
title: string
subtitle: string
banner: string
type_label: string
tag_icon: string
start_time: string
end_time: string
}

View File

@@ -12,10 +12,10 @@
* @property {number} retcode 状态码
* @property {string} message 状态信息
* @property {any} data 数据
* @return {Hk4eResponse}
* @returns {Hk4eResponse}
*/
export interface Hk4eResponse {
retcode: number;
message: string;
data: any;
retcode: number
message: string
data: any
}

View File

@@ -2,21 +2,21 @@
* @file plugins Genshin request announcements.ts
* @description 原神游戏内公告请求
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.1.1
* @since Alpha v0.1.2
*/
import { http } from "@tauri-apps/api";
import { Hk4e_ANNO_API } from "./base";
import { Hk4eAnnoApi } from "./base";
import {
AnnoListResponse,
AnnoContentResponse,
AnnoListData,
AnnoContentItem,
type AnnoListResponse,
type AnnoContentResponse,
type AnnoListData,
type AnnoContentItem,
} from "../interface/announcement";
// 公告 API
const ANNO_LIST_API = `${Hk4e_ANNO_API}/getAnnList?`;
const ANNO_CONTENT_API = `${Hk4e_ANNO_API}/getAnnContent?`;
const ANNO_LIST_API = `${Hk4eAnnoApi}/getAnnList?`;
const ANNO_CONTENT_API = `${Hk4eAnnoApi}/getAnnContent?`;
// 公告 Query
const ANNO_QUERY =
"game=hk4e&game_biz=hk4e_cn&lang=zh-cn&bundle_id=hk4e_cn&platform=pc&region=cn_gf01&level=60&uid=500299765";
@@ -24,28 +24,26 @@ const ANNO_QUERY =
/**
* @description 获取游戏内公告列表
* @since Alpha v0.1.1
* @return {Promise<AnnoListData>}
* @returns {Promise<AnnoListData>}
*/
export async function getAnnouncementList(): Promise<AnnoListData> {
return await http
.fetch<AnnoListResponse>(`${ANNO_LIST_API}${ANNO_QUERY}`)
.then(res => res.data.data);
export async function getAnnouncementList (): Promise<AnnoListData> {
return await http.fetch<AnnoListResponse>(`${ANNO_LIST_API}${ANNO_QUERY}`).then((res) => res.data.data);
}
/**
* @description 获取游戏内公告内容
* @since Alpha v0.1.1
* @param {number} ann_id 公告 ID
* @return {Promise<AnnoContentItem>}
* @since Alpha v0.1.2
* @param {number} annId 公告 ID
* @returns {Promise<AnnoContentItem>}
*/
export async function getAnnouncementContent(ann_id: number): Promise<AnnoContentItem> {
const annoContents: AnnoContentItem[] = await http
.fetch<AnnoContentResponse>(`${ANNO_CONTENT_API}${ANNO_QUERY}`)
.then(res => res.data.data.list);
const annoContent = annoContents.find(item => item.ann_id === ann_id);
if (annoContent) {
return annoContent;
} else {
throw new Error("公告内容不存在");
}
export async function getAnnouncementContent (annId: number): Promise<AnnoContentItem> {
const annoContents: AnnoContentItem[] = await http
.fetch<AnnoContentResponse>(`${ANNO_CONTENT_API}${ANNO_QUERY}`)
.then((res) => res.data.data.list);
const annoContent = annoContents.find((item) => item.ann_id === annId);
if (annoContent) {
return annoContent;
} else {
throw new Error("公告内容不存在");
}
}

View File

@@ -2,10 +2,10 @@
* @file plugins Genshin request base.ts
* @description 游戏内数据请求的基础类
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.1.1
* @since Alpha v0.1.2
*/
// Hk4e API目前先用这几个后续有需要再加
const Hk4e_API = "https://hk4e-api.mihoyo.com"; // 基础 API
export const Hk4e_ANNO_API = `${Hk4e_API}/common/hk4e_cn/announcement/api`; // 公告 API
export const Hk4e_Gacha_API = `${Hk4e_API}/event/gacha_info/api;`; // 卡池 API
const Hk4eApi = "https://hk4e-api.mihoyo.com"; // 基础 API
export const Hk4eAnnoApi = `${Hk4eApi}/common/hk4e_cn/announcement/api`; // 公告 API
export const Hk4eGachaApi = `${Hk4eApi}/event/gacha_info/api;`; // 卡池 API

View File

@@ -9,70 +9,70 @@
* @description 解析游戏内公告数据
* @since Alpha v0.1.1
* @param {string} data 游戏内公告数据
* @return {string} 解析后的数据
* @returns {string} 解析后的数据
*/
export function parseAnnoContent(data: string): string {
const htmlBase = new DOMParser().parseFromString(data, "text/html");
// 遍历所有 span 标签
htmlBase.querySelectorAll("span").forEach(span => {
if (span.style.fontSize) {
span.style.fontSize = "";
}
if (span.children.length === 0) {
return (span.innerHTML = decodeRegExp(span.innerHTML));
} else {
span.querySelectorAll("*").forEach(child => {
if (child.children.length === 0) {
return (child.innerHTML = decodeRegExp(child.innerHTML));
}
});
}
});
// 遍历所有 p 标签
htmlBase.querySelectorAll("p").forEach(p => {
// 如果没有子元素
if (p.children.length === 0) {
return (p.innerHTML = decodeRegExp(p.innerHTML));
} else {
p.querySelectorAll("*").forEach(child => {
if (child.children.length === 0) {
return (child.innerHTML = decodeRegExp(child.innerHTML));
}
});
}
});
// 遍历所有 a 标签
htmlBase.querySelectorAll("a").forEach(a => {
const span = htmlBase.createElement("i");
span.classList.add("mdi", "mdi-link-variant", "anno-link-icon");
// 添加到 a 标签中
a.prepend(span);
if (a.href.startsWith("javascript:miHoYoGameJSSDK.openInBrowser")) {
a.href = a.href.replace("javascript:miHoYoGameJSSDK.openInBrowser('", "").replace("');", "");
a.target = "_blank";
} else if (a.href.startsWith("javascript:miHoYoGameJSSDK.openInWebview")) {
a.href = a.href.replace("javascript:miHoYoGameJSSDK.openInWebview('", "").replace("');", "");
a.target = "_blank";
}
});
return htmlBase.body.innerHTML;
export function parseAnnoContent (data: string): string {
const htmlBase = new DOMParser().parseFromString(data, "text/html");
// 遍历所有 span 标签
htmlBase.querySelectorAll("span").forEach((span) => {
if (span.style.fontSize) {
span.style.fontSize = "";
}
if (span.children.length === 0) {
return (span.innerHTML = decodeRegExp(span.innerHTML));
} else {
span.querySelectorAll("*").forEach((child) => {
if (child.children.length === 0) {
return (child.innerHTML = decodeRegExp(child.innerHTML));
}
});
}
});
// 遍历所有 p 标签
htmlBase.querySelectorAll("p").forEach((p) => {
// 如果没有子元素
if (p.children.length === 0) {
return (p.innerHTML = decodeRegExp(p.innerHTML));
} else {
p.querySelectorAll("*").forEach((child) => {
if (child.children.length === 0) {
return (child.innerHTML = decodeRegExp(child.innerHTML));
}
});
}
});
// 遍历所有 a 标签
htmlBase.querySelectorAll("a").forEach((a) => {
const span = htmlBase.createElement("i");
span.classList.add("mdi", "mdi-link-variant", "anno-link-icon");
// 添加到 a 标签中
a.prepend(span);
if (a.href.startsWith("javascript:miHoYoGameJSSDK.openInBrowser")) {
a.href = a.href.replace("javascript:miHoYoGameJSSDK.openInBrowser('", "").replace("');", "");
a.target = "_blank";
} else if (a.href.startsWith("javascript:miHoYoGameJSSDK.openInWebview")) {
a.href = a.href.replace("javascript:miHoYoGameJSSDK.openInWebview('", "").replace("');", "");
a.target = "_blank";
}
});
return htmlBase.body.innerHTML;
}
/**
* @description 转义正则表达式
* @since Alpha v0.1.1
* @param {string} data 内容
* @return {string} 转义后的内容
* @returns {string} 转义后的内容
*/
export function decodeRegExp(data: string): string {
let res = data;
if (res.length === 0) return res;
res = res.replace(/&amp;/g, "&");
res = res.replace(/&lt;/g, "<");
res = res.replace(/&gt;/g, ">");
res = res.replace(/&nbsp;/g, " ");
res = res.replace(/&#39;/g, "'");
res = res.replace(/&quot;/g, '"');
res = res.replace(/&apos;/g, "'");
return res;
export function decodeRegExp (data: string): string {
let res = data;
if (res.length === 0) return res;
res = res.replace(/&amp;/g, "&");
res = res.replace(/&lt;/g, "<");
res = res.replace(/&gt;/g, ">");
res = res.replace(/&nbsp;/g, " ");
res = res.replace(/&#39;/g, "'");
res = res.replace(/&quot;/g, "\"");
res = res.replace(/&apos;/g, "'");
return res;
}

View File

@@ -5,29 +5,29 @@
* @since Alpha v0.1.1
*/
import { AnnoListData, AnnoListCard, Announcement, AnnoListItem } from "../interface/announcement";
import { type AnnoListData, type AnnoListCard, type Announcement, type AnnoListItem } from "../interface/announcement";
/**
* @description 将获取到的数据转为渲染用的卡片
* @since Alpha v0.1.1
* @param {AnnoListData} data 公告数据
* @return {AnnoListCard[]} 渲染用的卡片
* @returns {AnnoListCard[]} 渲染用的卡片
*/
export function getAnnoCards(data: AnnoListData): AnnoListCard[] {
const cards: AnnoListCard[] = [];
data.list.map((annoList: Announcement) => {
return annoList.list.map((anno: AnnoListItem) => {
return cards.push({
id: anno.ann_id,
title: anno.title,
subtitle: anno.subtitle,
banner: anno.banner,
type_label: anno.type_label,
tag_icon: anno.tag_icon,
start_time: anno.start_time,
end_time: anno.end_time,
});
});
});
return cards;
export function getAnnoCards (data: AnnoListData): AnnoListCard[] {
const cards: AnnoListCard[] = [];
data.list.map((annoList: Announcement) => {
return annoList.list.map((anno: AnnoListItem) => {
return cards.push({
id: anno.ann_id,
title: anno.title,
subtitle: anno.subtitle,
banner: anno.banner,
type_label: anno.type_label,
tag_icon: anno.tag_icon,
start_time: anno.start_time,
end_time: anno.end_time,
});
});
});
return cards;
}

View File

@@ -25,41 +25,41 @@ import { getCalendarData } from "./request/calendar";
import { getCalendarCard } from "./utils/calendar";
const MysOper = {
Post: {
get: getPostData,
parser: PostParser,
},
Gacha: {
get: getGachaData,
card: getGachaCard,
},
Position: {
get: getPositionData,
card: getPositionCard,
},
News: {
get: {
notice: getNoticeList,
activity: getActivityList,
news: getNewsList,
},
card: {
notice: getNoticeCard,
activity: getActivityCard,
news: getNewsCard,
},
},
Lottery: {
get: getLotteryData,
card: {
lottery: getLotteryCard,
reward: getLotteryRewardCard,
},
},
Calendar: {
get: getCalendarData,
card: getCalendarCard,
},
Post: {
get: getPostData,
parser: PostParser,
},
Gacha: {
get: getGachaData,
card: getGachaCard,
},
Position: {
get: getPositionData,
card: getPositionCard,
},
News: {
get: {
notice: getNoticeList,
activity: getActivityList,
news: getNewsList,
},
card: {
notice: getNoticeCard,
activity: getActivityCard,
news: getNewsCard,
},
},
Lottery: {
get: getLotteryData,
card: {
lottery: getLotteryCard,
reward: getLotteryRewardCard,
},
},
Calendar: {
get: getCalendarData,
card: getCalendarCard,
},
};
export default MysOper;

View File

@@ -12,12 +12,12 @@
* @property {number} retcode 状态码
* @property {string} message 状态信息
* @property {any} data 数据
* @return {MysResponse}
* @returns {MysResponse}
*/
export interface MysResponse {
retcode: number;
message: string;
data: any;
retcode: number
message: string
data: any
}
/**
@@ -26,12 +26,12 @@ export interface MysResponse {
* @interface MysObcResponse
* @extends MysResponse
* @property {MysObc[]} data.list obc 列表
* @return {MysObcResponse}
* @returns {MysObcResponse}
*/
export interface MysObcResponse extends MysResponse {
data: {
list: MysObc[];
};
data: {
list: MysObc[]
}
}
/**
@@ -45,16 +45,16 @@ export interface MysObcResponse extends MysResponse {
* @property {string} ch_ext 结构化扩展信息
* @property {any[]} children 子节点
* @property {unknown[]} list 列表
* @return {MysObc}
* @returns {MysObc}
*/
export interface MysObc {
id: number;
name: string;
parent_id: number;
depth: number;
ch_ext: string;
children: MysObc[];
list: unknown[];
id: number
name: string
parent_id: number
depth: number
ch_ext: string
children: MysObc[]
list: unknown[]
}
/**
@@ -69,14 +69,14 @@ export interface MysObc {
* @property {number} 5 大别野
* @property {number} 6 崩坏:星穹铁道
* @property {number} 8 绝区零
* @return {MysGid}
* @returns {MysGid}
*/
export enum MysGid {
BH3 = 1,
YS = 2,
BH2 = 3,
WD = 4,
DBY = 5,
SR = 6,
ZZZ = 8,
BH3 = 1,
YS = 2,
BH2 = 3,
WD = 4,
DBY = 5,
SR = 6,
ZZZ = 8,
}

View File

@@ -5,8 +5,8 @@
* @since Alpha v0.1.1
*/
import { MysResponse } from "./base";
import { Map } from "../../../interface/Base";
import { type MysResponse } from "./base";
import { type Map } from "../../../interface/Base";
/**
* @description 日历返回数据
@@ -14,12 +14,12 @@ import { Map } from "../../../interface/Base";
* @interface CalendarResponse
* @extends {MysResponse}
* @property {CalendarData[]} data.list 日历数据
* @return {CalendarResponse}
* @returns {CalendarResponse}
*/
export interface CalendarResponse extends MysResponse {
data: {
list: CalendarData[];
};
data: {
list: CalendarData[]
}
}
/**
@@ -43,26 +43,26 @@ export interface CalendarResponse extends MysResponse {
* @property {CalendarContent[]} contentInfos 材料内容kind 为 2 时不为空
* @property {string} sort 排序kind 为 2 时不为空,反序列化后为 Map<number, number>,前者为星期,后者为排序
* @property {CalendarContent[]} contentSource 材料来源kind 为 2 时不为空
* @return {CalendarData}
* @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[];
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[]
}
/**
@@ -73,13 +73,13 @@ export interface CalendarData {
* @property {string} title 材料/秘境 名称
* @property {string} icon 材料/秘境 图片 URL
* @property {string} bbs_url 链接,一般为空
* @return {CalendarContent}
* @returns {CalendarContent}
*/
export interface CalendarContent {
id: string;
title: string;
icon: string;
bbs_url: string;
id: string
title: string
icon: string
bbs_url: string
}
/**
@@ -94,15 +94,15 @@ export interface CalendarContent {
* @property {string[]} drop_day 掉落日
* @property {Map<number>} sort_day 排序
* @property {CalendarContent[]} contentInfos 材料内容
* @return {CalendarCard}
* @returns {CalendarCard}
*/
export interface CalendarCard {
id: number;
type: number;
title: string;
cover: string;
url: string;
drop_day: string[];
sort_day: Map<number>;
contentInfos: CalendarContent[];
id: number
type: number
title: string
cover: string
url: string
drop_day: string[]
sort_day: Map<number>
contentInfos: CalendarContent[]
}

View File

@@ -5,7 +5,7 @@
* @since Alpha
*/
import { MysResponse } from "./base";
import { type MysResponse } from "./base";
/**
* @description 获取卡池信息的返回类型
@@ -13,12 +13,12 @@ import { MysResponse } from "./base";
* @interface GachaResponse
* @extends MysResponse
* @property {GachaData[]} data.list 卡池数据
* @return {GachaResponse}
* @returns {GachaResponse}
*/
export interface GachaResponse extends MysResponse {
data: {
list: GachaData[];
};
data: {
list: GachaData[]
}
}
/**
@@ -36,19 +36,19 @@ export interface GachaResponse extends MysResponse {
* @description 如下时间示例2023-03-21 17:59:59
* @property {string} start_time 卡池开始时间
* @property {string} end_time 卡池结束时间
* @return {GachaData}
* @returns {GachaData}
*/
export interface GachaData {
id: string;
title: string;
activity_url: string;
content_before_act: string;
pool: GachaPool[];
voice_icon: string;
voice_url: string;
voice_status: string;
start_time: string;
end_time: string;
id: string
title: string
activity_url: string
content_before_act: string
pool: GachaPool[]
voice_icon: string
voice_url: string
voice_status: string
start_time: string
end_time: string
}
/**
@@ -57,11 +57,11 @@ export interface GachaData {
* @interface GachaPool
* @property {string} icon 卡池角色头像
* @property {string} url 卡池角色URL
* @return {GachaPool}
* @returns {GachaPool}
*/
export interface GachaPool {
icon: string;
url: string;
icon: string
url: string
}
/**
@@ -79,19 +79,19 @@ export interface GachaPool {
* @property {string} time.start_stamp 卡池开始时间戳
* @property {string} time.end 卡池结束时间
* @property {string} time.end_stamp 卡池结束时间戳
* @return {GachaCard}
* @returns {GachaCard}
*/
export interface GachaCard {
title: string;
subtitle: string;
cover: string;
post_id: number;
characters: GachaPool[];
voice: GachaPool;
time: {
start: string;
start_stamp: number;
end: string;
end_stamp: number;
};
title: string
subtitle: string
cover: string
post_id: number
characters: GachaPool[]
voice: GachaPool
time: {
start: string
start_stamp: number
end: string
end_stamp: number
}
}

View File

@@ -2,11 +2,11 @@
* @file plugins Mys interface lottery.ts
* @description Mys 插件抽奖接口
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.1.1
* @since Alpha v0.1.2
*/
import { MysResponse } from "./base";
import { User } from "./user";
import { type MysResponse } from "./base";
import { type User } from "./user";
/**
* @description 抽奖返回数据
@@ -14,12 +14,12 @@ import { User } from "./user";
* @interface LotteryResponse
* @extends {MysResponse}
* @property {LotteryData} data.show_lottery 抽奖数据
* @return {LotteryResponse}
* @returns {LotteryResponse}
*/
export interface LotteryResponse extends MysResponse {
data: {
show_lottery: LotteryData;
};
data: {
show_lottery: LotteryData
}
}
/**
@@ -41,24 +41,24 @@ export interface LotteryResponse extends MysResponse {
* @property {string} entity_id 实体 ID // 若为帖子,则为帖子 ID
* @property {string} entity_type 实体类型 // Post: 帖子
* @property {string} now_time 当前时间
* @return {LotteryData}
* @returns {LotteryData}
*/
export interface LotteryData {
id: string;
creator: User;
draw_time: string;
participant_way: string;
is_expect_unfocus_user: boolean;
is_expect_non_real_name_user: boolean;
user_rewards: LotteryReward[];
status: string;
is_blocked: boolean;
user_status: string;
is_upload_address: boolean;
lottery_entity_summary: string;
entity_id: string;
entity_type: string;
now_time: string;
id: string
creator: User
draw_time: string
participant_way: string
is_expect_unfocus_user: boolean
is_expect_non_real_name_user: boolean
user_rewards: LotteryReward[]
status: string
is_blocked: boolean
user_status: string
is_upload_address: boolean
lottery_entity_summary: string
entity_id: string
entity_type: string
now_time: string
}
/**
@@ -71,15 +71,15 @@ export interface LotteryData {
* @property {boolean} is_send_by_post 是否通过帖子发放
* @property {User[]} users 用户列表
* @property {string} id 奖励 ID
* @return {LotteryReward}
* @returns {LotteryReward}
*/
export interface LotteryReward {
reward_name: string;
winner_number: number;
scheduled_winner_number: number;
is_send_by_post: boolean;
users: User[];
id: string;
reward_name: string
winner_number: number
scheduled_winner_number: number
is_send_by_post: boolean
users: User[]
id: string
}
/**
@@ -92,29 +92,30 @@ export interface LotteryReward {
* @property {User} creator 创建者
* @property {string} drawTime 开奖时间
* @property {LotteryRewardCard[]} rewards 奖励列表
* @return {LotteryCard}
* @returns {LotteryCard}
*/
export interface LotteryCard {
id: string;
participantWay: string;
status: string;
creator: User;
drawTime: string;
rewards: LotteryRewardCard[];
id: string
participantWay: string
status: string
creator: User
drawTime: string
rewards: LotteryRewardCard[]
}
/**
* @description 渲染用的奖励信息
* @since Alpha v0.1.1
* @since Alpha v0.1.2
* @interface LotteryRewardCard
* @property {string} rewardName 奖励名称
* @property {number} winnerNumber 获奖人数
* @property {number} scheduledWinnerNumber 预计获奖人数
* @property {User[]} users 用户列表
* @returns {LotteryRewardCard}
*/
export interface LotteryRewardCard {
rewardName: string;
winnerNumber: number;
scheduledWinnerNumber: number;
users: User[];
rewardName: string
winnerNumber: number
scheduledWinnerNumber: number
users: User[]
}

View File

@@ -5,10 +5,10 @@
* @since Alpha
*/
import { MysResponse } from "./base";
import { Post, Forum, Topic, PostStat } from "./post";
import { User, SelfOperation } from "./user";
import { ImageData, HelpSys } from "./utils";
import { type MysResponse } from "./base";
import { type Post, type Forum, type Topic, type PostStat } from "./post";
import { type User, type SelfOperation } from "./user";
import { type ImageData, type HelpSys } from "./utils";
/**
* @description 咨讯返回数据
@@ -16,10 +16,10 @@ import { ImageData, HelpSys } from "./utils";
* @interface NewsResponse
* @extends {MysResponse}
* @property {NewsData} data 咨讯数据
* @return {NewsResponse}
* @returns {NewsResponse}
*/
export interface NewsResponse extends MysResponse {
data: NewsData;
data: NewsData
}
/**
@@ -29,12 +29,12 @@ export interface NewsResponse extends MysResponse {
* @property {number} last_id 最后一条咨讯 ID
* @property {boolean} is_last 是否最后一页
* @property {NewsItem[]} list 咨讯列表
* @return {NewsData}
* @returns {NewsData}
*/
export interface NewsData {
last_id: number;
is_last: boolean;
list: NewsItem[];
last_id: number
is_last: boolean
list: NewsItem[]
}
/**
@@ -62,30 +62,30 @@ export interface NewsData {
* @property {unknown} forum_rank_info 版块排名信息,可能为 null // TODO: 未知
* @property {unknown[]} link_card_list 链接卡片列表,可能为 null // TODO: 未知
* @property {NewsMeta} news_meta 元数据
* @return {NewsItem}
* @returns {NewsItem}
*/
export interface NewsItem {
post: Post;
forum: Forum;
topics: Topic[];
user: User;
self_operation: SelfOperation;
stat: PostStat;
help_sys: HelpSys;
cover: ImageData;
image_list: ImageData[];
is_official_master: boolean;
is_user_master: boolean;
hot_reply_exist: boolean;
vote_count: number;
last_modify_time: number;
recommend_type: string;
collection: unknown;
vod_list: unknown[];
is_block_on: boolean;
forum_rank_info: unknown;
link_card_list: unknown[];
news_meta: NewsMeta;
post: Post
forum: Forum
topics: Topic[]
user: User
self_operation: SelfOperation
stat: PostStat
help_sys: HelpSys
cover: ImageData
image_list: ImageData[]
is_official_master: boolean
is_user_master: boolean
hot_reply_exist: boolean
vote_count: number
last_modify_time: number
recommend_type: string
collection: unknown
vod_list: unknown[]
is_block_on: boolean
forum_rank_info: unknown
link_card_list: unknown[]
news_meta: NewsMeta
}
/**
@@ -95,12 +95,12 @@ export interface NewsItem {
* @property {number} activity_status 活动状态 // ActivityStatus
* @property {string} start_at_sec 活动开始时间戳,单位秒
* @property {string} end_at_sec 活动结束时间戳,单位秒
* @return {NewsMeta}
* @returns {NewsMeta}
*/
export interface NewsMeta {
activity_status: number;
start_at_sec: string;
end_at_sec: string;
activity_status: number
start_at_sec: string
end_at_sec: string
}
/**
@@ -112,14 +112,14 @@ export interface NewsMeta {
* @property {number} post_id 帖子 ID
* @property {string} subtitle 副标题
* @property {ActivityStatus} status 活动状态,仅活动咨讯有
* @return {NewsCard}
* @returns {NewsCard}
*/
export interface NewsCard {
title: string;
cover: string;
post_id: number;
subtitle: string;
status?: ActivityStatus;
title: string
cover: string
post_id: number
subtitle: string
status?: ActivityStatus
}
/**
@@ -127,9 +127,9 @@ export interface NewsCard {
* @since Alpha
* @property {string} status 活动状态
* @property {string} colorCss 活动状态按钮背景色
* @return {ActivityStatus}
* @returns {ActivityStatus}
*/
export interface ActivityStatus {
status: string;
colorCss: string;
status: string
colorCss: string
}

View File

@@ -5,7 +5,7 @@
* @since Alpha v0.1.1
*/
import { MysObcResponse, MysObc } from "./base";
import { type MysObcResponse, type MysObc } from "./base";
/**
* @description 获取热点追踪信息的返回类型
@@ -13,12 +13,12 @@ import { MysObcResponse, MysObc } from "./base";
* @interface PositionResponse
* @extends MysObcResponse
* @property {PositionObc[]} data.list obc 列表
* @return {PositionResponse}
* @returns {PositionResponse}
*/
export interface PositionResponse extends MysObcResponse {
data: {
list: PositionObc[];
};
data: {
list: PositionObc[]
}
}
/**
@@ -27,10 +27,10 @@ export interface PositionResponse extends MysObcResponse {
* @interface PositionObc
* @extends MysObc
* @property {PositionData[]} list 列表
* @return {PositionObc}
* @returns {PositionObc}
*/
export interface PositionObc extends MysObc {
list: PositionData[];
list: PositionData[]
}
/**
@@ -50,22 +50,22 @@ export interface PositionObc extends MysObc {
* @property {string} article_time 时间
* @property {string} create_time 创建时间 // 2023-03-31 11:16:57
* @property {string} end_time 结束时间 // 1680465599000
* @return {PositionData}
* @returns {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;
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
}
/**
@@ -81,17 +81,17 @@ export interface PositionData {
* @property {number} time.start_stamp 开始时间戳
* @property {string} time.end 结束时间
* @property {number} time.end_stamp 结束时间戳
* @return {PositionCard}
* @returns {PositionCard}
*/
export interface PositionCard {
title: string;
post_id: number;
icon: string;
abstract: string;
time: {
start: string;
start_stamp: number;
end: string;
end_stamp: number;
};
title: string
post_id: number
icon: string
abstract: string
time: {
start: string
start_stamp: number
end: string
end_stamp: number
}
}

View File

@@ -5,10 +5,10 @@
* @since Alpha v0.1.1
*/
import { MysResponse } from "./base";
import { NewsMeta } from "./news";
import { User, SelfOperation } from "./user";
import { ImageData, HelpSys } from "./utils";
import { type MysResponse } from "./base";
import { type NewsMeta } from "./news";
import { type User, type SelfOperation } from "./user";
import { type ImageData, type HelpSys } from "./utils";
/**
* @description 帖子返回数据
@@ -16,12 +16,12 @@ import { ImageData, HelpSys } from "./utils";
* @interface PostResponse
* @extends {MysResponse}
* @property {PostData} data.post 帖子数据
* @return {PostResponse}
* @returns {PostResponse}
*/
export interface PostResponse extends MysResponse {
data: {
post: PostData;
};
data: {
post: PostData
}
}
/**
@@ -49,30 +49,30 @@ export interface PostResponse extends MysResponse {
* @property {unknown} forum_rank_info 版块排行信息,可能为 null // TODO: 未知
* @property {unknown[]} link_card_list 链接卡片列表,可能为空 // TODO: 未知
* @property {NewsMeta} news_meta 咨讯元数据,可能为 null
* @return {PostData}
* @returns {PostData}
*/
export interface PostData {
post: Post;
forum: Forum;
topics: Topic[];
user: User;
self_operation: SelfOperation;
stat: PostStat;
help_sys: HelpSys | null;
cover: ImageData | null;
image_list: ImageData[];
is_official_master: boolean;
is_user_master: boolean;
hot_reply_exist: boolean;
vot_count: number;
last_modify_time: number;
recommend_type: string;
collection: unknown | null;
vod_list: unknown[];
is_block_on: boolean;
forum_rank_info: unknown | null;
link_card_list: unknown[];
news_meta: NewsMeta | null;
post: Post
forum: Forum
topics: Topic[]
user: User
self_operation: SelfOperation
stat: PostStat
help_sys: HelpSys | null
cover: ImageData | null
image_list: ImageData[]
is_official_master: boolean
is_user_master: boolean
hot_reply_exist: boolean
vot_count: number
last_modify_time: number
recommend_type: string
collection: unknown | null
vod_list: unknown[]
is_block_on: boolean
forum_rank_info: unknown | null
link_card_list: unknown[]
news_meta: NewsMeta | null
}
/**
@@ -118,49 +118,49 @@ export interface PostData {
* @property {boolean} is_showing_missing 是否显示缺失 // TODO: 未知
* @property {number} block_latest_reply_time 是否屏蔽最新回复时间 // TODO: 未知
* @property {number} selected_comment 是否选择评论 // TODO: 未知
* @return {Post}
* @returns {Post}
*/
export interface Post {
game_id: number;
post_id: string;
f_forum_id: number;
uid: string;
subject: string;
content: string;
cover: string;
view_type: number;
created_at: number;
images: string[];
post_status: {
is_top: boolean;
is_good: boolean;
is_official: boolean;
};
topic_ids: number[];
view_status: number;
max_floor: number;
is_original: number;
republish_authorization: number;
reply_time: string;
is_deleted: number;
is_interactive: boolean;
structured_content: string;
structured_content_rows: string[];
review_id: number;
is_profit: boolean;
is_in_profit: boolean;
updated_at: number;
deleted_at: number;
pre_pub_status: number;
cate_id: number;
profit_post_status: number;
audit_status: number;
meta_content: string;
is_missing: boolean;
block_reply_img: number;
is_showing_missing: boolean;
block_latest_reply_time: number;
selected_comment: number;
game_id: number
post_id: string
f_forum_id: number
uid: string
subject: string
content: string
cover: string
view_type: number
created_at: number
images: string[]
post_status: {
is_top: boolean
is_good: boolean
is_official: boolean
}
topic_ids: number[]
view_status: number
max_floor: number
is_original: number
republish_authorization: number
reply_time: string
is_deleted: number
is_interactive: boolean
structured_content: string
structured_content_rows: string[]
review_id: number
is_profit: boolean
is_in_profit: boolean
updated_at: number
deleted_at: number
pre_pub_status: number
cate_id: number
profit_post_status: number
audit_status: number
meta_content: string
is_missing: boolean
block_reply_img: number
is_showing_missing: boolean
block_latest_reply_time: number
selected_comment: number
}
/**
@@ -172,14 +172,14 @@ export interface Post {
* @property {string} icon 版块图标 URL
* @property {number} game_id 游戏 ID // 2 为原神
* @property {unknown} forum_cate 版块分类,可能为 null
* @return {Forum}
* @returns {Forum}
*/
export interface Forum {
id: number;
name: string;
icon: string;
game_id: number;
forum_cate: unknown | null;
id: number
name: string
icon: string
game_id: number
forum_cate: unknown | null
}
/**
@@ -194,17 +194,17 @@ export interface Forum {
* @property {boolean} is_interactive 是否互动
* @property {number} game_id 游戏 ID
* @property {number} content_type 内容类型
* @return {Topic}
* @returns {Topic}
*/
export interface Topic {
id: number;
name: string;
cover: string;
is_top: boolean;
is_good: boolean;
is_interactive: boolean;
game_id: number;
content_type: number;
id: number
name: string
cover: string
is_top: boolean
is_good: boolean
is_interactive: boolean
game_id: number
content_type: number
}
/**
@@ -216,14 +216,14 @@ export interface Topic {
* @property {number} like_num 点赞数
* @property {number} bookmark_num 收藏数
* @property {number} forward_num 转发数
* @return {PostStat}
* @returns {PostStat}
*/
export interface PostStat {
view_num: number;
reply_num: number;
like_num: number;
bookmark_num: number;
forward_num: number;
view_num: number
reply_num: number
like_num: number
bookmark_num: number
forward_num: number
}
/**
@@ -233,11 +233,11 @@ export interface PostStat {
* @interface PostContent
* @property {string} describe 描述
* @property {string[]} imgs 图片 URL
* @return {PostContent}
* @returns {PostContent}
*/
export interface PostContent {
describe: string;
imgs?: string[];
describe: string
imgs?: string[]
}
/**
@@ -265,36 +265,36 @@ export interface PostContent {
* @property {boolean} attributes.bold 是否加粗
* @property {string} attributes.color 颜色
* @property {string} attributes.link 链接
* @return {PostStructuredContent}
* @returns {PostStructuredContent}
*/
export interface PostStructuredContent {
insert:
| {
image?: string;
video?: string;
vod?: PostStructuredContentVod;
backup_text?: string;
lottery?: {
id: string;
toast: string;
};
fold?: {
title: string;
content: string;
};
link_card?: PostStructuredContentLinkCard;
divider?: string;
}
| string;
attributes?: {
height?: number;
width?: number;
size?: number;
ext?: string;
bold?: boolean;
color?: string;
link?: string;
};
insert:
| {
image?: string
video?: string
vod?: PostStructuredContentVod
backup_text?: string
lottery?: {
id: string
toast: string
}
fold?: {
title: string
content: string
}
link_card?: PostStructuredContentLinkCard
divider?: string
}
| string
attributes?: {
height?: number
width?: number
size?: number
ext?: string
bold?: boolean
color?: string
link?: string
}
}
/**
@@ -316,25 +316,25 @@ export interface PostStructuredContent {
* @property {number} view_num 浏览数
* @property {number} transcode_status 转码状态
* @property {number} review_status 审核状态
* @return {PostStructuredContentVod}
* @returns {PostStructuredContentVod}
*/
export interface PostStructuredContentVod {
id: number;
duration: number;
cover: string;
resolutions: {
url: string;
definition: string;
height: number;
width: number;
bitrate: number;
size: number;
format: string;
label: string;
}[];
view_num: number;
transcoding_status: number;
review_status: number;
id: number
duration: number
cover: string
resolutions: Array<{
url: string
definition: string
height: number
width: number
bitrate: number
size: number
format: string
label: string
}>
view_num: number
transcoding_status: number
review_status: number
}
/**
@@ -352,18 +352,18 @@ export interface PostStructuredContentVod {
* @property {string} price 价格
* @property {string} button_text 按钮文本
* @property {number} landing_url_type 落地链接类型 // TODO: 未知
* @return {PostStructuredContentLinkCard}
* @returns {PostStructuredContentLinkCard}
*/
export interface PostStructuredContentLinkCard {
link_type: number;
origin_url: string;
landing_url: string;
cover: string;
title: string;
card_id: string;
card_status: number;
market_price: string;
price: string;
button_text: string;
landing_url_type: number;
link_type: number
origin_url: string
landing_url: string
cover: string
title: string
card_id: string
card_status: number
market_price: string
price: string
button_text: string
landing_url_type: number
}

View File

@@ -26,26 +26,26 @@
* @property {boolean} is_follower 是否被关注
* @property {string} avatar_url 用户头像链接
* @property {string} pendant 用户挂件 URL可能为 ""
* @return {User}
* @returns {User}
*/
export interface User {
uid: string;
nickname: string;
introduce: string;
avatar: string;
gender: number;
certification: {
type: number;
label: string;
};
level_exp: {
level: number;
exp: number;
};
is_following: boolean;
is_follower: boolean;
avatar_url: string;
pendant: string;
uid: string
nickname: string
introduce: string
avatar: string
gender: number
certification: {
type: number
label: string
}
level_exp: {
level: number
exp: number
}
is_following: boolean
is_follower: boolean
avatar_url: string
pendant: string
}
/**
@@ -54,9 +54,9 @@ export interface User {
* @interface SelfOperation
* @property {number} attitude 操作类型 // TODO: 未知
* @property {boolean} is_collected 是否收藏
* @return {SelfOperation}
* @returns {SelfOperation}
*/
export interface SelfOperation {
attitude: number;
is_collected: boolean;
attitude: number
is_collected: boolean
}

View File

@@ -11,7 +11,7 @@
* @description 观测枢 content API
* @since Alpha
* @param {string} content_id 内容 ID
* @return {string} API
* @returns {string} API
*/
export const OBC_CONTENT_API =
"https://bbs.mihoyo.com/ys/obc/content/{content_id}/detail?bbs_presentation_style=no_header";
@@ -38,26 +38,26 @@ export const OBC_CONTENT_API =
* @property {string} entity_type 图片类型 // IMG_ENTITY_POST, IMG_ENTITY_UNKOWN
* @property {string} entity_id 图片 ID
* @property {boolean} is_deleted 是否已删除
* @return {ImageData}
* @returns {ImageData}
*/
export interface ImageData {
url: string;
height: number;
width: number;
format: string;
size: string;
crop: {
x: number;
y: number;
w: number;
h: number;
url: string;
} | null;
is_user_set_cover: boolean;
image_id: string;
entity_type: string;
entity_id: string;
is_deleted: boolean;
url: string
height: number
width: number
format: string
size: string
crop: {
x: number
y: number
w: number
h: number
url: string
} | null
is_user_set_cover: boolean
image_id: string
entity_type: string
entity_id: string
is_deleted: boolean
}
/**
@@ -68,10 +68,10 @@ export interface ImageData {
* @property {unknown} top_up 置顶, 可能为 null // TODO: 未知
* @property {unknown[]} top_n 置顶, 可能为空
* @property {number} answer_num 回答数
* @return {HelpSys}
* @returns {HelpSys}
*/
export interface HelpSys {
top_up: unknown | null;
top_n: unknown[];
answer_num: number;
top_up: unknown | null
top_n: unknown[]
answer_num: number
}

View File

@@ -6,27 +6,26 @@
*/
import { http } from "@tauri-apps/api";
import { CalendarResponse, CalendarData } from "../interface/calendar";
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";
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");
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

@@ -6,26 +6,25 @@
*/
import { http } from "@tauri-apps/api";
import { GachaResponse, GachaData } from "../interface/gacha";
import { type GachaResponse, type GachaData } from "../interface/gacha";
// 卡池 API
const GACHA_POOL_API =
"https://api-takumi.mihoyo.com/common/blackboard/ys_obc/v1/gacha_pool?app_sn=ys_obc";
const GACHA_POOL_API = "https://api-takumi.mihoyo.com/common/blackboard/ys_obc/v1/gacha_pool?app_sn=ys_obc";
/**
* @description 获取卡池信息
* @since Alpha
* @return {Promise<GachaData[]>}
*/
export async function getGachaData(): Promise<GachaData[]> {
return await http
.fetch<GachaResponse>(GACHA_POOL_API, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
})
.then(res => {
return res.data.data.list;
});
export async function getGachaData (): Promise<GachaData[]> {
return await http
.fetch<GachaResponse>(GACHA_POOL_API, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
})
.then((res) => {
return res.data.data.list;
});
}

View File

@@ -2,31 +2,30 @@
* @file plugins Mys interface lottery.ts
* @description Mys 插件抽奖接口
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.1.1
* @since Alpha v0.1.2
*/
import { http } from "@tauri-apps/api";
import { LotteryResponse, LotteryData } from "../interface/lottery";
import { type LotteryResponse, type LotteryData } from "../interface/lottery";
// 抽奖 API
const LOTTERY_API =
"https://bbs-api.miyoushe.com/painter/wapi/lottery/user/show?gids=2&id={lottery_id}";
const LOTTERY_API = "https://bbs-api.miyoushe.com/painter/wapi/lottery/user/show?gids=2&id={lottery_id}";
/**
* @description 获取抽奖信息
* @since Alpha v0.1.1
* @param {string} lottery_id 抽奖 ID
* @since Alpha v0.1.2
* @param {string} lotteryId 抽奖 ID
* @return {Promise<LotteryData>}
*/
export async function getLotteryData(lottery_id: string): Promise<LotteryData> {
return await http
.fetch<LotteryResponse>(LOTTERY_API.replace("{lottery_id}", lottery_id), {
method: "GET",
headers: {
"Content-Type": "application/json",
},
})
.then(res => {
return res.data.data.show_lottery;
});
export async function getLotteryData (lotteryId: string): Promise<LotteryData> {
return await http
.fetch<LotteryResponse>(LOTTERY_API.replace("{lottery_id}", lotteryId), {
method: "GET",
headers: {
"Content-Type": "application/json",
},
})
.then((res) => {
return res.data.data.show_lottery;
});
}

View File

@@ -6,7 +6,7 @@
*/
import { http } from "@tauri-apps/api";
import { NewsData, NewsResponse } from "../interface/news";
import { type NewsData, type NewsResponse } from "../interface/news";
// 咨讯 API
const NEWS_LIST_API =
@@ -22,67 +22,61 @@ const NEWS_LIST_API =
* @return {NewsType}
*/
enum NewsType {
NOTICE = "1",
ACTIVITY = "2",
NEWS = "3",
NOTICE = "1",
ACTIVITY = "2",
NEWS = "3",
}
// todo: 考虑使用泛型
/**
* @description 获取 Notice 列表
* @since Alpha v0.1.2
* @param {string} gid gid: 1 为崩坏3 2 为原神3 为崩坏24 为未定事件簿5 为大别野6 为崩坏星穹铁道8 为绝区零
* @param {number} page_size 返回数量
* @param {number} last_id 上一次请求的最后一条数据的 id
* @param {number} pageSize 返回数量
* @param {number} lastId 上一次请求的最后一条数据的 id
* @return {Promise<NewsData>}
*/
export async function getNoticeList(
gid: string = "2",
page_size: number = 20,
last_id: number = 0
): Promise<NewsData> {
const url = NEWS_LIST_API.replace("{page_size}", page_size.toString())
.replace("{gid}", gid)
.replace("{news_type}", NewsType.NOTICE)
.replace("{last_id}", last_id.toString());
return await http.fetch<NewsResponse>(url).then(res => res.data.data);
export async function getNoticeList (gid: string = "2", pageSize: number = 20, lastId: number = 0): Promise<NewsData> {
const url = NEWS_LIST_API.replace("{page_size}", pageSize.toString())
.replace("{gid}", gid)
.replace("{news_type}", NewsType.NOTICE)
.replace("{last_id}", lastId.toString());
return await http.fetch<NewsResponse>(url).then((res) => res.data.data);
}
/**
* @description 获取 Activity 列表
* @since Alpha v0.1.2
* @param {string} gid gid: 1 为崩坏3 2 为原神3 为崩坏24 为未定事件簿5 为大别野6 为崩坏星穹铁道8 为绝区零
* @param {number} page_size 返回数量
* @param {number} last_id 上一次请求的最后一条数据的 id
* @param {number} pageSize 返回数量
* @param {number} lastId 上一次请求的最后一条数据的 id
* @return {Promise<NewsData>}
*/
export async function getActivityList(
gid: string = "2",
page_size: number = 20,
last_id: number = 0
export async function getActivityList (
gid: string = "2",
pageSize: number = 20,
lastId: number = 0,
): Promise<NewsData> {
const url = NEWS_LIST_API.replace("{page_size}", page_size.toString())
.replace("{gid}", gid)
.replace("{news_type}", NewsType.ACTIVITY)
.replace("{last_id}", last_id.toString());
return await http.fetch<NewsResponse>(url).then(res => res.data.data);
const url = NEWS_LIST_API.replace("{page_size}", pageSize.toString())
.replace("{gid}", gid)
.replace("{news_type}", NewsType.ACTIVITY)
.replace("{last_id}", lastId.toString());
return await http.fetch<NewsResponse>(url).then((res) => res.data.data);
}
/**
* @description 获取 News 列表
* @since Alpha v0.1.2
* @param {string} gid gid: 1 为崩坏3 2 为原神3 为崩坏24 为未定事件簿5 为大别野6 为崩坏星穹铁道8 为绝区零
* @param {number} page_size 返回数量
* @param {number} last_id 上一次请求的最后一条数据的 id
* @param {number} pageSize 返回数量
* @param {number} lastId 上一次请求的最后一条数据的 id
* @return {Promise<NewsData>}
*/
export async function getNewsList(
gid: string = "2",
page_size: number = 20,
last_id: number = 0
): Promise<NewsData> {
const url = NEWS_LIST_API.replace("{page_size}", page_size.toString())
.replace("{gid}", gid)
.replace("{news_type}", NewsType.NEWS)
.replace("{last_id}", last_id.toString());
return await http.fetch<NewsResponse>(url).then(res => res.data.data);
export async function getNewsList (gid: string = "2", pageSize: number = 20, lastId: number = 0): Promise<NewsData> {
const url = NEWS_LIST_API.replace("{page_size}", pageSize.toString())
.replace("{gid}", gid)
.replace("{news_type}", NewsType.NEWS)
.replace("{last_id}", lastId.toString());
return await http.fetch<NewsResponse>(url).then((res) => res.data.data);
}

View File

@@ -2,32 +2,31 @@
* @file plugins Mys request position.ts
* @description Mys 插件热点追踪请求
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.1.1
* @since Alpha v0.1.2
*/
import { http } from "@tauri-apps/api";
import { PositionResponse, PositionData, PositionObc } from "../interface/position";
import { type PositionResponse, type PositionData } 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";
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[]);
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);
}

View File

@@ -6,7 +6,7 @@
*/
import { http } from "@tauri-apps/api";
import { PostResponse, PostData } from "../interface/post";
import { type PostResponse, type PostData } from "../interface/post";
// 帖子 API
const POST_API = "https://bbs-api.mihoyo.com/post/wapi/getPostFull?post_id={post_id}";
@@ -15,19 +15,19 @@ const POST_REFERER = "https://bbs.mihoyo.com/";
/**
* @description 获取帖子信息
* @since Alpha v0.1.2
* @param {number} post_id 帖子 ID
* @param {number} postId 帖子 ID
* @return {Promise<PostData>}
*/
export async function getPostData(post_id: number): Promise<PostData> {
return await http
.fetch<PostResponse>(POST_API.replace("{post_id}", post_id.toString()), {
method: "GET",
headers: {
"Content-Type": "application/json",
Referer: POST_REFERER,
},
})
.then(res => {
return res.data.data.post;
});
export async function getPostData (postId: number): Promise<PostData> {
return await http
.fetch<PostResponse>(POST_API.replace("{post_id}", postId.toString()), {
method: "GET",
headers: {
"Content-Type": "application/json",
Referer: POST_REFERER,
},
})
.then((res) => {
return res.data.data.post;
});
}

View File

@@ -5,27 +5,27 @@
* @since Alpha v0.1.1
*/
import { CalendarData, CalendarCard } from "../interface/calendar";
import { type CalendarData, type CalendarCard } from "../interface/calendar";
/**
* @description 将日历数据转换为卡片数据
* @since Alpha v0.1.1
* @param {CalendarData[]} calendarData 日历数据
* @return {CalendarCard[]}
* @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;
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;
}

View File

@@ -6,60 +6,60 @@
*/
import { getPostData } from "../request/post";
import { GachaCard, GachaData } from "../interface/gacha";
import { Map } from "../../../interface/Base";
import { type GachaCard, type GachaData } from "../interface/gacha";
import { type Map } from "../../../interface/Base";
/**
* @description 根据卡池信息转为渲染用的卡池信息
* @since Alpha v0.1.2
* @param {GachaData[]} gachaData 卡池信息
* @param {Map<string>} poolCover 卡池封面
* @return {Promise<GachaCard[]>}
* @returns {Promise<GachaCard[]>}
*/
export async function getGachaCard(
gachaData: GachaData[],
poolCover: Map<string> | undefined = undefined
export async function getGachaCard (
gachaData: GachaData[],
poolCover: Map<string> | undefined = undefined,
): Promise<GachaCard[]> {
const gachaCard: GachaCard[] = [];
await Promise.allSettled(
gachaData.map(async (data: GachaData) => {
let cover = "/source/UI/empty.webp";
const post_id: number | undefined = Number(data.activity_url.split("/").pop()) || undefined;
if (post_id === undefined || isNaN(post_id)) {
throw new Error("无法获取帖子 ID");
}
if (poolCover !== undefined) {
cover = poolCover[post_id];
} else {
try {
await console.log("调用 getPostData");
const post = await getPostData(post_id);
cover = post.cover?.url || post.post.images[0];
} catch (error) {
await console.error(error);
}
}
return gachaCard.push({
title: data.title,
subtitle: data.content_before_act,
cover: cover,
post_id: post_id,
characters: data.pool.map(character => ({
icon: character.icon,
url: character.url,
})),
voice: {
icon: data.voice_icon,
url: data.voice_url,
},
time: {
start: data.start_time,
start_stamp: new Date(data.start_time).getTime(),
end: data.end_time,
end_stamp: new Date(data.end_time).getTime(),
},
});
})
);
return gachaCard;
const gachaCard: GachaCard[] = [];
await Promise.allSettled(
gachaData.map(async (data: GachaData) => {
let cover = "/source/UI/empty.webp";
const postId: number | undefined = Number(data.activity_url.split("/").pop()) || undefined;
if (postId === undefined || isNaN(postId)) {
throw new Error("无法获取帖子 ID");
}
if (poolCover !== undefined) {
cover = poolCover[postId];
} else {
try {
console.log("调用 getPostData");
const post = await getPostData(postId);
cover = post.cover?.url ?? post.post.images[0];
} catch (error) {
console.error(error);
}
}
return gachaCard.push({
title: data.title,
subtitle: data.content_before_act,
cover,
post_id: postId,
characters: data.pool.map((character) => ({
icon: character.icon,
url: character.url,
})),
voice: {
icon: data.voice_icon,
url: data.voice_url,
},
time: {
start: data.start_time,
start_stamp: new Date(data.start_time).getTime(),
end: data.end_time,
end_stamp: new Date(data.end_time).getTime(),
},
});
}),
);
return gachaCard;
}

View File

@@ -5,38 +5,38 @@
* @since Alpha v0.1.1
*/
import { LotteryData, LotteryCard, LotteryRewardCard, LotteryReward } from "../interface/lottery";
import { type LotteryData, type LotteryCard, type LotteryRewardCard, type LotteryReward } from "../interface/lottery";
/**
* @description 根据抽奖信息转为渲染用的抽奖信息
* @since Alpha v0.1.1
* @param {LotteryData} lotteryData 抽奖信息
* @return {LotteryCard}
* @returns {LotteryCard}
*/
export function getLotteryCard(lotteryData: LotteryData): LotteryCard {
return {
id: lotteryData.id,
participantWay: lotteryData.participant_way,
status: lotteryData.status,
creator: lotteryData.creator,
drawTime: lotteryData.draw_time,
rewards: lotteryData.user_rewards.map(reward => {
return getLotteryRewardCard(reward);
}),
};
export function getLotteryCard (lotteryData: LotteryData): LotteryCard {
return {
id: lotteryData.id,
participantWay: lotteryData.participant_way,
status: lotteryData.status,
creator: lotteryData.creator,
drawTime: lotteryData.draw_time,
rewards: lotteryData.user_rewards.map((reward) => {
return getLotteryRewardCard(reward);
}),
};
}
/**
* @description 根据抽奖奖励信息转为渲染用的抽奖奖励信息
* @since Alpha v0.1.1
* @param {LotteryReward} lotteryReward 抽奖奖励信息
* @return {LotteryRewardCard}
* @returns {LotteryRewardCard}
*/
export function getLotteryRewardCard(lotteryReward: LotteryReward): LotteryRewardCard {
return {
rewardName: lotteryReward.reward_name,
winnerNumber: lotteryReward.winner_number,
scheduledWinnerNumber: lotteryReward.scheduled_winner_number,
users: lotteryReward.users,
};
export function getLotteryRewardCard (lotteryReward: LotteryReward): LotteryRewardCard {
return {
rewardName: lotteryReward.reward_name,
winnerNumber: lotteryReward.winner_number,
scheduledWinnerNumber: lotteryReward.scheduled_winner_number,
users: lotteryReward.users,
};
}

View File

@@ -5,7 +5,7 @@
* @since Alpha v0.1.2
*/
import { NewsData, NewsItem, NewsCard, ActivityStatus } from "../interface/news";
import { type NewsData, type NewsItem, type NewsCard, type ActivityStatus } from "../interface/news";
// 默认封面图
const defaultCover = "/source/UI/defaultCover.webp";
@@ -17,103 +17,103 @@ const defaultCover = "/source/UI/defaultCover.webp";
* @property {ActivityStatus} STARTED 进行中
* @property {ActivityStatus} FINISHED 已结束
* @property {ActivityStatus} SELECTION 评选中
* @return {EnumStatus}
* @returns {EnumStatus}
*/
const EnumStatus = {
STARTED: {
status: "进行中",
colorCss: "#1EE2BA !important",
},
FINISHED: {
status: "已结束",
colorCss: "#C0C5C8 !important",
},
SELECTION: {
status: "评选中",
colorCss: "#FF983B !important",
},
UNKNOWN: {
status: "未知",
colorCss: "#3C3F41 !important",
},
STARTED: {
status: "进行中",
colorCss: "#1EE2BA !important",
},
FINISHED: {
status: "已结束",
colorCss: "#C0C5C8 !important",
},
SELECTION: {
status: "评选中",
colorCss: "#FF983B !important",
},
UNKNOWN: {
status: "未知",
colorCss: "#3C3F41 !important",
},
};
/**
* @description 获取活动状态
* @since Alpha
* @param {number} status 活动状态码
* @return {string}
* @returns {string}
*/
export function getActivityStatus(status: number): ActivityStatus {
switch (status) {
case 1:
return EnumStatus.STARTED;
case 2:
return EnumStatus.SELECTION;
case 3:
return EnumStatus.FINISHED;
default:
return EnumStatus.UNKNOWN;
}
export function getActivityStatus (status: number): ActivityStatus {
switch (status) {
case 1:
return EnumStatus.STARTED;
case 2:
return EnumStatus.SELECTION;
case 3:
return EnumStatus.FINISHED;
default:
return EnumStatus.UNKNOWN;
}
}
/**
* @description 获取渲染用公告数据
* @since Alpha
* @since Alpha v0.1.2
* @param {NewsData} noticeData 公告数据
* @return {NewsCard[]}
* @returns {NewsCard[]}
*/
export function getNoticeCard(noticeData: NewsData): NewsCard[] {
const noticeCard: NewsCard[] = [];
noticeData.list.map((item: NewsItem) => {
noticeCard.push({
title: item.post.subject,
cover: item.cover?.url || item.post.cover || item.post.images[0] || defaultCover,
post_id: Number(item.post.post_id),
subtitle: item.post.post_id,
});
});
return noticeCard;
export function getNoticeCard (noticeData: NewsData): NewsCard[] {
const noticeCard: NewsCard[] = [];
noticeData.list.map((item: NewsItem) => {
return noticeCard.push({
title: item.post.subject,
cover: item.cover?.url || item.post.cover || item.post.images[0] || defaultCover,
post_id: Number(item.post.post_id),
subtitle: item.post.post_id,
});
});
return noticeCard;
}
/**
* @description 获取渲染用活动数据
* @since Alpha
* @since Alpha v0.1.2
* @param {NewsData} activityData 活动数据
* @return {NewsCard[]}
* @returns {NewsCard[]}
*/
export function getActivityCard(activityData: NewsData): NewsCard[] {
const activityCard: NewsCard[] = [];
activityData.list.map((item: NewsItem) => {
const start_time = new Date(Number(item.news_meta.start_at_sec) * 1000).toLocaleDateString();
const end_time = new Date(Number(item.news_meta.end_at_sec) * 1000).toLocaleDateString();
const status_info = getActivityStatus(item.news_meta.activity_status);
activityCard.push({
title: item.post.subject,
cover: item.cover?.url || item.post.cover || item.post.images[0] || defaultCover,
post_id: Number(item.post.post_id),
subtitle: `${start_time} - ${end_time}`,
status: status_info,
});
});
return activityCard;
export function getActivityCard (activityData: NewsData): NewsCard[] {
const activityCard: NewsCard[] = [];
activityData.list.map((item: NewsItem) => {
const startTime = new Date(Number(item.news_meta.start_at_sec) * 1000).toLocaleDateString();
const endTime = new Date(Number(item.news_meta.end_at_sec) * 1000).toLocaleDateString();
const statusInfo = getActivityStatus(item.news_meta.activity_status);
return activityCard.push({
title: item.post.subject,
cover: item.cover?.url || item.post.cover || item.post.images[0] || defaultCover,
post_id: Number(item.post.post_id),
subtitle: `${startTime} - ${endTime}`,
status: statusInfo,
});
});
return activityCard;
}
/**
* @description 获取渲染用新闻数据
* @since Alpha
* @since Alpha v0.1.2
* @param {NewsData} newsData 新闻数据
* @return {NewsCard[]}
* @returns {NewsCard[]}
*/
export function getNewsCard(newsData: NewsData): NewsCard[] {
const newsCard: NewsCard[] = [];
newsData.list.map((item: NewsItem) => {
newsCard.push({
title: item.post.subject,
cover: item.cover?.url || item.post.cover || item.post.images[0] || defaultCover,
post_id: Number(item.post.post_id),
subtitle: item.post.post_id,
});
});
return newsCard;
export function getNewsCard (newsData: NewsData): NewsCard[] {
const newsCard: NewsCard[] = [];
newsData.list.map((item: NewsItem) => {
return newsCard.push({
title: item.post.subject,
cover: item.cover?.url || item.post.cover || item.post.images[0] || defaultCover,
post_id: Number(item.post.post_id),
subtitle: item.post.post_id,
});
});
return newsCard;
}

View File

@@ -4,7 +4,7 @@
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.1.2
*/
import { PostContent, PostData, PostStructuredContent } from "../interface/post";
import { type PostData, type PostStructuredContent } from "../interface/post";
/**
* @description 检测链接是否是米游社帖子
@@ -12,47 +12,61 @@ import { PostContent, PostData, PostStructuredContent } from "../interface/post"
* @param {string} url 链接
* @returns {boolean} 是否是米游社帖子
*/
export function IsMysPost(url: string): boolean {
const regBBS = /^https:\/\/bbs\.mihoyo\.com\/\w+\/article\/\d+$/;
const regMYS = /^https:\/\/www\.miyoushe\.com\/\w+\/article\/\d+$/;
return regBBS.test(url) || regMYS.test(url);
export function IsMysPost (url: string): boolean {
const regBBS = /^https:\/\/bbs\.mihoyo\.com\/\w+\/article\/\d+$/;
const regMYS = /^https:\/\/www\.miyoushe\.com\/\w+\/article\/\d+$/;
return regBBS.test(url) || regMYS.test(url);
}
/**
* @description 根据 url 获取帖子 id
* @since Alpha v0.1.2
* @param {string} url 链接
* @returns {string} 帖子 id
*/
export function getPostId (url: string): string {
const postId: string | undefined = url.split("/").pop();
if (postId === undefined) {
throw new Error("无法获取帖子 id");
}
return postId;
}
/**
* @description 解析用户帖子,将其转换为 PostStructContent
* @since Alpha v0.1.1
* @since Alpha v0.1.2
* @see PostContent
* @param {string} content 帖子内容
* @returns {string} 解析后的内容
*/
export function contentParser(content: string): string {
const data = JSON.parse(content);
const result: PostStructuredContent[] = [];
// 遍历 data 属性,值
Object.keys(data).forEach(key => {
switch (key) {
case "describe":
result.push({
insert: data.describe,
});
break;
case "imgs":
for (const image of data.imgs) {
result.push({
insert: {
image: image,
},
});
}
break;
default:
// 如果是其他属性,就直接插入
result.push({
insert: JSON.stringify(data[key]),
});
}
});
return JSON.stringify(result);
export function contentParser (content: string): string {
const data = JSON.parse(content);
const result: PostStructuredContent[] = [];
// 遍历 data 属性,值
Object.keys(data).forEach((key) => {
switch (key) {
case "describe":
result.push({
insert: data.describe,
});
break;
case "imgs":
for (const image of data.imgs) {
result.push({
insert: {
image,
},
});
}
break;
default:
// 如果是其他属性,就直接插入
result.push({
insert: JSON.stringify(data[key]),
});
}
});
return JSON.stringify(result);
}
/**
@@ -62,25 +76,25 @@ export function contentParser(content: string): string {
* @description 为了安全考虑,不会解析所有的属性,只会解析几个常用的属性
* @returns {string} 解析后的HTML可作为 v-html 使用
*/
export function PostParser(post: PostData): string {
const postContent = post.post.content;
let parserData;
if (postContent.startsWith("<")) {
parserData = post.post.structured_content;
} else {
try {
parserData = contentParser(post.post.content);
} catch (error) {
parserData = post.post.structured_content;
}
}
let jsonData: PostStructuredContent[] = JSON.parse(parserData);
const doc = document.createElement("div");
jsonData.forEach((item: any) => {
const parsed = ParserTransfer(item);
doc.appendChild(parsed);
});
return doc.innerHTML;
export function PostParser (post: PostData): string {
const postContent = post.post.content;
let parserData;
if (postContent.startsWith("<")) {
parserData = post.post.structured_content;
} else {
try {
parserData = contentParser(post.post.content);
} catch (error) {
parserData = post.post.structured_content;
}
}
const jsonData: PostStructuredContent[] = JSON.parse(parserData);
const doc = document.createElement("div");
jsonData.forEach((item: any) => {
const parsed = ParserTransfer(item);
doc.appendChild(parsed);
});
return doc.innerHTML;
}
/**
@@ -89,24 +103,24 @@ export function PostParser(post: PostData): string {
* @param {PostStructuredContent} data Mys数据
* @returns {HTMLDivElement | HTMLSpanElement} 解析后的中转
*/
function ParserTransfer(data: PostStructuredContent): HTMLDivElement | HTMLSpanElement {
if (typeof data.insert === "string") {
return TextParser(data);
} else if (data.insert.image) {
return ImageParser(data);
} else if (data.insert.vod) {
return VideoParser(data);
} else if (data.insert.video) {
return VideoParser(data);
} else if (data.insert.backup_text) {
return BackupTextParser(data);
} else if (data.insert.link_card) {
return LinkCardParser(data);
} else if (data.insert.divider) {
return DividerParser(data);
} else {
return UnknownParser(data);
}
function ParserTransfer (data: PostStructuredContent): HTMLDivElement | HTMLSpanElement {
if (typeof data.insert === "string") {
return TextParser(data);
} else if (data.insert.image) {
return ImageParser(data);
} else if (data.insert.vod) {
return VideoParser(data);
} else if (data.insert.video) {
return VideoParser(data);
} else if (data.insert.backup_text) {
return BackupTextParser(data);
} else if (data.insert.link_card) {
return LinkCardParser(data);
} else if (data.insert.divider) {
return DividerParser(data);
} else {
return UnknownParser(data);
}
}
/**
@@ -115,17 +129,17 @@ function ParserTransfer(data: PostStructuredContent): HTMLDivElement | HTMLSpanE
* @param {PostStructuredContent} data Mys数据
* @returns {HTMLDivElement} 解析后的未知数据
*/
function UnknownParser(data: PostStructuredContent): HTMLDivElement {
// 创建 div
const div = document.createElement("div");
div.classList.add("mys-post-unknown");
// 创建 code将数据放入 code
const code = document.createElement("code");
code.innerText = JSON.stringify(data);
// 插入 code
div.appendChild(code);
// 返回 div
return div;
function UnknownParser (data: PostStructuredContent): HTMLDivElement {
// 创建 div
const div = document.createElement("div");
div.classList.add("mys-post-unknown");
// 创建 code将数据放入 code
const code = document.createElement("code");
code.innerText = JSON.stringify(data);
// 插入 code
div.appendChild(code);
// 返回 div
return div;
}
/**
@@ -134,65 +148,66 @@ function UnknownParser(data: PostStructuredContent): HTMLDivElement {
* @param {PostStructuredContent} data Mys数据
* @returns {HTMLSpanElement} 解析后的文本
*/
function TextParser(data: PostStructuredContent): HTMLSpanElement {
// 检查数据
if (typeof data.insert !== "string") {
throw new Error("data.insert is not a string");
}
// 创建文本
const text = document.createElement("span");
// 设置文本属性
if (data.attributes) {
if (data.attributes.bold) text.style.fontWeight = "bold";
if (data.attributes.color) text.style.color = data.attributes.color;
if (data.attributes.link) {
return LinkTextParser(data);
}
}
// 添加 class
text.classList.add("mys-post-span");
// 设置 span 内容
text.innerText = data.insert;
// 返回文本
return text;
function TextParser (data: PostStructuredContent): HTMLSpanElement {
// 检查数据
if (typeof data.insert !== "string") {
throw new Error("data.insert is not a string");
}
// 创建文本
const text = document.createElement("span");
// 设置文本属性
if (data.attributes) {
if (data.attributes.bold) text.style.fontWeight = "bold";
if (data.attributes.color) text.style.color = data.attributes.color;
if (data.attributes.link) {
return LinkTextParser(data);
}
}
// 添加 class
text.classList.add("mys-post-span");
// 设置 span 内容
text.innerText = data.insert;
// 返回文本
return text;
}
/**
* @description 解析链接
* @since Alpha v0.1.1
* @since Alpha v0.1.2
* @param {PostStructuredContent} data Mys数据
* @returns {HTMLSpanElement} 解析后的链接
*/
function LinkTextParser(data: PostStructuredContent): HTMLSpanElement {
// 检查数据
if (typeof data.insert !== "string") {
throw new Error("data.insert is not a string");
}
if (!data.attributes) {
throw new Error("data.attributes is not defined");
}
if (!data.attributes.link) {
throw new Error("data.attributes.link is not defined");
}
// 创建图标
const icon = document.createElement("i");
icon.classList.add("mdi", "mdi-link-variant");
// 创建链接
const link = document.createElement("a");
const link_url = data.attributes.link;
link.classList.add("mys-post-link");
if (IsMysPost(link_url)) {
link.href = "/post_detail/" + link_url.split("/").pop();
link.target = "_self";
} else {
link.href = link_url;
link.target = "view_window";
}
link.innerText = data.insert;
// 插入图标作为链接前缀
link.prepend(icon);
// 返回链接
return link;
function LinkTextParser (data: PostStructuredContent): HTMLSpanElement {
// 检查数据
if (typeof data.insert !== "string") {
throw new Error("data.insert is not a string");
}
if (!data.attributes) {
throw new Error("data.attributes is not defined");
}
if (!data.attributes.link) {
throw new Error("data.attributes.link is not defined");
}
// 创建图标
const icon = document.createElement("i");
icon.classList.add("mdi", "mdi-link-variant");
// 创建链接
const link = document.createElement("a");
const linkUrl = data.attributes.link;
link.classList.add("mys-post-link");
if (IsMysPost(linkUrl)) {
const postId = getPostId(linkUrl);
link.href = `/post_detail/${postId}`;
link.target = "_self";
} else {
link.href = linkUrl;
link.target = "view_window";
}
link.innerText = data.insert;
// 插入图标作为链接前缀
link.prepend(icon);
// 返回链接
return link;
}
/**
@@ -201,39 +216,38 @@ function LinkTextParser(data: PostStructuredContent): HTMLSpanElement {
* @param {PostStructuredContent} data Mys数据
* @returns {HTMLDivElement} 解析后的分割线
*/
function DividerParser(data: PostStructuredContent): HTMLDivElement {
// 数据检查
if (typeof data.insert === "string") {
throw new Error("data.insert is a string");
}
if (!data.insert.divider) {
throw new Error("data.insert.divider is not defined");
}
// 创建分割线
const div = document.createElement("div");
div.classList.add("mys-post-divider");
// 创建 img
const img = document.createElement("img");
if (data.insert.divider === "line_1") {
img.src =
function DividerParser (data: PostStructuredContent): HTMLDivElement {
// 数据检查
if (typeof data.insert === "string") {
throw new Error("data.insert is a string");
}
if (!data.insert.divider) {
throw new Error("data.insert.divider is not defined");
}
// 创建分割线
const div = document.createElement("div");
div.classList.add("mys-post-divider");
// 创建 img
const img = document.createElement("img");
if (data.insert.divider === "line_1") {
img.src =
"https://mihoyo-community-web.oss-cn-shanghai.aliyuncs.com/upload/2021/01/05/40eb5281cb24042bf34a9f1bcc61eaf5.png";
} else if (data.insert.divider === "line_2") {
img.src =
} else if (data.insert.divider === "line_2") {
img.src =
"https://mihoyo-community-web.oss-cn-shanghai.aliyuncs.com/upload/2021/01/05/477d4c535e965bec1791203aecdfa8e6.png";
} else if (data.insert.divider === "line_3") {
img.src =
} else if (data.insert.divider === "line_3") {
img.src =
"https://mihoyo-community-web.oss-cn-shanghai.aliyuncs.com/upload/2021/01/05/e7047588e912d60ff87a975e037c7606.png";
} else if (data.insert.divider === "line_4") {
img.src =
"https://mihoyo-community-web.oss-cn-shanghai.aliyuncs.com/upload/2022/07/13/line_4.png";
} else {
console.error("Unknown divider type", data);
return UnknownParser(data);
}
// 插入 img
div.appendChild(img);
// 返回分割线
return div;
} else if (data.insert.divider === "line_4") {
img.src = "https://mihoyo-community-web.oss-cn-shanghai.aliyuncs.com/upload/2022/07/13/line_4.png";
} else {
console.error("Unknown divider type", data);
return UnknownParser(data);
}
// 插入 img
div.appendChild(img);
// 返回分割线
return div;
}
/**
@@ -242,35 +256,35 @@ function DividerParser(data: PostStructuredContent): HTMLDivElement {
* @param {PostStructuredContent} data Mys数据
* @returns {HTMLDivElement} 解析后的图片
*/
function ImageParser(data: PostStructuredContent): HTMLDivElement {
// 检查数据
if (typeof data.insert === "string") {
throw new Error("data.insert is a string");
}
if (!data.insert.image) {
throw new Error("data.insert.image is not defined");
}
// if (!data.attributes) {
// throw new Error("data.attributes is not defined");
// }
// if (!data.attributes.width) {
// throw new Error("data.attributes.width is not defined");
// }
// if (!data.attributes.height) {
// throw new Error("data.attributes.height is not defined");
// }
const div = document.createElement("div");
// 创建图片
const img = document.createElement("img");
img.src = data.insert.image;
// 添加 class
img.classList.add("mys-post-img");
// 插入图片
div.appendChild(img);
// 添加 class
div.classList.add("mys-post-div");
// 返回 div
return div;
function ImageParser (data: PostStructuredContent): HTMLDivElement {
// 检查数据
if (typeof data.insert === "string") {
throw new Error("data.insert is a string");
}
if (!data.insert.image) {
throw new Error("data.insert.image is not defined");
}
// if (!data.attributes) {
// throw new Error("data.attributes is not defined");
// }
// if (!data.attributes.width) {
// throw new Error("data.attributes.width is not defined");
// }
// if (!data.attributes.height) {
// throw new Error("data.attributes.height is not defined");
// }
const div = document.createElement("div");
// 创建图片
const img = document.createElement("img");
img.src = data.insert.image;
// 添加 class
img.classList.add("mys-post-img");
// 插入图片
div.appendChild(img);
// 添加 class
div.classList.add("mys-post-div");
// 返回 div
return div;
}
/**
@@ -279,48 +293,48 @@ function ImageParser(data: PostStructuredContent): HTMLDivElement {
* @param {PostStructuredContent} data Mys数据
* @returns {HTMLDivElement} 解析后的视频
*/
function VideoParser(data: PostStructuredContent): HTMLDivElement {
// 检查数据
if (typeof data.insert === "string") {
throw new Error("data.insert is a string");
}
if (!data.insert.vod && !data.insert.video) {
throw new Error("data.insert.vod is not defined");
}
// 创建 div
const div = document.createElement("div");
div.classList.add("mys-post-div");
if (data.insert.vod) {
// 创建视频
const video = document.createElement("video");
video.classList.add("mys-post-vod");
// 获取 resolutions中size最大的视频
const resolution = data.insert.vod.resolutions.reduce((prev: any, curr: any) => {
if (prev.size > curr.size) return prev;
return curr;
});
video.poster = data.insert.vod.cover; // 设置封面
video.controls = true; // 设置 controls
// 添加 source
const source = document.createElement("source");
source.src = resolution.url;
source.type = resolution.format === ".mp4" ? "video/mp4" : "video/webm";
// 插入 source
video.appendChild(source);
// 插入 video
div.appendChild(video);
} else if (data.insert.video) {
// 创建 iframe
const video = document.createElement("iframe");
video.classList.add("mys-post-iframe");
// 设置 iframe 属性
video.src = data.insert.video;
video.allowFullscreen = true;
video.sandbox.add("allow-top-navigation", "allow-same-origin", "allow-forms", "allow-scripts");
// 插入 video
div.appendChild(video);
}
return div;
function VideoParser (data: PostStructuredContent): HTMLDivElement {
// 检查数据
if (typeof data.insert === "string") {
throw new Error("data.insert is a string");
}
if (!data.insert.vod && !data.insert.video) {
throw new Error("data.insert.vod is not defined");
}
// 创建 div
const div = document.createElement("div");
div.classList.add("mys-post-div");
if (data.insert.vod) {
// 创建视频
const video = document.createElement("video");
video.classList.add("mys-post-vod");
// 获取 resolutions中size最大的视频
const resolution = data.insert.vod.resolutions.reduce((prev: any, curr: any) => {
if (prev.size > curr.size) return prev;
return curr;
});
video.poster = data.insert.vod.cover; // 设置封面
video.controls = true; // 设置 controls
// 添加 source
const source = document.createElement("source");
source.src = resolution.url;
source.type = resolution.format === ".mp4" ? "video/mp4" : "video/webm";
// 插入 source
video.appendChild(source);
// 插入 video
div.appendChild(video);
} else if (data.insert.video) {
// 创建 iframe
const video = document.createElement("iframe");
video.classList.add("mys-post-iframe");
// 设置 iframe 属性
video.src = data.insert.video;
video.allowFullscreen = true;
video.sandbox.add("allow-top-navigation", "allow-same-origin", "allow-forms", "allow-scripts");
// 插入 video
div.appendChild(video);
}
return div;
}
/**
@@ -329,44 +343,44 @@ function VideoParser(data: PostStructuredContent): HTMLDivElement {
* @param {PostStructuredContent} data Mys数据
* @returns {HTMLDivElement} 解析后的折叠内容
*/
function BackupTextParser(data: PostStructuredContent): HTMLDivElement {
// 检查数据
if (typeof data.insert === "string") {
throw new Error("data.insert is a string");
}
if (data.insert.backup_text === "[抽奖]") {
return LotteryParser(data);
}
if (!data.insert.fold) {
throw new Error("data.insert.fold is not defined");
}
// 转换
const titleJson: PostStructuredContent[] = JSON.parse(data.insert.fold.title);
const contentJson: PostStructuredContent[] = JSON.parse(data.insert.fold.content);
// 创建 div
const div = document.createElement("div");
div.classList.add("mys-post-div");
// 创建折叠内容
const details = document.createElement("details");
details.classList.add("mys-post-details");
// 创建标题
const title = document.createElement("summary");
// 解析标题
titleJson.forEach(item => {
const parsed = ParserTransfer(item);
title.appendChild(parsed);
});
// 创建内容
const content = document.createElement("div");
contentJson.forEach(item => {
const parsed = ParserTransfer(item);
content.appendChild(parsed);
});
details.appendChild(title);
details.appendChild(content);
div.appendChild(details);
// 返回 div
return div;
function BackupTextParser (data: PostStructuredContent): HTMLDivElement {
// 检查数据
if (typeof data.insert === "string") {
throw new Error("data.insert is a string");
}
if (data.insert.backup_text === "[抽奖]") {
return LotteryParser(data);
}
if (!data.insert.fold) {
throw new Error("data.insert.fold is not defined");
}
// 转换
const titleJson: PostStructuredContent[] = JSON.parse(data.insert.fold.title);
const contentJson: PostStructuredContent[] = JSON.parse(data.insert.fold.content);
// 创建 div
const div = document.createElement("div");
div.classList.add("mys-post-div");
// 创建折叠内容
const details = document.createElement("details");
details.classList.add("mys-post-details");
// 创建标题
const title = document.createElement("summary");
// 解析标题
titleJson.forEach((item) => {
const parsed = ParserTransfer(item);
title.appendChild(parsed);
});
// 创建内容
const content = document.createElement("div");
contentJson.forEach((item) => {
const parsed = ParserTransfer(item);
content.appendChild(parsed);
});
details.appendChild(title);
details.appendChild(content);
div.appendChild(details);
// 返回 div
return div;
}
/**
@@ -375,96 +389,97 @@ function BackupTextParser(data: PostStructuredContent): HTMLDivElement {
* @param {PostStructuredContent} data Mys数据
* @returns {HTMLDivElement} 解析后的抽奖
*/
function LotteryParser(data: PostStructuredContent): HTMLDivElement {
// 检查数据
if (typeof data.insert === "string") {
throw new Error("data.insert is a string");
}
if (!data.insert.backup_text) {
throw new Error("data.insert.backup_text is not defined");
}
if (data.insert.backup_text !== "[抽奖]") {
throw new Error("data.insert.backup_text is not [抽奖]");
}
if (!data.insert.lottery) {
throw new Error("data.insert.lottery is not defined");
}
// 创建 div
const div = document.createElement("div");
// 创建图标
const icon = document.createElement("i");
icon.classList.add("mdi", "mdi-gift");
// 创建标题
const title = document.createElement("a");
title.classList.add("mys-post-link");
title.href = `/lottery/${data.insert.lottery.id}`;
title.innerText = data.insert.lottery.toast;
// 插入图标
title.prepend(icon);
// 插入标题
div.appendChild(title);
// 返回 div
return div;
function LotteryParser (data: PostStructuredContent): HTMLDivElement {
// 检查数据
if (typeof data.insert === "string") {
throw new Error("data.insert is a string");
}
if (!data.insert.backup_text) {
throw new Error("data.insert.backup_text is not defined");
}
if (data.insert.backup_text !== "[抽奖]") {
throw new Error("data.insert.backup_text is not [抽奖]");
}
if (!data.insert.lottery) {
throw new Error("data.insert.lottery is not defined");
}
// 创建 div
const div = document.createElement("div");
// 创建图标
const icon = document.createElement("i");
icon.classList.add("mdi", "mdi-gift");
// 创建标题
const title = document.createElement("a");
title.classList.add("mys-post-link");
title.href = `/lottery/${data.insert.lottery.id}`;
title.innerText = data.insert.lottery.toast;
// 插入图标
title.prepend(icon);
// 插入标题
div.appendChild(title);
// 返回 div
return div;
}
/**
* @description 解析链接卡片
* @since Alpha v0.1.1
* @since Alpha v0.1.2
* @param {PostStructuredContent} data Mys数据
* @returns {HTMLDivElement} 解析后的链接卡片
*/
function LinkCardParser(data: PostStructuredContent): HTMLDivElement {
// 检查数据
if (typeof data.insert === "string") {
throw new Error("data.insert is a string");
}
if (!data.insert.link_card) {
throw new Error("data.insert.link_card is not defined");
}
// 创建 div
const div = document.createElement("div");
// 创建 cover
const cover = document.createElement("div");
cover.classList.add("mys-post-link-card-cover");
// 创建 img
const img = document.createElement("img");
img.src = data.insert.link_card.cover;
// 插入 img
cover.appendChild(img);
// 插入 cover
div.appendChild(cover);
// 创建 content
const content = document.createElement("div");
content.classList.add("mys-post-link-card-content");
// 创建标题
const title = document.createElement("div");
title.classList.add("mys-post-link-card-title");
title.innerHTML = data.insert.link_card.title;
// 插入 title
content.appendChild(title);
if (data.insert.link_card.price) {
const price = document.createElement("div");
price.classList.add("mys-post-link-card-price");
price.innerHTML = data.insert.link_card.price;
content.appendChild(price);
}
// 创建 button
const button = document.createElement("a");
button.classList.add("mys-post-link-card-btn");
button.innerHTML = (data.insert.link_card.button_text || "详情") + " >";
const link_url = data.insert.link_card.origin_url;
if (IsMysPost(link_url)) {
button.href = "/post_detail/" + link_url.split("/").pop();
button.target = "_self";
} else {
button.href = link_url;
button.target = "view_window";
}
// 插入 button
content.appendChild(button);
// 插入 content
div.appendChild(content);
// 添加 class
div.classList.add("mys-post-link-card");
return div;
function LinkCardParser (data: PostStructuredContent): HTMLDivElement {
// 检查数据
if (typeof data.insert === "string") {
throw new Error("data.insert is a string");
}
if (!data.insert.link_card) {
throw new Error("data.insert.link_card is not defined");
}
// 创建 div
const div = document.createElement("div");
// 创建 cover
const cover = document.createElement("div");
cover.classList.add("mys-post-link-card-cover");
// 创建 img
const img = document.createElement("img");
img.src = data.insert.link_card.cover;
// 插入 img
cover.appendChild(img);
// 插入 cover
div.appendChild(cover);
// 创建 content
const content = document.createElement("div");
content.classList.add("mys-post-link-card-content");
// 创建标题
const title = document.createElement("div");
title.classList.add("mys-post-link-card-title");
title.innerHTML = data.insert.link_card.title;
// 插入 title
content.appendChild(title);
if (data.insert.link_card.price) {
const price = document.createElement("div");
price.classList.add("mys-post-link-card-price");
price.innerHTML = data.insert.link_card.price;
content.appendChild(price);
}
// 创建 button
const button = document.createElement("a");
button.classList.add("mys-post-link-card-btn");
button.innerHTML = (data.insert.link_card.button_text || "详情") + " >";
const linkUrl = data.insert.link_card.origin_url;
if (IsMysPost(linkUrl)) {
const postId = getPostId(linkUrl);
button.href = `/post_detail/${postId}`;
button.target = "_self";
} else {
button.href = linkUrl;
button.target = "view_window";
}
// 插入 button
content.appendChild(button);
// 插入 content
div.appendChild(content);
// 添加 class
div.classList.add("mys-post-link-card");
return div;
}

View File

@@ -2,55 +2,55 @@
* @file plugins Mys utils position.ts
* @description Mys 插件热点追踪工具
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.1.1
* @since Alpha v0.1.2
*/
import { PositionObc, PositionData, PositionCard } from "../interface/position";
import { type PositionObc, type PositionData, type PositionCard } from "../interface/position";
/**
* @description 深度优先遍历
* @since Alpha v0.1.1
* @param {PositionObc[]} list 列表
* @return {PositionData[]} 返回列表
* @returns {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;
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
* @since Alpha v0.1.2
* @param {PositionData[]} positionData 列表
* @return {PositionCard[]} 返回列表
* @returns {PositionCard[]} 返回列表
*/
export function getPositionCard(positionData: PositionData[]): PositionCard[] {
const res: PositionCard[] = [];
positionData.map(position => {
res.push({
title: position.title,
post_id: Number(position.url.split("/").pop()),
icon: position.icon,
abstract: position.abstract,
time: {
start: position.create_time,
start_stamp: new Date(position.create_time).getTime(),
end: new Date(Number(position.end_time))
.toLocaleString("zh-CN", {
hour12: false,
})
.replace(/\//g, "-"),
end_stamp: Number(position.end_time),
},
});
});
return res;
export function getPositionCard (positionData: PositionData[]): PositionCard[] {
const res: PositionCard[] = [];
positionData.map((position) => {
return res.push({
title: position.title,
post_id: Number(position.url.split("/").pop()),
icon: position.icon,
abstract: position.abstract,
time: {
start: position.create_time,
start_stamp: new Date(position.create_time).getTime(),
end: new Date(Number(position.end_time))
.toLocaleString("zh-CN", {
hour12: false,
})
.replace(/\//g, "-"),
end_stamp: Number(position.end_time),
},
});
});
return res;
}

View File

@@ -2,16 +2,16 @@
* @file plugins UIAF index.ts
* @description UIAF plugin index
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha
* @since Alpha v0.1.2
*/
import { checkUIAFData, readUIAFData } from "./utils/importData";
import { getUIAFInfo } from "./utils/exportData";
import { checkUiafData, readUiafData } from "./utils/importData";
import { getUiafInfo } from "./utils/exportData";
const UIAF_Oper = {
checkUIAFData,
readUIAFData,
getUIAFInfo,
const UiafOper = {
checkUiafData,
readUiafData,
getUiafInfo,
};
export default UIAF_Oper;
export default UiafOper;

View File

@@ -4,49 +4,50 @@
* @author BTMuli<bt-muli@outlook.com>
* @see https://github.com/DGP-Studio/Snap.Genshin.Docs/blob/main/docs/development/UIAF.md
* @version v1.1
* @since Alpha
* @since Alpha v0.1.2
*/
/**
* @interface Achievements
* @description Achievements interface
* @property {UIAF_Info} info - UIAF info
* @property {UIAF_Achievement[]} list - Achievements data
* @return Achievements
* @description UIAF 成就数据
* @property {UIAF_Info} info UIAF 头部信息
* @property {UIAF_Achievement[]} list UIAF 成就列表
* @returns {Achievements}
*/
export interface Achievements {
info: UIAF_Info;
list: UIAF_Achievement[];
info: UiafHeader
list: UiafAchievement[]
}
/**
* @interface UIAF_Info
* @description UIAF info interface
* @property {string} export_app - Export app name
* @property {number} export_timestamp - Export timestamp
* @property {string} export_app_version - Export app version
* @property {string} uiaf_version - UIAF version
* @return UIAF_Info
* @interface UiafHeader
* @description UIAF 头部信息
* @property {string} export_app 导出的应用名称
* @property {number} export_timestamp 导出时间戳,正确时间戳得乘以 1000
* @property {string} export_app_version 导出的应用版本
* @property {string} uiaf_version UIAF 版本
* @returns {UiafHeader}
*/
export interface UIAF_Info {
export_app: string;
export_timestamp: number;
export_app_version: string;
uiaf_version: string;
export interface UiafHeader {
export_app: string
export_timestamp: number
export_app_version: string
uiaf_version: string
}
/**
* @interface UIAF_Achievement
* @description Achievements data interface
* @property {number} id - Achievement ID
* @property {number} timestamp - Achievement timestamp
* @property {number} current - Current progress
* @property {number} status - Achievement status
* @return UIAF_Achievement
* @interface UiafAchievement
* @since Alpha v0.1.2
* @description UIAF 单个成就数据
* @property {number} id 成就 ID
* @property {number} timestamp 成就记录时间戳,正确时间戳得乘以 1000
* @property {number} current 成就进度
* @property {number} status 成就状态0 为未完成1 为已完成
* @returns {UiafAchievement}
*/
export interface UIAF_Achievement {
id: number;
timestamp: number;
current: number;
status: number;
export interface UiafAchievement {
id: number
timestamp: number
current: number
status: number
}

View File

@@ -2,21 +2,22 @@
* @file plugins UIAF utils exportData.ts
* @description UIAF export data utils
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha
* @since Alpha v0.1.2
*/
import { UIAF_Info } from "../interface/UIAF";
import { type UiafHeader } from "../interface/UIAF";
import { app } from "@tauri-apps/api";
/**
* @description 获取 UIAF_Info
* @return Promise<UIAF_Info>
* @description 获取 UIAF 头部信息
* @since Alpha v0.1.2
* @returns {Promise<UiafHeader>}
*/
export async function getUIAFInfo(): Promise<UIAF_Info> {
return {
export_app: "Tauri.Genshin",
export_timestamp: Math.floor(Date.now() / 1000),
export_app_version: await app.getVersion(),
uiaf_version: "v1.1",
};
export async function getUiafInfo (): Promise<UiafHeader> {
return {
export_app: "Tauri.Genshin",
export_timestamp: Math.floor(Date.now() / 1000),
export_app_version: await app.getVersion(),
uiaf_version: "v1.1",
};
}

View File

@@ -2,40 +2,40 @@
* @file plugins UIAF utils importData.ts
* @description UIAF import data utils
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha
* @since Alpha v0.1.2
*/
import { UIAF_Info } from "../interface/UIAF";
import { type UiafHeader } from "../interface/UIAF";
import { fs } from "@tauri-apps/api";
/**
* @description 检测是否存在 UIAF 数据
* @description 粗略检测,不保证数据完整性
* @since Alpha
* @since Alpha v0.1.2
* @param {string} path - UIAF 数据路径
* @return {Promise<boolean>} 是否存在 UIAF 数据
* @returns {Promise<boolean>} 是否存在 UIAF 数据
*/
export async function checkUIAFData(path: string): Promise<boolean> {
const fileData: string = await fs.readTextFile(path);
const UIAFData: UIAF_Info = JSON.parse(fileData)["info"];
return UIAFData.uiaf_version !== undefined;
export async function checkUiafData (path: string): Promise<boolean> {
const fileData: string = await fs.readTextFile(path);
const UIAFData: UiafHeader = JSON.parse(fileData).info;
return UIAFData.uiaf_version !== undefined;
}
/**
* @description 读取 UIAF 数据
* @since Alpha
* @since Alpha v0.1.2
* @param {string} userPath - UIAF 数据路径
* @return {Promise<string|false>} UIAF 数据
* @returns {Promise<string|false>} UIAF 数据
*/
export async function readUIAFData(userPath: string): Promise<string | false> {
if (await fs.exists(userPath)) {
const fileData = await fs.readTextFile(userPath);
if (fileData !== undefined && fileData !== null && fileData !== "" && fileData !== "{}") {
return fileData;
} else {
return false;
}
} else {
return false;
}
export async function readUiafData (userPath: string): Promise<string | false> {
if (await fs.exists(userPath)) {
const fileData = await fs.readTextFile(userPath);
if (fileData !== undefined && fileData !== null && fileData !== "" && fileData !== "{}") {
return fileData;
} else {
return false;
}
} else {
return false;
}
}

View File

@@ -2,15 +2,15 @@
* @file router index.ts
* @description 路由入口
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha
* @since Alpha v0.1.2
*/
import { createRouter, createWebHistory } from "vue-router";
import routes from "./routes";
const router = createRouter({
history: createWebHistory(),
routes: routes,
history: createWebHistory(),
routes,
});
export default router;

View File

@@ -15,35 +15,35 @@ import Achievements from "../../pages/Achievements.vue";
import Config from "../../pages/Config.vue";
const mainRoutes = [
{
path: "/",
name: "首页",
component: Home,
},
{
path: "/achievements",
name: "成就",
component: Achievements,
},
{
path: "/announcements",
name: "公告",
component: Announcements,
},
{
path: "/config",
name: "设置",
component: Config,
},
{
path: "/GCG",
name: "卡牌",
component: GCG,
},
{
path: "/home",
redirect: "/",
},
{
path: "/",
name: "首页",
component: Home,
},
{
path: "/achievements",
name: "成就",
component: Achievements,
},
{
path: "/announcements",
name: "公告",
component: Announcements,
},
{
path: "/config",
name: "设置",
component: Config,
},
{
path: "/GCG",
name: "卡牌",
component: GCG,
},
{
path: "/home",
redirect: "/",
},
];
export default mainRoutes;

View File

@@ -16,36 +16,36 @@ import TPostJson from "../../views/t-post-json.vue";
import TLottery from "../../views/t-lottery.vue";
const subRoutes = [
{
path: "/anno_detail/:anno_id",
name: "游戏内公告",
component: TAnno,
},
{
path: "/anno_detail_json/:anno_id",
name: "游戏内公告JSON",
component: TAnnoJson,
},
{
path: "/news/:gid",
name: "咨讯",
component: TNews,
},
{
path: "/post_detail/:post_id",
name: "帖子详情",
component: TPost,
},
{
path: "/post_detail_json/:post_id",
name: "帖子详情JSON",
component: TPostJson,
},
{
path: "/lottery/:lottery_id",
name: "抽奖详情",
component: TLottery,
},
{
path: "/anno_detail/:anno_id",
name: "游戏内公告",
component: TAnno,
},
{
path: "/anno_detail_json/:anno_id",
name: "游戏内公告JSON",
component: TAnnoJson,
},
{
path: "/news/:gid",
name: "咨讯",
component: TNews,
},
{
path: "/post_detail/:post_id",
name: "帖子详情",
component: TPost,
},
{
path: "/post_detail_json/:post_id",
name: "帖子详情JSON",
component: TPostJson,
},
{
path: "/lottery/:lottery_id",
name: "抽奖详情",
component: TLottery,
},
];
export default subRoutes;

View File

@@ -8,37 +8,37 @@
import { defineStore } from "pinia";
const useAchievementsStore = defineStore({
id: "achievements",
state() {
return {
total_achievements: 899,
fin_achievements: 0,
// 这个数据用于说明当前的数据版本,不会被渲染
last_version: "v3.5",
UIAF_Version: "v1.1",
// 显示用,避免重复计算
title: "成就完成数0/899 完成率0%",
};
},
actions: {
init() {
this.total_achievements = 899;
this.fin_achievements = 0;
this.title = this.getTitle();
},
flushData(total: number, fin: number) {
this.total_achievements = total;
this.fin_achievements = fin;
this.title = this.getTitle();
},
getTitle() {
return `成就完成数:${this.fin_achievements}/${this.total_achievements} 完成率:${(
(this.fin_achievements / this.total_achievements) *
id: "achievements",
state () {
return {
total_achievements: 899,
fin_achievements: 0,
// 这个数据用于说明当前的数据版本,不会被渲染
last_version: "v3.5",
UIAF_Version: "v1.1",
// 显示用,避免重复计算
title: "成就完成数0/899 完成率0%",
};
},
actions: {
init () {
this.total_achievements = 899;
this.fin_achievements = 0;
this.title = this.getTitle();
},
flushData (total: number, fin: number) {
this.total_achievements = total;
this.fin_achievements = fin;
this.title = this.getTitle();
},
getTitle () {
return `成就完成数:${this.fin_achievements}/${this.total_achievements} 完成率:${(
(this.fin_achievements / this.total_achievements) *
100
).toFixed(2)}%`;
},
},
persist: true,
).toFixed(2)}%`;
},
},
persist: true,
});
export default useAchievementsStore;

View File

@@ -16,106 +16,107 @@ const userDataDir = `${await path.appLocalDataDir()}userData`;
const tempDataDir = `${await path.appLocalDataDir()}tempData`;
const useAppStore = defineStore({
id: "app",
state: () => {
return {
// 是否加载数据
loading: false,
// 侧边栏设置
sidebar: {
// 是否折叠
collapse: true,
// 是否显示
submenu: {
// 米游社
mihoyo: false,
// 数据库
database: false,
},
},
// 开发者模式
devMode: false,
// 数据路径
dataPath: {
app: appDataDir,
user: userDataDir,
temp: tempDataDir,
},
// 应用数据路径
appPath: {
achievements: `${appDataDir}\\achievements.json`,
achievementSeries: `${appDataDir}\\achievementSeries.json`,
nameCards: `${appDataDir}\\nameCards.json`,
},
// 用户数据路径
userPath: {
achievements: `${userDataDir}\\achievements.json`,
},
};
},
actions: {
// 检测 store 数据兼容,主要是 sideBar 数据
async check() {
if (this.sidebar === undefined) {
this.sidebar = {
collapse: true,
submenu: {
mihoyo: false,
database: false,
},
};
} else {
if (this.sidebar.collapse === undefined) this.sidebar.collapse = false;
if (this.sidebar.submenu === undefined)
this.sidebar.submenu = { database: false, mihoyo: false };
if (this.sidebar.submenu.database === undefined) this.sidebar.submenu.database = false;
if (this.sidebar.submenu.mihoyo === undefined) this.sidebar.submenu.mihoyo = false;
}
},
// 初始化配置
async init() {
// 初始化侧边栏设置
this.sidebar = {
collapse: false,
submenu: {
mihoyo: false,
database: false,
},
};
// 初始化加载状态
this.loading = false;
// 初始化开发者模式
this.devMode = false;
// 初始化用户数据路径
this.userPath = {
achievements: `${userDataDir}\\achievements.json`,
};
},
// 获取折叠
getSubmenu() {
let open = [];
if (this.sidebar.submenu.database) open.push("database");
if (this.sidebar.submenu.mihoyo) open.push("mihoyo");
return open;
},
},
persist: [
{
key: "appPath",
storage: window.localStorage,
paths: ["dataPath", "appPath", "userPath"],
},
{
key: "app",
storage: window.localStorage,
paths: ["devMode", "loading"],
},
{
key: "sidebar",
storage: window.localStorage,
paths: ["sidebar"],
},
],
id: "app",
state: () => {
return {
// 是否加载数据
loading: false,
// 侧边栏设置
sidebar: {
// 是否折叠
collapse: true,
// 是否显示
submenu: {
// 米游社
mihoyo: false,
// 数据库
database: false,
},
},
// 开发者模式
devMode: false,
// 数据路径
dataPath: {
app: appDataDir,
user: userDataDir,
temp: tempDataDir,
},
// 应用数据路径
appPath: {
achievements: `${appDataDir}\\achievements.json`,
achievementSeries: `${appDataDir}\\achievementSeries.json`,
nameCards: `${appDataDir}\\nameCards.json`,
},
// 用户数据路径
userPath: {
achievements: `${userDataDir}\\achievements.json`,
},
};
},
actions: {
// 检测 store 数据兼容,主要是 sideBar 数据
async check () {
if (this.sidebar === undefined) {
this.sidebar = {
collapse: true,
submenu: {
mihoyo: false,
database: false,
},
};
} else {
if (this.sidebar.collapse === undefined) this.sidebar.collapse = false;
if (this.sidebar.submenu === undefined) {
this.sidebar.submenu = { database: false, mihoyo: false };
}
if (this.sidebar.submenu.database === undefined) this.sidebar.submenu.database = false;
if (this.sidebar.submenu.mihoyo === undefined) this.sidebar.submenu.mihoyo = false;
}
},
// 初始化配置
async init () {
// 初始化侧边栏设置
this.sidebar = {
collapse: false,
submenu: {
mihoyo: false,
database: false,
},
};
// 初始化加载状态
this.loading = false;
// 初始化开发者模式
this.devMode = false;
// 初始化用户数据路径
this.userPath = {
achievements: `${userDataDir}\\achievements.json`,
};
},
// 获取折叠
getSubmenu () {
const open = [];
if (this.sidebar.submenu.database) open.push("database");
if (this.sidebar.submenu.mihoyo) open.push("mihoyo");
return open;
},
},
persist: [
{
key: "appPath",
storage: window.localStorage,
paths: ["dataPath", "appPath", "userPath"],
},
{
key: "app",
storage: window.localStorage,
paths: ["devMode", "loading"],
},
{
key: "sidebar",
storage: window.localStorage,
paths: ["sidebar"],
},
],
});
export default useAppStore;

View File

@@ -6,120 +6,120 @@
*/
import { defineStore } from "pinia";
import { Map } from "../../interface/Base";
import { type Map } from "../../interface/Base";
const useHomeStore = defineStore({
id: "home",
state: () => {
return {
calendar: {
show: true,
order: 3,
},
pool: {
show: true,
order: 1,
},
position: {
show: true,
order: 2,
},
poolCover: {} as Map<string>,
};
},
actions: {
async init() {
this.$state = {
calendar: {
show: true,
order: 3,
},
pool: {
show: true,
order: 1,
},
position: {
show: true,
order: 2,
},
poolCover: {},
};
},
getShowItem() {
const defaultList = ["素材日历", "限时祈愿", "近期活动"];
defaultList.sort((a, b) => {
return this.getItemOrder(a) - this.getItemOrder(b);
});
return defaultList;
},
getShowValue() {
let showValue = [];
if (this.calendar.show) showValue.push("素材日历");
if (this.pool.show) showValue.push("限时祈愿");
if (this.position.show) showValue.push("近期活动");
showValue.sort((a, b) => {
return this.getItemOrder(a) - this.getItemOrder(b);
});
return showValue;
},
getItemOrder(item: string) {
switch (item) {
case "素材日历":
return this.calendar.order;
case "限时祈愿":
return this.pool.order;
case "近期活动":
return this.position.order;
default:
return 4;
}
},
setShowValue(value: string[]) {
let order = 1;
// 遍历 value
value.forEach(item => {
if (!this.getShowItem().includes(item)) {
throw new Error("传入的值不在可选范围内");
}
switch (item) {
case "素材日历":
this.calendar.order = order;
this.calendar.show = true;
order++;
break;
case "限时祈愿":
this.pool.order = order;
this.pool.show = true;
order++;
break;
case "近期活动":
this.position.order = order;
this.position.show = true;
order++;
break;
default:
break;
}
// 没有显示的 item
if (!value.includes("素材日历")) {
this.calendar.show = false;
this.calendar.order = order;
order++;
}
if (!value.includes("限时祈愿")) {
this.pool.show = false;
this.pool.order = order;
order++;
}
if (!value.includes("近期活动")) {
this.position.show = false;
this.position.order = order;
order++;
}
});
},
},
persist: true,
id: "home",
state: () => {
return {
calendar: {
show: true,
order: 3,
},
pool: {
show: true,
order: 1,
},
position: {
show: true,
order: 2,
},
poolCover: {} satisfies Map<string>,
};
},
actions: {
async init () {
this.$state = {
calendar: {
show: true,
order: 3,
},
pool: {
show: true,
order: 1,
},
position: {
show: true,
order: 2,
},
poolCover: {},
};
},
getShowItem () {
const defaultList = ["素材日历", "限时祈愿", "近期活动"];
defaultList.sort((a, b) => {
return this.getItemOrder(a) - this.getItemOrder(b);
});
return defaultList;
},
getShowValue () {
const showValue = [];
if (this.calendar.show) showValue.push("素材日历");
if (this.pool.show) showValue.push("限时祈愿");
if (this.position.show) showValue.push("近期活动");
showValue.sort((a, b) => {
return this.getItemOrder(a) - this.getItemOrder(b);
});
return showValue;
},
getItemOrder (item: string) {
switch (item) {
case "素材日历":
return this.calendar.order;
case "限时祈愿":
return this.pool.order;
case "近期活动":
return this.position.order;
default:
return 4;
}
},
setShowValue (value: string[]) {
let order = 1;
// 遍历 value
value.forEach((item) => {
if (!this.getShowItem().includes(item)) {
throw new Error("传入的值不在可选范围内");
}
switch (item) {
case "素材日历":
this.calendar.order = order;
this.calendar.show = true;
order++;
break;
case "限时祈愿":
this.pool.order = order;
this.pool.show = true;
order++;
break;
case "近期活动":
this.position.order = order;
this.position.show = true;
order++;
break;
default:
break;
}
// 没有显示的 item
if (!value.includes("素材日历")) {
this.calendar.show = false;
this.calendar.order = order;
order++;
}
if (!value.includes("限时祈愿")) {
this.pool.show = false;
this.pool.order = order;
order++;
}
if (!value.includes("近期活动")) {
this.position.show = false;
this.position.order = order;
order++;
}
});
},
},
persist: true,
});
export default useHomeStore;

View File

@@ -2,7 +2,7 @@
* @file utils TGIndex.ts
* @description IndexedDB utils
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha
* @since Alpha v0.1.2
*/
import { TGConfigList } from "../data";
@@ -14,31 +14,32 @@ export const DB_VERSION = 1;
/**
* @description 初始化数据库
* @description 只会在第一次打开游戏时执行
* @since Alpha
* @since Alpha v0.1.2
* @returns {Promise<void>}
*/
export async function InitTGData() {
const request = window.indexedDB.open(DB_NAME, DB_VERSION);
request.onupgradeneeded = () => {
const db = request.result;
// 创建表
TGConfigList.forEach(config => {
const store = db.createObjectStore(config.storeName, {
keyPath: config.keyPath,
});
config.indexes.forEach(index => {
store.createIndex(index, index, { unique: false });
});
});
};
export async function InitTGData (): Promise<void> {
const request = window.indexedDB.open(DB_NAME, DB_VERSION);
request.onupgradeneeded = () => {
const db = request.result;
// 创建表
TGConfigList.forEach((config) => {
const store = db.createObjectStore(config.storeName, {
keyPath: config.keyPath,
});
config.indexes.forEach((index) => {
store.createIndex(index, index, { unique: false });
});
});
};
}
/**
* @description 删除数据库
* @since Alpha
* @return {void}
* @returns {void}
*/
export function DeleteTGData() {
window.indexedDB.deleteDatabase(DB_NAME);
export function DeleteTGData (): void {
window.indexedDB.deleteDatabase(DB_NAME);
}
/**
@@ -46,18 +47,18 @@ export function DeleteTGData() {
* @since Alpha
* @param {string} storeName 表名
* @param {any[]} data 数据
* @return {Promise<void>}
* @returns {Promise<void>}
*/
export async function WriteTGData(storeName: string, data: any[]) {
const request = window.indexedDB.open(DB_NAME, DB_VERSION);
request.onsuccess = () => {
const db = request.result;
const transaction = db.transaction(storeName, "readwrite");
const store = transaction.objectStore(storeName);
data.forEach(item => {
store.put(item);
});
};
export async function WriteTGData (storeName: string, data: any[]): Promise<void> {
const request = window.indexedDB.open(DB_NAME, DB_VERSION);
request.onsuccess = () => {
const db = request.result;
const transaction = db.transaction(storeName, "readwrite");
const store = transaction.objectStore(storeName);
data.forEach((item) => {
store.put(item);
});
};
}
/**
@@ -65,16 +66,16 @@ export async function WriteTGData(storeName: string, data: any[]) {
* @since Alpha
* @param {string} storeName 表名
* @param {any} data 数据
* @return {Promise<void>}
* @returns {Promise<void>}
*/
export async function UpdateTGDataByKey(storeName: string, data: any): Promise<void> {
const request = window.indexedDB.open(DB_NAME, DB_VERSION);
request.onsuccess = () => {
const db = request.result;
const transaction = db.transaction(storeName, "readwrite");
const store = transaction.objectStore(storeName);
store.put(data);
};
export async function UpdateTGDataByKey (storeName: string, data: any): Promise<void> {
const request = window.indexedDB.open(DB_NAME, DB_VERSION);
request.onsuccess = () => {
const db = request.result;
const transaction = db.transaction(storeName, "readwrite");
const store = transaction.objectStore(storeName);
store.put(data);
};
}
/**
@@ -84,31 +85,26 @@ export async function UpdateTGDataByKey(storeName: string, data: any): Promise<v
* @param {string} indexName 索引名
* @param {any} key 索引值
* @param {any} data 数据
* @return {Promise<void>}
* @returns {Promise<void>}
*/
export async function UpdateTGDataByIndex(
storeName: string,
indexName: string,
key: any,
data: any
): Promise<void> {
const request = window.indexedDB.open(DB_NAME, DB_VERSION);
request.onsuccess = () => {
const db = request.result;
const transaction = db.transaction(storeName, "readwrite");
const store = transaction.objectStore(storeName);
const index = store.index(indexName);
const requestData = index.getAll(key);
requestData.onsuccess = () => {
const result = requestData.result;
result.forEach(item => {
Object.keys(data).forEach(key => {
item[key] = data[key];
});
store.put(item);
});
};
};
export async function UpdateTGDataByIndex (storeName: string, indexName: string, key: any, data: any): Promise<void> {
const request = window.indexedDB.open(DB_NAME, DB_VERSION);
request.onsuccess = () => {
const db = request.result;
const transaction = db.transaction(storeName, "readwrite");
const store = transaction.objectStore(storeName);
const index = store.index(indexName);
const requestData = index.getAll(key);
requestData.onsuccess = () => {
const result = requestData.result;
result.forEach((item) => {
Object.keys(data).forEach((key) => {
item[key] = data[key];
});
store.put(item);
});
};
};
}
/**
@@ -116,31 +112,31 @@ export async function UpdateTGDataByIndex(
* @since Alpha
* @param {string} storeName 表名
* @param {any[]} keys 主键值
* @return {Promise<any[]>}
* @returns {Promise<any[]>}
*/
export async function ReadTGDataByKey(storeName: string, keys: any[]): Promise<any[]> {
const request = window.indexedDB.open(DB_NAME, DB_VERSION);
return new Promise((resolve, reject) => {
request.onsuccess = () => {
const db = request.result;
const transaction = db.transaction(storeName, "readonly");
const store = transaction.objectStore(storeName);
const requestData = store.getAll();
requestData.onsuccess = () => {
const result = requestData.result;
const data = result.filter(item => {
return keys.includes(item.id);
});
resolve(data);
};
requestData.onerror = () => {
reject(requestData.error);
};
};
request.onerror = () => {
reject(request.error);
};
});
export async function ReadTGDataByKey (storeName: string, keys: any[]): Promise<any[]> {
const request = window.indexedDB.open(DB_NAME, DB_VERSION);
return await new Promise((resolve, reject) => {
request.onsuccess = () => {
const db = request.result;
const transaction = db.transaction(storeName, "readonly");
const store = transaction.objectStore(storeName);
const requestData = store.getAll();
requestData.onsuccess = () => {
const result = requestData.result;
const data = result.filter((item) => {
return keys.includes(item.id);
});
resolve(data);
};
requestData.onerror = () => {
reject(requestData.error);
};
};
request.onerror = () => {
reject(request.error);
};
});
}
/**
@@ -149,57 +145,53 @@ export async function ReadTGDataByKey(storeName: string, keys: any[]): Promise<a
* @param {string} storeName 表名
* @param {string} indexName 索引名
* @param {any} key 索引值
* @return {Promise<any[]>}
* @returns {Promise<any[]>}
*/
export async function ReadTGDataByIndex(
storeName: string,
indexName: string,
key: any
): Promise<any[]> {
const request = window.indexedDB.open(DB_NAME, DB_VERSION);
return new Promise((resolve, reject) => {
request.onsuccess = () => {
const db = request.result;
const transaction = db.transaction(storeName, "readonly");
const store = transaction.objectStore(storeName);
const index = store.index(indexName);
const requestData = index.getAll(key);
requestData.onsuccess = () => {
resolve(requestData.result);
};
requestData.onerror = () => {
reject(requestData.error);
};
};
request.onerror = () => {
reject(request.error);
};
});
export async function ReadTGDataByIndex (storeName: string, indexName: string, key: any): Promise<any[]> {
const request = window.indexedDB.open(DB_NAME, DB_VERSION);
return await new Promise((resolve, reject) => {
request.onsuccess = () => {
const db = request.result;
const transaction = db.transaction(storeName, "readonly");
const store = transaction.objectStore(storeName);
const index = store.index(indexName);
const requestData = index.getAll(key);
requestData.onsuccess = () => {
resolve(requestData.result);
};
requestData.onerror = () => {
reject(requestData.error);
};
};
request.onerror = () => {
reject(request.error);
};
});
}
/**
* @description 从数据库中读取所有数据
* @since Alpha
* @param {string} storeName 表名
* @return {Promise<any[]>}
* @returns {Promise<any[]>}
*/
export async function ReadAllTGData(storeName: string): Promise<any[]> {
const request = window.indexedDB.open(DB_NAME, DB_VERSION);
return new Promise((resolve, reject) => {
request.onsuccess = () => {
const db = request.result;
const transaction = db.transaction(storeName, "readonly");
const store = transaction.objectStore(storeName);
const requestData = store.getAll();
requestData.onsuccess = () => {
resolve(requestData.result);
};
requestData.onerror = () => {
reject(requestData.error);
};
};
request.onerror = () => {
reject(request.error);
};
});
export async function ReadAllTGData (storeName: string): Promise<any[]> {
const request = window.indexedDB.open(DB_NAME, DB_VERSION);
return await new Promise((resolve, reject) => {
request.onsuccess = () => {
const db = request.result;
const transaction = db.transaction(storeName, "readonly");
const store = transaction.objectStore(storeName);
const requestData = store.getAll();
requestData.onsuccess = () => {
resolve(requestData.result);
};
requestData.onerror = () => {
reject(requestData.error);
};
};
request.onerror = () => {
reject(request.error);
};
});
}

View File

@@ -17,38 +17,38 @@ import { window as TauriWindow } from "@tauri-apps/api";
* @param {boolean} resizable 是否可调整大小
* @returns {void}
*/
export function createTGWindow(
url: string,
label: string,
title: string,
width: number,
height: number,
resizable: boolean
export function createTGWindow (
url: string,
label: string,
title: string,
width: number,
height: number,
resizable: boolean,
): void {
// 计算窗口位置
const left = (window.screen.width - width) / 2;
const top = (window.screen.height - height) / 2;
// https://github.com/tauri-apps/tauri/issues/5380
new TauriWindow.WebviewWindow(label, {
height: height,
width: width,
x: left,
y: top,
resizable: resizable,
url: url,
title: title,
visible: false,
});
new TauriWindow.WindowManager(label).close().then(() => {
new TauriWindow.WebviewWindow(label, {
height: height,
width: width,
x: left,
y: top,
resizable: resizable,
url: url,
title: title,
visible: false,
});
});
// 计算窗口位置
const left = (window.screen.width - width) / 2;
const top = (window.screen.height - height) / 2;
// https://github.com/tauri-apps/tauri/issues/5380
void new TauriWindow.WebviewWindow(label, {
height,
width,
x: left,
y: top,
resizable,
url,
title,
visible: false,
});
void new TauriWindow.WindowManager(label).close().then(() => {
void new TauriWindow.WebviewWindow(label, {
height,
width,
x: left,
y: top,
resizable,
url,
title,
visible: false,
});
});
}