♻️ erasableSyntaxOnly

This commit is contained in:
目棃
2025-03-17 17:58:15 +08:00
parent 08f74ce6a0
commit 522add2441
8 changed files with 42 additions and 156 deletions

View File

@@ -38,21 +38,11 @@ import TOverlay from "./t-overlay.vue";
import { generateShareImg } from "@/utils/TGShare.js";
enum ToNameCardTypeEnum {
other,
achievement,
role,
record,
activity,
unknown,
}
type ToNameCardTypeMap = { [key in ToNameCardTypeEnum]: string };
type ToNameCardProps = { data?: TGApp.App.NameCard.Item };
const props = defineProps<ToNameCardProps>();
const visible = defineModel<boolean>();
const typeMap: ToNameCardTypeMap = {
const typeMap: Record<number, string> = {
0: "其他",
1: "成就",
2: "角色",
@@ -62,10 +52,9 @@ const typeMap: ToNameCardTypeMap = {
};
const loading = ref<boolean>(false);
const getType = computed<string>(() => {
if (!props.data) return typeMap[ToNameCardTypeEnum.unknown];
if (!(props.data.type satisfies ToNameCardTypeEnum)) return typeMap[5];
const type: ToNameCardTypeEnum = props.data.type;
return typeMap[type];
if (!props.data) return typeMap[0];
if (!(props.data.type in typeMap)) return typeMap[5];
return typeMap[props.data.type];
});
function parseNameCard(desc: string): string {

View File

@@ -52,15 +52,8 @@ import { onMounted, reactive, type Ref, ref, shallowRef, watch } from "vue";
import { timestampToDate } from "@/utils/toolFunc.js";
enum AbyssTabEnum {
use = "角色使用",
up = "角色出场",
team = "队伍出场",
hold = "角色持有",
}
type AbyssTab = keyof typeof AbyssTabEnum;
type AbyssList = Array<{ label: AbyssTabEnum; value: AbyssTab }>;
type AbyssTab = "use" | "up" | "team" | "hold";
type AbyssList = Array<{ label: string; value: AbyssTab }>;
export type AbyssDataItem<T> = { cur: T; last: T };
export type AbyssDataItemType<T extends AbyssTab> = T extends "use"
? AbyssDataItem<Array<TGApp.Plugins.Hutao.Abyss.AvatarUse>>
@@ -74,11 +67,17 @@ export type AbyssDataItemType<T extends AbyssTab> = T extends "use"
type AbyssData = { [key in AbyssTab]: Ref<AbyssDataItemType<key> | null> };
const abyssList: Readonly<AbyssList> = [
{ label: AbyssTabEnum.use, value: "use" },
{ label: AbyssTabEnum.up, value: "up" },
{ label: AbyssTabEnum.team, value: "team" },
{ label: AbyssTabEnum.hold, value: "hold" },
{ label: "角色使用", value: "use" },
{ label: "角色出场", value: "up" },
{ label: "队伍出场", value: "team" },
{ label: "角色持有", value: "hold" },
];
const abyssMap: Readonly<Record<AbyssTab, string>> = {
use: "角色使用率",
up: "角色出场率",
team: "队伍出场率",
hold: "角色持有率",
};
const showDialog = ref<boolean>(false);
const tab = shallowRef<AbyssTab>("use");
const overview = shallowRef<AbyssDataItem<TGApp.Plugins.Hutao.Abyss.OverviewData>>();
@@ -107,7 +106,7 @@ onMounted(async () => {
async function refreshData(type: AbyssTab): Promise<void> {
if (abyssData && abyssData[type] !== null) return;
await showLoading.start("正在获取深渊数据", `正在获取 ${AbyssTabEnum[type]} 数据`);
await showLoading.start("正在获取深渊数据", `正在获取 ${abyssMap[type]} 数据`);
const data = await getData(type);
switch (type) {
case "use":

View File

@@ -72,7 +72,7 @@ import { storeToRefs } from "pinia";
import { type Component, computed, onMounted, ref, shallowRef, watch } from "vue";
import { useAppStore } from "@/store/modules/app.js";
import { ShowItemEnum, useHomeStore } from "@/store/modules/home.js";
import { useHomeStore } from "@/store/modules/home.js";
import TGLogger from "@/utils/TGLogger.js";
import apiHubReq from "@/web/request/apiHubReq.js";
@@ -87,20 +87,16 @@ type SelectItem = { icon: string; title: string; gid: number };
const { devMode, isLogin } = storeToRefs(useAppStore());
const homeStore = useHomeStore();
const showItemsAll: Array<ShowItemEnum> = [
ShowItemEnum.calendar,
ShowItemEnum.pool,
ShowItemEnum.position,
];
const showItemsAll: Array<string> = ["素材日历", "限时祈愿", "近期活动"];
const curGid = ref<number>(2);
const gameList = shallowRef<Array<SelectItem>>();
const loadItems = shallowRef<Array<ShowItemEnum>>([]);
const loadItems = shallowRef<Array<string>>([]);
const components = shallowRef<Array<SFComp>>([]);
const showItems = computed<Array<ShowItemEnum>>({
const showItems = computed<Array<string>>({
get: () => homeStore.getShowItems(),
set: (v: Array<ShowItemEnum>) => homeStore.setShowItems(v),
set: (v: Array<string>) => homeStore.setShowItems(v),
});
onMounted(async () => {
@@ -154,14 +150,14 @@ async function submitHome(): Promise<void> {
await loadComp();
}
function getName(name: string): ShowItemEnum | undefined {
function getName(name: string): string | undefined {
switch (name) {
case "ph-comp-pool":
return ShowItemEnum.pool;
return "限时祈愿";
case "ph-comp-position":
return ShowItemEnum.position;
return "近期活动";
case "ph-comp-calendar":
return ShowItemEnum.calendar;
return "素材日历";
default:
return undefined;
}

View File

@@ -72,7 +72,7 @@ import type { Ref } from "vue";
import { computed, onMounted, reactive, ref, shallowRef } from "vue";
import { useRoute, useRouter } from "vue-router";
import { type NewsType, NewsTypeEnum, useAppStore } from "@/store/modules/app.js";
import { type NewsType, useAppStore } from "@/store/modules/app.js";
import TGBbs from "@/utils/TGBbs.js";
import TGLogger from "@/utils/TGLogger.js";
import { createPost } from "@/utils/TGWindow.js";
@@ -87,6 +87,7 @@ const { recentNewsType } = storeToRefs(useAppStore());
const { gid } = <{ gid: string }>useRoute().params;
const tabValues: Readonly<Array<NewsType>> = ["notice", "activity", "news"];
const tabMap: Readonly<Record<NewsType, string>> = { notice: "1", activity: "2", news: "3" };
const gameName = TGBbs.channels.find((v) => v.gid.toString() === gid)?.title || "未知分区";
const loading = ref<boolean>(false);
@@ -123,7 +124,7 @@ async function firstLoad(key: NewsType, refresh: boolean = false): Promise<void>
}
await showLoading.start(`正在获取${gameName}${rawData[key].name}数据`);
document.documentElement.scrollTo({ top: 0, behavior: "smooth" });
const getData = await painterReq.news(gid, NewsTypeEnum[key]);
const getData = await painterReq.news(gid, tabMap[key]);
await showLoading.update(`数量:${getData.list.length},是否最后一页:${getData.is_last}`);
rawData[key] = { isLast: getData.is_last, name: rawData[key].name, lastId: getData.list.length };
postData[key] = getData.list;
@@ -150,7 +151,7 @@ async function loadMore(key: NewsType): Promise<void> {
await showLoading.start(`正在获取${gameName}${rawData[key].name}数据`);
const mod = rawData[key].lastId % 20;
const pageSize = mod === 0 ? 20 : 20 - mod;
const getData = await painterReq.news(gid, NewsTypeEnum[key], pageSize, rawData[key].lastId);
const getData = await painterReq.news(gid, tabMap[key], pageSize, rawData[key].lastId);
await showLoading.update(`数量:${getData.list.length},是否最后一页:${getData.is_last}`);
rawData[key].lastId = rawData[key].lastId + getData.list.length;
rawData[key].isLast = getData.is_last;

View File

@@ -18,13 +18,7 @@ const dbDataPath: Readonly<string> = `${await path.appConfigDir()}${path.sep()}T
// 用于存放日志的路径
const logDataDir: Readonly<string> = await path.appLogDir();
export enum NewsTypeEnum {
notice = "1",
activity = "2",
news = "3",
}
export type NewsType = keyof typeof NewsTypeEnum;
export type NewsType = "notice" | "activity" | "news";
export const useAppStore = defineStore(
"app",

View File

@@ -1,29 +1,23 @@
/**
* @file store/modules/home.ts
* @description Home store module
* @since Beta v0.6.5
* @since Beta v0.7.2
*/
import { defineStore } from "pinia";
import { ref } from "vue";
export const enum ShowItemEnum {
calendar = "素材日历",
pool = "限时祈愿",
position = "近期活动",
}
export type ShowItem = { show: boolean; order: number; label: ShowItemEnum };
export type ShowItem = { show: boolean; order: number; label: string };
export const useHomeStore = defineStore("home", () => {
const homeShow = ref<Array<ShowItem>>([
{ show: true, order: 1, label: ShowItemEnum.pool },
{ show: true, order: 2, label: ShowItemEnum.position },
{ show: true, order: 3, label: ShowItemEnum.calendar },
{ show: true, order: 1, label: "限时祈愿" },
{ show: true, order: 2, label: "近期活动" },
{ show: true, order: 3, label: "素材日历" },
]);
const poolCover = ref<Record<number, string>>();
function getShowItems(): Array<ShowItemEnum> {
function getShowItems(): Array<string> {
const homeShowLocal = localStorage.getItem("homeShow");
if (homeShowLocal === null || !Array.isArray(JSON.parse(homeShowLocal))) {
localStorage.setItem("homeShow", JSON.stringify(homeShow.value));
@@ -37,14 +31,14 @@ export const useHomeStore = defineStore("home", () => {
function init(): void {
homeShow.value = [
{ show: true, order: 1, label: ShowItemEnum.pool },
{ show: true, order: 2, label: ShowItemEnum.position },
{ show: true, order: 3, label: ShowItemEnum.calendar },
{ show: true, order: 1, label: "限时祈愿" },
{ show: true, order: 2, label: "近期活动" },
{ show: true, order: 3, label: "素材日历" },
];
localStorage.setItem("homeShow", JSON.stringify(homeShow.value));
}
function setShowItems(items: Array<ShowItemEnum>): void {
function setShowItems(items: Array<string>): void {
let order = 1;
for (const item of items) {
const findIdx = homeShow.value.findIndex((i) => i.label === item);

View File

@@ -1,88 +0,0 @@
/**
* @file types Game Constant.d.ts
* @description 游戏常量类型定义文件
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.1.5
*/
declare namespace TGApp.Game.Constant {
/**
* @description 七元素
* @since Alpha v0.1.5
* @enum {string}
* @property {string} pyro - 火元素
* @property {string} hydro - 水元素
* @property {string} anemo - 风元素
* @property {string} electro - 雷元素
* @property {string} cryo - 冰元素
* @property {string} geo - 岩元素
* @property {string} dendro - 草元素
*/
export enum EnumElement {
pyro = "火元素",
hydro = "水元素",
anemo = "风元素",
electro = "雷元素",
cryo = "冰元素",
geo = "岩元素",
dendro = "草元素",
}
/**
* @description 七元素-英文
* @since Alpha v0.2.0
* @enum {string}
* @property {string} pyro - 火元素
* @property {string} hydro - 水元素
* @property {string} anemo - 风元素
* @property {string} electro - 雷元素
* @property {string} cryo - 冰元素
* @property {string} geo - 岩元素
* @property {string} dendro - 草元素
*/
export enum EnumElementEn {
pyro = "Pyro",
hydro = "Hydro",
anemo = "Anemo",
electro = "Electro",
cryo = "Cryo",
geo = "Geo",
dendro = "Dendro",
}
/**
* @description 武器类型
* @since Alpha v0.1.5
* @enum {string}
* @property {string} sword - 单手剑
* @property {string} claymore - 双手剑
* @property {string} pole - 长柄武器
* @property {string} bow - 弓
* @property {string} catalyst - 法器
*/
export enum EnumWeapon {
sword = "单手剑",
claymore = "双手剑",
pole = "长柄武器",
bow = "弓",
catalyst = "法器",
}
/**
* @description 圣遗物位置
* @since Alpha v0.2.0
* @enum {string}
* @property {string} flower - 生之花
* @property {string} feather - 死之羽
* @property {string} sands - 时之沙
* @property {string} goblet - 空之杯
* @property {string} circlet - 理之冠
*/
export enum EnumRelic {
flower = "生之花",
feather = "死之羽",
sands = "时之沙",
goblet = "空之杯",
circlet = "理之冠",
}
}

View File

@@ -16,6 +16,7 @@
"types": ["vite/client", "node", "color-convert", "js-md5", "uuid"],
"allowSyntheticDefaultImports": true,
"composite": true,
"erasableSyntaxOnly": true,
"baseUrl": ".",
"paths": {
"@/*": ["src/*"],