♻️ 支持空存档

This commit is contained in:
BTMuli
2025-12-11 18:05:59 +08:00
parent 073cd5e35d
commit 16af3dcd24
2 changed files with 40 additions and 9 deletions

View File

@@ -60,7 +60,7 @@
</template>
</v-app-bar>
<div class="pbm-container">
<template v-for="material in materialShow" :key="material.info.id">
<template v-for="material in materialShow" :key="`${curUid}-${material.info.id}`">
<PbMaterialItem :info="material.info" :tb="material.tb" @select="handleSelect" />
</template>
</div>
@@ -113,7 +113,7 @@ export type MaterialInfo = {
const { gameDir } = storeToRefs(useAppStore());
const curUid = ref<number>();
const curUid = ref<number>(0);
const selectType = ref<string | null>(null);
const search = ref<string>();
const showOverlay = ref<boolean>(false);
@@ -135,9 +135,9 @@ onMounted(async () => {
watch(
() => curUid.value,
async (value) => {
async () => {
if (showOverlay.value) showOverlay.value = false;
if (value) await loadMaterialList(value);
await loadMaterialList(curUid.value);
},
);
watch(
@@ -156,12 +156,16 @@ watch(
/**
* 加载存档数据
* @param {number} uid 存档UID
* @todo 重构加载逻辑,支持空存档
* @returns {Promise<void>}
*/
async function loadMaterialList(uid: number): Promise<void> {
if (showOverlay.value) showOverlay.value = false;
await showLoading.start(`正在加载 ${uid} 的材料数据`);
// 初始化
materialTypes.value = [];
materialShow.value = [];
materialList.value = [];
selectType.value = null;
const dList = await TSUserBagMaterial.getMaterial(uid);
const mList = [];
const tList: Array<MaterialType> = [];
@@ -180,7 +184,6 @@ async function loadMaterialList(uid: number): Promise<void> {
materialShow.value = mList;
materialTypes.value = tList;
curIdx.value = 0;
selectType.value = null;
await showLoading.end();
}
@@ -299,6 +302,9 @@ async function deleteUid(): Promise<void> {
uidList.value = uidList.value.filter((e) => e !== curUid.value);
if (uidList.value.length === 0) uidList.value = [0];
curUid.value = uidList.value[0];
showSnackbar.success(`已删除对应存档,即将刷新`);
await new Promise<void>((resolve) => setTimeout(resolve, 1000));
window.location.reload();
}
/**

View File

@@ -6,6 +6,19 @@ import { timestampToDate } from "@utils/toolFunc.js";
import TGSqlite from "../index.js";
import { WikiMaterialData } from "@/data/index.js";
/**
* 获取有效材料ID
* @since Beta v0.9.0
* @return {Array<number>}
*/
function getValidMIds(): Array<number> {
const skipType = ["系统开放", "好感成长", "风之翼", "挑战结算道具", "稀有货币", "通用货币"];
const filter = WikiMaterialData.filter((m) => !skipType.includes(m.type));
return filter.map((f) => f.id);
}
/**
* 获取插入Sql
* @since Beta v0.9.0
@@ -116,7 +129,11 @@ async function getMaterial(
[uid],
);
}
return res.map(parseMaterial);
const list = res.map(parseMaterial);
const ids = new Set<number>(getValidMIds());
for (const item of list) if (ids.has(item.id)) ids.delete(item.id);
for (const item of ids) list.push({ uid: uid, id: item, count: 0, records: [], updated: "" });
return list;
}
/**
@@ -128,10 +145,17 @@ async function getMaterial(
*/
async function saveYaeData(
uid: number,
list: Array<TGApp.Plugins.Yae.BagItem<"material">>,
list: Array<TGApp.Plugins.Yae.BagItemMaterial>,
): Promise<number> {
let skip = 0;
for (const item of list) {
const ids = new Set<number>(getValidMIds());
const newList = list;
for (const item of list) if (ids.has(item.item_id)) ids.delete(item.item_id);
// 处理0数据
for (const item of ids.values()) {
newList.push({ item_id: item, kind: "material", info: { count: 0 } });
}
for (const item of newList) {
const read = await getMaterial(uid, item.item_id);
if (read.length === 0) {
await insertMaterial(uid, item.item_id, item.info.count);
@@ -154,6 +178,7 @@ const TSUserBagMaterial = {
saveYaeData,
getMaterial,
insertMaterial,
getValidMIds,
};
export default TSUserBagMaterial;