diff --git a/src/pages/common/PageBagMaterial.vue b/src/pages/common/PageBagMaterial.vue
index 16165a0d..216df1ee 100644
--- a/src/pages/common/PageBagMaterial.vue
+++ b/src/pages/common/PageBagMaterial.vue
@@ -60,7 +60,7 @@
@@ -113,7 +113,7 @@ export type MaterialInfo = {
const { gameDir } = storeToRefs(useAppStore());
-const curUid = ref();
+const curUid = ref(0);
const selectType = ref(null);
const search = ref();
const showOverlay = ref(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}
*/
async function loadMaterialList(uid: number): Promise {
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 = [];
@@ -180,7 +184,6 @@ async function loadMaterialList(uid: number): Promise {
materialShow.value = mList;
materialTypes.value = tList;
curIdx.value = 0;
- selectType.value = null;
await showLoading.end();
}
@@ -299,6 +302,9 @@ async function deleteUid(): Promise {
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((resolve) => setTimeout(resolve, 1000));
+ window.location.reload();
}
/**
diff --git a/src/plugins/Sqlite/modules/userBagMaterial.ts b/src/plugins/Sqlite/modules/userBagMaterial.ts
index cc6d49e6..b543ea74 100644
--- a/src/plugins/Sqlite/modules/userBagMaterial.ts
+++ b/src/plugins/Sqlite/modules/userBagMaterial.ts
@@ -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}
+ */
+function getValidMIds(): Array {
+ 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(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>,
+ list: Array,
): Promise {
let skip = 0;
- for (const item of list) {
+ const ids = new Set(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;