mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-29 06:09:45 +08:00
♻️ 统一uid选取逻辑
This commit is contained in:
@@ -91,6 +91,7 @@ import TuaAchiList from "@comp/userAchi/tua-achi-list.vue";
|
||||
import TuaSeries from "@comp/userAchi/tua-series.vue";
|
||||
import TSUserAchi from "@Sqlm/userAchi.js";
|
||||
import useAppStore from "@store/app.js";
|
||||
import useUserStore from "@store/user.js";
|
||||
import { path } from "@tauri-apps/api";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { listen, type UnlistenFn } from "@tauri-apps/api/event";
|
||||
@@ -114,7 +115,8 @@ const seriesList = AppAchievementSeriesData.sort((a, b) => a.order - b.order).ma
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const { gameDir, isInAdmin } = storeToRefs(useAppStore());
|
||||
const { gameDir, isInAdmin, isLogin } = storeToRefs(useAppStore());
|
||||
const { account } = storeToRefs(useUserStore());
|
||||
|
||||
let achiListener: UnlistenFn | null = null;
|
||||
|
||||
@@ -134,9 +136,7 @@ onMounted(async () => {
|
||||
await showLoading.start("正在加载成就数据");
|
||||
await TGLogger.Info("[Achievements][onMounted] 打开成就页面");
|
||||
await showLoading.update("正在读取UID列表");
|
||||
uidList.value = await TSUserAchi.getAllUid();
|
||||
if (uidList.value.length === 0) uidList.value = [0];
|
||||
uidCur.value = uidList.value[0];
|
||||
await reloadUid();
|
||||
await showLoading.update("正在获取成就概况");
|
||||
await refreshOverview();
|
||||
await showLoading.end();
|
||||
@@ -155,6 +155,16 @@ onUnmounted(async () => {
|
||||
|
||||
watch(() => uidCur.value, refreshOverview);
|
||||
|
||||
async function reloadUid(): Promise<void> {
|
||||
uidList.value = await TSUserAchi.getAllUid();
|
||||
if (uidList.value.includes(account.value.gameUid)) uidCur.value = account.value.gameUid;
|
||||
else if (uidList.value.length > 0) uidCur.value = uidList.value[0];
|
||||
else if (isLogin.value) {
|
||||
uidList.value = [account.value.gameUid];
|
||||
uidCur.value = account.value.gameUid;
|
||||
} else uidCur.value = 0;
|
||||
}
|
||||
|
||||
function switchHideFin(): void {
|
||||
const text = hideFin.value ? "显示已完成" : "隐藏已完成";
|
||||
hideFin.value = !hideFin.value;
|
||||
@@ -299,9 +309,7 @@ async function deleteUid(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
await TSUserAchi.delUid(uidCur.value);
|
||||
uidList.value = uidList.value.filter((e) => e !== uidCur.value);
|
||||
if (uidList.value.length === 0) uidList.value = [0];
|
||||
uidCur.value = uidList.value[0];
|
||||
await reloadUid();
|
||||
}
|
||||
|
||||
async function toYae(): Promise<void> {
|
||||
|
||||
@@ -105,6 +105,7 @@ import PbMaterialItem from "@comp/pageBag/pb-materialItem.vue";
|
||||
import PboMaterial from "@comp/pageBag/pbo-material.vue";
|
||||
import TSUserBagMaterial from "@Sqlm/userBagMaterial.js";
|
||||
import useAppStore from "@store/app.js";
|
||||
import useUserStore from "@store/user.js";
|
||||
import { path } from "@tauri-apps/api";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { exists } from "@tauri-apps/plugin-fs";
|
||||
@@ -130,7 +131,8 @@ export type MaterialInfo = {
|
||||
info: TGApp.App.Material.WikiItem;
|
||||
};
|
||||
|
||||
const { gameDir, isInAdmin } = storeToRefs(useAppStore());
|
||||
const { gameDir, isInAdmin, isLogin } = storeToRefs(useAppStore());
|
||||
const { account } = storeToRefs(useUserStore());
|
||||
|
||||
const curUid = ref<number>(0);
|
||||
const selectType = ref<string | null>(null);
|
||||
@@ -145,11 +147,8 @@ const materialShow = shallowRef<Array<MaterialInfo>>([]);
|
||||
|
||||
onMounted(async () => {
|
||||
await showLoading.start("正在获取存档列表...");
|
||||
uidList.value = await TSUserBagMaterial.getAllUid();
|
||||
await showLoading.update(`存档数:${uidList.value.length}`);
|
||||
// TODO: 如果用户已登录,优先当前登录UID
|
||||
if (uidList.value.length > 0) curUid.value = uidList.value[0];
|
||||
else await showLoading.end();
|
||||
await reloadUid();
|
||||
await showLoading.end();
|
||||
});
|
||||
|
||||
watch(
|
||||
@@ -168,6 +167,17 @@ watch(
|
||||
},
|
||||
);
|
||||
|
||||
async function reloadUid(): Promise<void> {
|
||||
uidList.value = await TSUserBagMaterial.getAllUid();
|
||||
if (uidList.value.includes(Number(account.value.gameUid))) {
|
||||
curUid.value = Number(account.value.gameUid);
|
||||
} else if (uidList.value.length > 0) curUid.value = uidList.value[0];
|
||||
else if (isLogin.value) {
|
||||
uidList.value = [Number(account.value.gameUid)];
|
||||
curUid.value = Number(account.value.gameUid);
|
||||
} else curUid.value = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对应类别下的材料列表
|
||||
* @return {Array<MaterialInfo>}
|
||||
@@ -342,12 +352,8 @@ async function deleteUid(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
await TSUserBagMaterial.delUid(curUid.value);
|
||||
uidList.value = uidList.value.filter((e) => e !== curUid.value);
|
||||
if (uidList.value.length === 0) uidList.value = [0];
|
||||
curUid.value = uidList.value[0];
|
||||
await reloadUid();
|
||||
showSnackbar.success(`已删除对应存档,即将刷新`);
|
||||
await new Promise<void>((resolve) => setTimeout(resolve, 1000));
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user