mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-04-01 06:39:45 +08:00
✨ 支持货币数据获取
This commit is contained in:
21
src/App.vue
21
src/App.vue
@@ -129,13 +129,16 @@ async function handleYaeListen(event: Event<TGApp.Plugins.Yae.RsEvent>): Promise
|
||||
} else if (event.payload.type === "store") {
|
||||
await loadYaeBag(event.payload.uid, JSON.parse(event.payload.data));
|
||||
if (!yaeFlag.includes("store")) yaeFlag.push("store");
|
||||
} else if (event.payload.type === "prop") {
|
||||
await loadYaeProp(event.payload.uid, JSON.parse(event.payload.data));
|
||||
if (!yaeFlag.includes("prop")) yaeFlag.push("prop");
|
||||
}
|
||||
if (yaeFlag.length === 2) {
|
||||
if (yaeFlag.length === 3) {
|
||||
yaeFlag = [];
|
||||
showSnackbar.success(`导入Yae数据完成,即将刷新页面`);
|
||||
await showLoading.end();
|
||||
// await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
// window.location.reload();
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,6 +197,18 @@ async function loadYaeBag(uid: string, data: TGApp.Plugins.Yae.BagListRes): Prom
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理属性
|
||||
* @param uid - 用户UID
|
||||
* @param data - 属性数据
|
||||
* @returns 无返回值
|
||||
*/
|
||||
async function loadYaeProp(uid: string, data: TGApp.Plugins.Yae.PropRes): Promise<void> {
|
||||
for (const [k, v] of Object.entries(data)) {
|
||||
await TSUserBagMaterial.saveYaeCoin(Number(uid), Number(k), v);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 主题监听处理
|
||||
* @param {Event<string>} event - 事件
|
||||
|
||||
@@ -14,16 +14,14 @@ export const SKIP_BAG_TYPES: ReadonlyArray<string> = [
|
||||
"风之翼",
|
||||
/**TODO:数据获取*/
|
||||
"挑战结算道具",
|
||||
/**TODO:数据获取*/
|
||||
"稀有货币",
|
||||
/**TODO:数据获取*/
|
||||
"通用货币",
|
||||
];
|
||||
export const BAG_TYPE_LIST: ReadonlyArray<string> = [
|
||||
"高级兑换券",
|
||||
"普通兑换券",
|
||||
"限定祈愿道具",
|
||||
"祈愿道具",
|
||||
"稀有货币",
|
||||
"通用货币",
|
||||
"任务道具",
|
||||
"七国徽印",
|
||||
"冒险道具",
|
||||
@@ -68,11 +66,11 @@ function getValidMIds(): Array<number> {
|
||||
function getInsertSql(tb: TGApp.Sqlite.UserBag.MaterialRaw): string {
|
||||
return `
|
||||
INSERT INTO UserBagMaterial(uid, id, count, records, updated)
|
||||
VALUES (${tb.uid}, ${tb.id}, ${tb.count}, '${tb.records}', '${tb.updated}') ON CONFLICT(uid, id) DO
|
||||
UPDATE
|
||||
SET count = ${tb.count},
|
||||
records = '${tb.records}',
|
||||
updated = '${tb.updated}';
|
||||
VALUES (${tb.uid}, ${tb.id}, ${tb.count}, '${tb.records}', '${tb.updated}')
|
||||
ON CONFLICT(uid, id) DO UPDATE
|
||||
SET count = ${tb.count},
|
||||
records = '${tb.records}',
|
||||
updated = '${tb.updated}';
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -192,6 +190,11 @@ async function saveYaeData(
|
||||
): Promise<number> {
|
||||
let skip = 0;
|
||||
const ids = new Set<number>(getValidMIds());
|
||||
// 移除货币数据
|
||||
ids.delete(201);
|
||||
ids.delete(202);
|
||||
ids.delete(203);
|
||||
ids.delete(204);
|
||||
const newList = list;
|
||||
for (const item of list) if (ids.has(item.item_id)) ids.delete(item.item_id);
|
||||
// 处理0数据
|
||||
@@ -215,10 +218,30 @@ async function saveYaeData(
|
||||
return skip;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存货币数据
|
||||
* @since Beta v0.9.1
|
||||
* @param uid - 存档UID
|
||||
* @param id - 货币ID
|
||||
* @param cnt - 货币数量
|
||||
* @returns 无返回值
|
||||
*/
|
||||
async function saveYaeCoin(uid: number, id: number, cnt: number): Promise<void> {
|
||||
const read = await getMaterial(uid, id);
|
||||
if (read.length === 0) {
|
||||
await insertMaterial(uid, id, cnt);
|
||||
return;
|
||||
}
|
||||
const local = read[0];
|
||||
if (cnt === local.count) return;
|
||||
await insertMaterial(uid, id, cnt, local.records);
|
||||
}
|
||||
|
||||
const TSUserBagMaterial = {
|
||||
getAllUid,
|
||||
delUid,
|
||||
saveYaeData,
|
||||
saveYaeCoin,
|
||||
getMaterial,
|
||||
insertMaterial,
|
||||
getValidMIds,
|
||||
|
||||
14
src/types/Plugins/Yae.d.ts
vendored
14
src/types/Plugins/Yae.d.ts
vendored
@@ -1,18 +1,18 @@
|
||||
/**
|
||||
* Yae 插件类型定义
|
||||
* @since Beta v0.9.0
|
||||
* @since Beta v0.9.1
|
||||
*/
|
||||
|
||||
declare namespace TGApp.Plugins.Yae {
|
||||
/**
|
||||
* 后端返的事件数据
|
||||
* @since Beta v0.9.0
|
||||
* @since Beta v0.9.1
|
||||
*/
|
||||
type RsEvent = {
|
||||
/** 数据,序列化后的JSON */
|
||||
data: string;
|
||||
/** 类型,成就或背包 */
|
||||
type: "achievement" | "store";
|
||||
/** 类型,成就或背包或属性 */
|
||||
type: "achievement" | "store" | "prop";
|
||||
/** 存档UID,需要预先输入 */
|
||||
uid: string;
|
||||
};
|
||||
@@ -29,6 +29,12 @@ declare namespace TGApp.Plugins.Yae {
|
||||
*/
|
||||
type BagListRes = Array<BagItemUnion>;
|
||||
|
||||
/**
|
||||
* 后端返回的属性数据
|
||||
* @since Beta v0.9.1
|
||||
*/
|
||||
type PropRes = Record<number, number>;
|
||||
|
||||
/**
|
||||
* 背包物品类型
|
||||
* @since Beta v0.9.0
|
||||
|
||||
Reference in New Issue
Block a user