🐛 修复用户数据缺失

This commit is contained in:
BTMuli
2023-09-07 15:46:48 +08:00
parent 2a696d77b4
commit fcb158a7eb
3 changed files with 14 additions and 12 deletions

View File

@@ -56,6 +56,7 @@ import { generateShareImg } from "../../utils/TGShare";
// store // store
const userStore = useUserStore(); const userStore = useUserStore();
const user = userStore.getCurAccount();
// loading // loading
const loading = ref<boolean>(false); const loading = ref<boolean>(false);
@@ -66,7 +67,6 @@ const loadingSub = ref<string>();
const isEmpty = ref(true); const isEmpty = ref(true);
const roleList = ref<TGApp.Sqlite.Character.UserRole[]>([]); const roleList = ref<TGApp.Sqlite.Character.UserRole[]>([]);
const roleCookie = computed(() => userStore.getCookieGroup4()); const roleCookie = computed(() => userStore.getCookieGroup4());
const user = computed(() => userStore.getCurAccount());
// overlay // overlay
const visible = ref(false); const visible = ref(false);
@@ -94,7 +94,7 @@ function getGridGap(): void {
} }
async function loadRole(): Promise<void> { async function loadRole(): Promise<void> {
const roleData = await TGSqlite.getUserCharacter(user.value.gameUid); const roleData = await TGSqlite.getUserCharacter(user.gameUid);
if (roleData !== false) { if (roleData !== false) {
roleList.value = roleData; roleList.value = roleData;
isEmpty.value = false; isEmpty.value = false;
@@ -104,10 +104,10 @@ async function loadRole(): Promise<void> {
async function refreshRoles(): Promise<void> { async function refreshRoles(): Promise<void> {
loadingTitle.value = "正在获取角色数据"; loadingTitle.value = "正在获取角色数据";
loading.value = true; loading.value = true;
const res = await TGRequest.User.byLToken.getRoleList(roleCookie.value, user.value); const res = await TGRequest.User.byLToken.getRoleList(roleCookie.value, user);
if (Array.isArray(res)) { if (Array.isArray(res)) {
loadingTitle.value = "正在保存角色数据"; loadingTitle.value = "正在保存角色数据";
await TGSqlite.saveUserCharacter(user.value.gameUid, res); await TGSqlite.saveUserCharacter(user.gameUid, res);
loadingTitle.value = "正在更新角色数据"; loadingTitle.value = "正在更新角色数据";
await loadRole(); await loadRole();
} }
@@ -123,7 +123,7 @@ async function refreshTalent(): Promise<void> {
loadingSub.value = `CID${role.cid}`; loadingSub.value = `CID${role.cid}`;
const res = await TGRequest.User.calculate.getSyncAvatarDetail( const res = await TGRequest.User.calculate.getSyncAvatarDetail(
talentCookie, talentCookie,
user.value.gameUid, user.gameUid,
role.cid, role.cid,
); );
if ("skill_list" in res) { if ("skill_list" in res) {
@@ -138,7 +138,7 @@ async function refreshTalent(): Promise<void> {
icon: skill.icon, icon: skill.icon,
}); });
}); });
await TGSqlite.saveUserCharacterTalent(user.value.gameUid, role.cid, talent); await TGSqlite.saveUserCharacterTalent(user.gameUid, role.cid, talent);
} else { } else {
loadingTitle.value = `获取${role.name}的天赋数据失败`; loadingTitle.value = `获取${role.name}的天赋数据失败`;
loadingSub.value = `[${res.retcode}] ${res.message}`; loadingSub.value = `[${res.retcode}] ${res.message}`;
@@ -158,7 +158,7 @@ async function refreshTalent(): Promise<void> {
async function shareRoles(): Promise<void> { async function shareRoles(): Promise<void> {
const rolesBox = <HTMLElement>document.querySelector(".uc-box"); const rolesBox = <HTMLElement>document.querySelector(".uc-box");
const fileName = `【角色列表】-${user.value.gameUid}`; const fileName = `【角色列表】-${user.gameUid}`;
loadingTitle.value = "正在生成图片"; loadingTitle.value = "正在生成图片";
loadingSub.value = `${fileName}.png`; loadingSub.value = `${fileName}.png`;
loading.value = true; loading.value = true;

View File

@@ -50,6 +50,7 @@ import showSnackbar from "../../components/func/snackbar";
// store // store
const userStore = useUserStore(); const userStore = useUserStore();
const user = userStore.getCurAccount();
// loading // loading
const loading = ref<boolean>(false); const loading = ref<boolean>(false);
@@ -60,7 +61,6 @@ const loadingSub = ref<string>();
const isEmpty = ref<boolean>(true); const isEmpty = ref<boolean>(true);
const recordData = ref<TGApp.Sqlite.Record.SingleTable>(<TGApp.Sqlite.Record.SingleTable>{}); const recordData = ref<TGApp.Sqlite.Record.SingleTable>(<TGApp.Sqlite.Record.SingleTable>{});
const recordCookie = computed<TGApp.BBS.Constant.CookieGroup2>(() => userStore.getCookieGroup2()); const recordCookie = computed<TGApp.BBS.Constant.CookieGroup2>(() => userStore.getCookieGroup2());
const user = computed<TGApp.Sqlite.Account.Game>(() => userStore.getCurAccount());
onMounted(async () => { onMounted(async () => {
loadingTitle.value = "正在加载战绩数据"; loadingTitle.value = "正在加载战绩数据";
@@ -73,7 +73,7 @@ onMounted(async () => {
}); });
async function initUserRecordData(): Promise<void> { async function initUserRecordData(): Promise<void> {
const recordGet = await TGSqlite.getUserRecord(user.value.gameUid); const recordGet = await TGSqlite.getUserRecord(user.gameUid);
if (recordGet !== false) { if (recordGet !== false) {
recordData.value = recordGet; recordData.value = recordGet;
isEmpty.value = false; isEmpty.value = false;
@@ -85,11 +85,11 @@ async function initUserRecordData(): Promise<void> {
async function refresh(): Promise<void> { async function refresh(): Promise<void> {
loadingTitle.value = "正在获取战绩数据"; loadingTitle.value = "正在获取战绩数据";
loading.value = true; loading.value = true;
const res = await TGRequest.User.getRecord(recordCookie.value, user.value); const res = await TGRequest.User.getRecord(recordCookie.value, user);
if (!("retcode" in res)) { if (!("retcode" in res)) {
console.log(res); console.log(res);
loadingTitle.value = "正在保存战绩数据"; loadingTitle.value = "正在保存战绩数据";
await TGSqlite.saveUserRecord(res, user.value.gameUid); await TGSqlite.saveUserRecord(res, user.gameUid);
await initUserRecordData(); await initUserRecordData();
} else { } else {
showSnackbar({ showSnackbar({
@@ -107,7 +107,7 @@ function getTitle(): string {
async function shareRecord(): Promise<void> { async function shareRecord(): Promise<void> {
const recordBox = <HTMLElement>document.querySelector(".ur-box"); const recordBox = <HTMLElement>document.querySelector(".ur-box");
const fileName = `【原神战绩】-${user.value.gameUid}`; const fileName = `【原神战绩】-${user.gameUid}`;
loadingTitle.value = "正在生成图片"; loadingTitle.value = "正在生成图片";
loadingSub.value = `${fileName}.png`; loadingSub.value = `${fileName}.png`;
loading.value = true; loading.value = true;

View File

@@ -311,6 +311,8 @@ async function confirmRefreshUser(): Promise<void> {
if (Array.isArray(accountRes)) { if (Array.isArray(accountRes)) {
loadingTitle.value = "获取成功!正在保存到数据库!"; loadingTitle.value = "获取成功!正在保存到数据库!";
await TGSqlite.saveAccount(accountRes); await TGSqlite.saveAccount(accountRes);
const curAccount = await TGSqlite.getCurAccount();
if (curAccount) userStore.setCurAccount(curAccount);
} else { } else {
console.error(accountRes); console.error(accountRes);
loadingTitle.value = "获取失败!"; loadingTitle.value = "获取失败!";