mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-13 09:28:14 +08:00
✨ 实装祈愿记录获取
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
<template>
|
||||
<ToLoading v-model="loading" :title="loadingTitle" />
|
||||
<ToLoading v-model="loading" :title="loadingTitle" :subtitle="loadingSub" />
|
||||
<div class="gacha-top-bar">
|
||||
<div class="gacha-top-title">祈愿记录</div>
|
||||
<v-select v-model="uidCur" class="gacha-top-select" :items="selectItem" variant="outlined" />
|
||||
<div class="gacha-top-btns">
|
||||
<v-btn prepend-icon="mdi-refresh" class="gacha-top-btn" @click="confirmRefresh">刷新</v-btn>
|
||||
<v-btn prepend-icon="mdi-import" class="gacha-top-btn" @click="handleImportBtn()">
|
||||
导入
|
||||
</v-btn>
|
||||
@@ -49,13 +50,23 @@ import GroEcharts from "../../components/gachaRecord/gro-echarts.vue";
|
||||
import GroOverview from "../../components/gachaRecord/gro-overview.vue";
|
||||
// tauri
|
||||
import { dialog, path } from "@tauri-apps/api";
|
||||
// store
|
||||
import { useUserStore } from "../../store/modules/user";
|
||||
// utils
|
||||
import { backupUigfData, exportUigfData, readUigfData, verifyUigfData } from "../../utils/UIGF";
|
||||
import TGSqlite from "../../plugins/Sqlite";
|
||||
import TGRequest from "../../web/request/TGRequest";
|
||||
import { AppCharacterData, AppWeaponData } from "../../data";
|
||||
|
||||
// store
|
||||
const userStore = useUserStore();
|
||||
const account = userStore.getCurAccount();
|
||||
const authkey = ref<string>("");
|
||||
|
||||
// loading
|
||||
const loading = ref<boolean>(true);
|
||||
const loadingTitle = ref<string>();
|
||||
const loadingSub = ref<string>();
|
||||
|
||||
// data
|
||||
const selectItem = ref<string[]>([]);
|
||||
@@ -85,6 +96,88 @@ onMounted(async () => {
|
||||
});
|
||||
});
|
||||
|
||||
// 刷新按钮点击事件
|
||||
async function confirmRefresh(): Promise<void> {
|
||||
const confirmRes = await showConfirm({
|
||||
title: "是否刷新祈愿数据?",
|
||||
text: `将刷新 UID:${account.gameUid} 的祈愿数据`,
|
||||
});
|
||||
if (!confirmRes) {
|
||||
showSnackbar({
|
||||
color: "grey",
|
||||
text: `已取消刷新祈愿数据`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
loadingTitle.value = "正在获取 authkey";
|
||||
loading.value = true;
|
||||
const cookie = {
|
||||
stoken: userStore.cookie.stoken,
|
||||
mid: userStore.cookie.mid,
|
||||
};
|
||||
const gameUid = userStore.getCurAccount().gameUid;
|
||||
const authkeyRes = await TGRequest.User.getAuthkey(cookie, gameUid);
|
||||
if (typeof authkeyRes === "string") {
|
||||
authkey.value = authkeyRes;
|
||||
} else {
|
||||
showSnackbar({
|
||||
color: "error",
|
||||
text: `获取 authkey 失败`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
loadingTitle.value = "正在刷新新手祈愿数据";
|
||||
await getGachaLogs("100");
|
||||
loadingTitle.value = "正在刷新常驻祈愿数据";
|
||||
await getGachaLogs("200");
|
||||
loadingTitle.value = "正在刷新角色祈愿数据";
|
||||
await getGachaLogs("301");
|
||||
loadingTitle.value = "正在刷新角色祈愿2数据";
|
||||
await getGachaLogs("400");
|
||||
loadingTitle.value = "正在刷新武器祈愿数据";
|
||||
await getGachaLogs("302");
|
||||
loadingTitle.value = "数据获取完成,即将刷新页面";
|
||||
loadingSub.value = "";
|
||||
loading.value = false;
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
// 获取祈愿数据并写入数据库
|
||||
async function getGachaLogs(pool: string, endId: string = "0"): Promise<void> {
|
||||
const gachaRes = await TGRequest.User.getGachaLog(authkey.value, pool, endId);
|
||||
if (Array.isArray(gachaRes)) {
|
||||
const uigfList: TGApp.Plugins.UIGF.GachaItem[] = [];
|
||||
gachaRes.forEach((item) => {
|
||||
loadingSub.value = `[${item.item_type}][${item.time}] ${item.name}`;
|
||||
const tempItem: TGApp.Plugins.UIGF.GachaItem = {
|
||||
gacha_type: item.gacha_type,
|
||||
item_id: item.item_id,
|
||||
count: item.count,
|
||||
time: item.time,
|
||||
name: item.name,
|
||||
item_type: item.item_type,
|
||||
rank_type: item.rank_type,
|
||||
id: item.id,
|
||||
uigf_gacha_type: item.gacha_type === "400" ? "301" : item.gacha_type,
|
||||
};
|
||||
if (item.item_type === "角色") {
|
||||
const find = AppCharacterData.find((char) => char.name === item.name);
|
||||
if (find) tempItem.item_id = find.id.toString();
|
||||
} else if (item.item_type === "武器") {
|
||||
const find = AppWeaponData.find((weapon) => weapon.name === item.name);
|
||||
if (find) tempItem.item_id = find.id.toString();
|
||||
}
|
||||
uigfList.push(tempItem);
|
||||
});
|
||||
await TGSqlite.mergeUIGF(account.gameUid, uigfList);
|
||||
if (gachaRes.length === 20) {
|
||||
await getGachaLogs(pool, gachaRes[gachaRes.length - 1].id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 导入按钮点击事件
|
||||
async function handleImportBtn(savePath?: string): Promise<void> {
|
||||
let selectedFile;
|
||||
|
||||
49
src/types/Game/Gacha.d.ts
vendored
49
src/types/Game/Gacha.d.ts
vendored
@@ -23,4 +23,53 @@ declare namespace TGApp.Game.Gacha {
|
||||
authkey: string;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取抽卡记录返回类型
|
||||
* @interface GachaLogResponse
|
||||
* @since Beta v0.3.0
|
||||
* @extends TGApp.BBS.Response.Base
|
||||
* @property {number} data.page - 页码
|
||||
* @property {number} data.size - 每页大小
|
||||
* @property {number} data.total - 总数
|
||||
* @property {GachaItem[]} data.list - 抽卡记录列表
|
||||
* @return GachaLogResponse
|
||||
*/
|
||||
export interface GachaLogResponse extends TGApp.BBS.Response.Base {
|
||||
data: {
|
||||
page: number;
|
||||
size: number;
|
||||
total: number;
|
||||
list: GachaItem[];
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 抽卡记录类型
|
||||
* @interface GachaItem
|
||||
* @since Beta v0.3.0
|
||||
* @property {string} uid - 用户 uid
|
||||
* @property {string} gacha_type - 抽卡类型 // 100: 新手祈愿, 200: 常驻祈愿, 301: 角色活动祈愿, 302: 武器活动祈愿 400:角色活动祈愿2
|
||||
* @property {string} item_id - 物品 id // todo:一般为 "",需要自己添加
|
||||
* @property {string} count - 数量
|
||||
* @property {string} time - 时间 // yyyy-MM-dd HH:mm:ss
|
||||
* @property {string} name - 物品名称
|
||||
* @property {string} lang - 语言
|
||||
* @property {string} item_type - 物品类型 // “武器” “角色”
|
||||
* @property {string} rank_type - 星级
|
||||
* @property {string} id - 抽卡记录 id
|
||||
* @return GachaItem
|
||||
*/
|
||||
export interface GachaItem {
|
||||
uid: string;
|
||||
gacha_type: string;
|
||||
item_id: string;
|
||||
count: string;
|
||||
time: string;
|
||||
name: string;
|
||||
lang: string;
|
||||
item_type: string;
|
||||
rank_type: string;
|
||||
id: string;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
* @file utils UIGF.ts
|
||||
* @description UIGF工具类
|
||||
* @author BTMuli <bt-muli@outlook.com>
|
||||
* @since Alpha v0.2.3
|
||||
* @since Beta v0.3.0
|
||||
*/
|
||||
|
||||
// tauri
|
||||
import { app, fs, path } from "@tauri-apps/api";
|
||||
// utils
|
||||
import TGSqlite from "../plugins/Sqlite";
|
||||
import { timestampToDate } from "./t2D";
|
||||
|
||||
/**
|
||||
@@ -113,19 +112,3 @@ export async function backupUigfData(
|
||||
const savePath = `${await path.appLocalDataDir()}userData\\UIGF_${uid}.json`;
|
||||
await exportUigfData(uid, gachaList, savePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 恢复 UIGF 数据
|
||||
* @since Alpha v0.2.3
|
||||
* @param {string} uid - UID
|
||||
* @returns {Promise<boolean>} UIGF 数据
|
||||
*/
|
||||
export async function restoreUigfData(uid: string): Promise<boolean> {
|
||||
const uigfPath = `${await path.appLocalDataDir()}userData\\UIGF_${uid}.json`;
|
||||
if (!(await fs.exists(uigfPath))) {
|
||||
return false;
|
||||
}
|
||||
const uigfData = await readUigfData(uigfPath);
|
||||
await TGSqlite.mergeUIGF(uid, uigfData.list);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
|
||||
import { genAuthkey } from "./genAuthkey";
|
||||
import { getAbyss } from "./getAbyss";
|
||||
import { getAnnoList, getAnnoContent } from "./getAnno";
|
||||
import { getAnnoContent, getAnnoList } from "./getAnno";
|
||||
import { getCookieTokenByGameToken, getCookieTokenBySToken } from "./getCookieToken";
|
||||
// import * from "./getEnkaData.ts";
|
||||
import { getGameAccountsBySToken, getGameAccountsByCookie } from "./getGameAccounts";
|
||||
import { getGachaLog } from "./getGachaLog";
|
||||
import { getGameAccountsByCookie, getGameAccountsBySToken } from "./getGameAccounts";
|
||||
import { getGameRecord } from "./getGameRecord";
|
||||
import { getLTokenBySToken } from "./getLToken";
|
||||
import { getGameRoleListByLToken } from "./getRoleList";
|
||||
@@ -28,6 +29,7 @@ const TGRequest = {
|
||||
},
|
||||
User: {
|
||||
getAuthkey: genAuthkey,
|
||||
getGachaLog,
|
||||
getRecord: getGameRecord,
|
||||
byLoginTicket: {
|
||||
getTokens: getTokensByLoginTicket,
|
||||
|
||||
44
src/web/request/getGachaLog.ts
Normal file
44
src/web/request/getGachaLog.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* @file web request getGachaLog.ts
|
||||
* @description 获取抽卡记录请求函数
|
||||
* @author BTMuli <bt-muli@outlook.com>
|
||||
* @since Beta v0.3.0
|
||||
*/
|
||||
|
||||
// tauri
|
||||
import { http } from "@tauri-apps/api";
|
||||
|
||||
/**
|
||||
* @description 获取抽卡记录
|
||||
* @since Beta v0.3.0
|
||||
* @param {string} authkey authkey
|
||||
* @param {string} gachaType 抽卡类型
|
||||
* @param {string} endId 结束 id,默认为 0
|
||||
* @returns {Promise<TGApp.Game.Gacha.GachaItem[] | TGApp.BBS.Response.Base>} 抽卡记录
|
||||
*/
|
||||
export async function getGachaLog(
|
||||
authkey: string,
|
||||
gachaType: string,
|
||||
endId: string = "0",
|
||||
): Promise<TGApp.Game.Gacha.GachaItem[] | TGApp.BBS.Response.Base> {
|
||||
const url = "https://hk4e-api.mihoyo.com/event/gacha_info/api/getGachaLog";
|
||||
const params = {
|
||||
lang: "zh-cn",
|
||||
auth_appid: "webview_gacha",
|
||||
authkey,
|
||||
authkey_ver: "1",
|
||||
sign_type: "2",
|
||||
gacha_type: gachaType,
|
||||
size: "20",
|
||||
end_id: endId,
|
||||
};
|
||||
return await http
|
||||
.fetch<TGApp.Game.Gacha.GachaLogResponse>(url, {
|
||||
method: "GET",
|
||||
query: params,
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.data.retcode === 0) return res.data.data.list;
|
||||
return res.data;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user