♻️ 统一uid选取逻辑

This commit is contained in:
BTMuli
2025-12-22 20:24:11 +08:00
parent faacc856de
commit 88cd657525
10 changed files with 139 additions and 92 deletions

View File

@@ -112,6 +112,7 @@ import TuaDetail from "@comp/userAbyss/tua-detail.vue";
import TuaOverview from "@comp/userAbyss/tua-overview.vue";
import recordReq from "@req/recordReq.js";
import TSUserAbyss from "@Sqlm/userAbyss.js";
import useAppStore from "@store/app.js";
import useUserStore from "@store/user.js";
import { getVersion } from "@tauri-apps/api/app";
import { open } from "@tauri-apps/plugin-dialog";
@@ -123,6 +124,7 @@ import { onMounted, ref, shallowRef, watch } from "vue";
import { useRouter } from "vue-router";
const router = useRouter();
const { isLogin } = storeToRefs(useAppStore());
const { account, cookie } = storeToRefs(useUserStore());
const userTab = ref<number>(0);
const version = ref<string>();
@@ -135,10 +137,7 @@ onMounted(async () => {
version.value = await getVersion();
await TGLogger.Info("[UserAbyss][onMounted] 打开角色深渊页面");
await showLoading.update("正在获取UID列表");
uidList.value = await TSUserAbyss.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 uidCur.value = "";
await reloadUid();
await showLoading.update(`正在加载${uidCur.value}的深渊数据`);
await showLoading.end();
showSnackbar.success(`已加载${uidCur.value}${localAbyss.value.length}条深渊数据`);
@@ -146,6 +145,16 @@ onMounted(async () => {
watch(() => uidCur.value, loadAbyss);
async function reloadUid(): Promise<void> {
uidList.value = await TSUserAbyss.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 = undefined;
}
async function toCombat(): Promise<void> {
await router.push({ name: "真境剧诗" });
}
@@ -218,8 +227,7 @@ async function refreshAbyss(): Promise<void> {
await TSUserAbyss.saveAbyss(account.value.gameUid, res);
await TGLogger.Info(`[UserAbyss][getAbyssData] 成功获取${account.value.gameUid}的本期深渊数据`);
await showLoading.update("正在加载深渊数据");
uidList.value = await TSUserAbyss.getAllUid();
uidCur.value = account.value.gameUid;
await reloadUid();
await loadAbyss();
await showLoading.end();
showSnackbar.success(`已加载${account.value.gameUid}${localAbyss.value.length}条深渊数据`);
@@ -254,9 +262,7 @@ async function deleteAbyss(): Promise<void> {
await TSUserAbyss.delAbyss(uidCur.value);
await showLoading.end();
showSnackbar.success(`已清除 ${uidCur.value} 的深渊数据`);
uidList.value = await TSUserAbyss.getAllUid();
if (uidList.value.length > 0) uidCur.value = uidList.value[0];
else uidCur.value = undefined;
await reloadUid();
await loadAbyss();
}

View File

@@ -142,6 +142,7 @@ import TucPopItem from "@comp/userChallenge/tuc-pop-item.vue";
import { GameServerEnum, getGameServerDesc } from "@enum/game.js";
import recordReq from "@req/recordReq.js";
import TSUserChallenge from "@Sqlm/userChallenge.js";
import useAppStore from "@store/app.js";
import useUserStore from "@store/user.js";
import { getVersion } from "@tauri-apps/api/app";
import { open } from "@tauri-apps/plugin-dialog";
@@ -164,6 +165,7 @@ const serverList: ReadonlyArray<SelectItem<TGApp.Game.Base.ServerTypeEnum>> = [
].map((i) => ({ text: getGameServerDesc(i), value: i }));
const router = useRouter();
const { isLogin } = storeToRefs(useAppStore());
const { account, cookie } = storeToRefs(useUserStore());
const version = ref<string>();
@@ -238,13 +240,13 @@ async function shareChallenge(): Promise<void> {
async function reloadChallenge(): Promise<void> {
await showLoading.start("正在加载UID列表");
uidList.value = await TSUserChallenge.getAllUid();
if (uidList.value.length === 0) {
uidCur.value = "";
} else {
if (uidCur.value === undefined || uidCur.value === "") {
if (uidList.value.includes(account.value.gameUid)) uidCur.value = account.value.gameUid;
else uidCur.value = uidList.value[0];
}
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 = undefined;
if (uidCur.value) {
await showLoading.update(`正在加载UID${uidCur.value}的幽境危战数据`);
await loadChallenge();
}
@@ -316,7 +318,6 @@ async function refreshChallenge(): Promise<void> {
await TSUserChallenge.saveChallenge(account.value.gameUid, challenge);
}
isReq.value = false;
// await showLoading.end();
uidCur.value = account.value.gameUid;
await reloadChallenge();
}

View File

@@ -119,6 +119,7 @@ import TuaAvatarBox from "@comp/userAvatar/tua-avatar-box.vue";
import TuaDetailOverlay from "@comp/userAvatar/tua-detail-overlay.vue";
import recordReq from "@req/recordReq.js";
import TSUserAvatar from "@Sqlm/userAvatar.js";
import useAppStore from "@store/app.js";
import useUserStore from "@store/user.js";
import { getVersion } from "@tauri-apps/api/app";
import TGLogger from "@utils/TGLogger.js";
@@ -137,7 +138,10 @@ const modeList: Readonly<Array<TabItem>> = [
{ label: "卡片视图(简略)", value: "card" },
{ label: "卡片视图(详细)", value: "dev" },
];
const { isLogin } = storeToRefs(useAppStore());
const { cookie, account, propMap } = storeToRefs(useUserStore());
const loadData = ref<boolean>(false);
const loadShare = ref<boolean>(false);
const loadDel = ref<boolean>(false);
@@ -227,9 +231,12 @@ function getOverview(data: Array<TGApp.Sqlite.Character.UserRole>): Array<Overvi
async function loadUid(): Promise<void> {
uidList.value = await TSUserAvatar.getAllUid();
if (uidList.value.length === 0) uidList.value = [account.value.gameUid];
if (uidList.value.includes(account.value.gameUid)) uidCur.value = account.value.gameUid;
else uidCur.value = uidList.value[0];
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 = undefined;
}
async function loadRole(): Promise<void> {

View File

@@ -108,6 +108,7 @@ import TucOverview from "@comp/userCombat/tuc-overview.vue";
import TucRound from "@comp/userCombat/tuc-round.vue";
import recordReq from "@req/recordReq.js";
import TSUserCombat from "@Sqlm/userCombat.js";
import useAppStore from "@store/app.js";
import useUserStore from "@store/user.js";
import { getVersion } from "@tauri-apps/api/app";
import { open } from "@tauri-apps/plugin-dialog";
@@ -119,6 +120,7 @@ import { onMounted, ref, shallowRef, watch } from "vue";
import { useRouter } from "vue-router";
const router = useRouter();
const { isLogin } = storeToRefs(useAppStore());
const { account, cookie } = storeToRefs(useUserStore());
const userTab = ref<number>(0);
const version = ref<string>();
@@ -131,15 +133,11 @@ onMounted(async () => {
version.value = await getVersion();
await TGLogger.Info("[UserCombat][onMounted] 打开真境剧诗页面");
await showLoading.update("正在加载UID列表");
uidList.value = await TSUserCombat.getAllUid();
if (uidList.value.length === 0) {
uidCur.value = "";
} else {
if (uidList.value.includes(account.value.gameUid)) uidCur.value = account.value.gameUid;
else uidCur.value = uidList.value[0];
await reloadUid();
if (uidCur.value) {
await showLoading.update(`正在加载UID${uidCur.value}的剧诗数据`);
await loadCombat();
}
await loadCombat();
await showLoading.end();
});
@@ -153,6 +151,16 @@ async function toChallenge(): Promise<void> {
await router.push({ name: "幽境危战" });
}
async function reloadUid(): Promise<void> {
uidList.value = await TSUserCombat.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 = undefined;
}
async function loadCombat(): Promise<void> {
localCombat.value = [];
if (uidCur.value === undefined || uidCur.value === "") return;
@@ -207,8 +215,7 @@ async function refreshCombat(): Promise<void> {
await TSUserCombat.saveCombat(account.value.gameUid, combat);
}
await showLoading.update("正在加载剧诗数据");
uidList.value = await TSUserCombat.getAllUid();
uidCur.value = account.value.gameUid;
await reloadUid();
await loadCombat();
await showLoading.end();
}
@@ -242,9 +249,7 @@ async function deleteCombat(): Promise<void> {
await TSUserCombat.delCombat(uidCur.value);
showSnackbar.success(`已清除 ${uidCur.value} 的剧诗数据`);
await showLoading.update("正在加载剧诗数据");
uidList.value = await TSUserCombat.getAllUid();
if (uidList.value.length > 0) uidCur.value = uidList.value[0];
else uidCur.value = undefined;
await reloadUid();
await loadCombat();
await showLoading.end();
}

View File

@@ -45,8 +45,9 @@
prepend-icon="mdi-import"
variant="elevated"
@click="importUigf()"
>导入</v-btn
>
导入
</v-btn>
<v-btn
class="gacha-top-btn"
prepend-icon="mdi-import"
@@ -60,8 +61,9 @@
prepend-icon="mdi-export"
variant="elevated"
@click="exportUigf()"
>导出</v-btn
>
导出
</v-btn>
<v-btn
class="gacha-top-btn"
prepend-icon="mdi-export"
@@ -75,8 +77,9 @@
prepend-icon="mdi-delete"
variant="elevated"
@click="deleteGacha()"
>删除</v-btn
>
删除
</v-btn>
<v-btn
class="gacha-top-btn"
prepend-icon="mdi-database-check"
@@ -131,7 +134,7 @@ import UgoUid from "@comp/userGacha/ugo-uid.vue";
import hk4eReq from "@req/hk4eReq.js";
import takumiReq from "@req/takumiReq.js";
import TSUserGacha from "@Sqlm/userGacha.js";
// import useAppStore from "@store/app.js";
import useAppStore from "@store/app.js";
import useUserStore from "@store/user.js";
import { path } from "@tauri-apps/api";
import { open, save } from "@tauri-apps/plugin-dialog";
@@ -146,7 +149,7 @@ import { AppCharacterData, AppWeaponData } from "@/data/index.js";
const router = useRouter();
// const { isLogin } = storeToRefs(useAppStore());
const { isLogin } = storeToRefs(useAppStore());
const { account, cookie } = storeToRefs(useUserStore());
const authkey = ref<string>("");
@@ -170,19 +173,14 @@ onMounted(async () => {
}
await showLoading.update("正在获取祈愿 UID 列表");
await TGLogger.Info("[UserGacha][onMounted] 进入角色祈愿页面");
selectItem.value = await TSUserGacha.getUidList();
if (selectItem.value.length === 0) {
await showLoading.end();
showSnackbar.error("暂无祈愿数据,请先导入祈愿数据");
await TGLogger.Warn("[UserGacha][onMounted] 暂无祈愿数据,请先导入祈愿数据");
return;
await reloadUid();
if (uidCur.value) {
await showLoading.update(`UID${uidCur.value}`);
gachaListCur.value = await TSUserGacha.getGachaRecords(uidCur.value);
await TGLogger.Info(
`[UserGacha][onMounted] 获取到 ${uidCur.value}${gachaListCur.value.length} 条祈愿数据`,
);
}
uidCur.value = selectItem.value[0];
await showLoading.update(`UID${uidCur.value}`);
gachaListCur.value = await TSUserGacha.getGachaRecords(uidCur.value);
await TGLogger.Info(
`[UserGacha][onMounted] 获取到 ${uidCur.value}${gachaListCur.value.length} 条祈愿数据`,
);
await showLoading.end();
showSnackbar.success(`成功获取 ${gachaListCur.value.length} 条祈愿数据`);
});
@@ -204,6 +202,16 @@ async function toBeyond(): Promise<void> {
await router.push({ name: "千星奇域祈愿记录" });
}
async function reloadUid(): Promise<void> {
selectItem.value = await TSUserGacha.getUidList();
if (selectItem.value.includes(account.value.gameUid)) uidCur.value = account.value.gameUid;
if (selectItem.value.length > 0) uidCur.value = selectItem.value[0];
else if (isLogin.value) {
selectItem.value = [account.value.gameUid];
uidCur.value = account.value.gameUid;
} else uidCur.value = undefined;
}
// 刷新按钮点击事件
async function confirmRefresh(force: boolean): Promise<void> {
await TGLogger.Info(`[UserGacha][${account.value.gameUid}][confirmRefresh] 刷新祈愿数据`);

View File

@@ -95,18 +95,12 @@ const gachaListCur = shallowRef<Array<TGApp.Sqlite.GachaRecords.TableGachaB>>([]
onMounted(async () => {
await TGLogger.Info("[UserGachaB][onMounted] 进入千星奇域页面");
await showLoading.start("正在加载千星奇域祈愿数据", "正在获取UID列表...");
selectItem.value = await TSUserGachaB.getUidList();
await TGLogger.Info(`[UserGachaB][onMounted] 总UID数${selectItem.value.length}`);
if (selectItem.value.length === 0) {
await showLoading.end();
await TGLogger.Info("[UserGachaB][onMounted] UID列表为空");
return;
await reloadUid();
if (uidCur.value) {
await showLoading.update(`UID: ${uidCur.value}`);
gachaListCur.value = await TSUserGachaB.getGachaRecords(uidCur.value);
await TGLogger.Info(`[UserGachaB][onMounted] 祈愿记录数: ${gachaListCur.value.length}`);
}
uidCur.value = selectItem.value[0];
await TGLogger.Info(`[UserGachaB][onMounted] 当前UID:${uidCur.value}`);
await showLoading.update(`UID: ${uidCur.value}`);
gachaListCur.value = await TSUserGachaB.getGachaRecords(uidCur.value);
await TGLogger.Info(`[UserGachaB][onMounted] 祈愿记录数: ${gachaListCur.value.length}`);
await showLoading.end();
showSnackbar.success(`加载完成,共 ${gachaListCur.value.length} 条祈愿记录`);
});
@@ -130,6 +124,16 @@ async function toGacha(): Promise<void> {
await router.push({ name: "祈愿记录" });
}
async function reloadUid(): Promise<void> {
selectItem.value = await TSUserGachaB.getUidList();
if (selectItem.value.includes(account.value.gameUid)) uidCur.value = account.value.gameUid;
else if (selectItem.value.length > 0) uidCur.value = selectItem.value[0];
else if (isLogin.value) {
selectItem.value = [account.value.gameUid];
uidCur.value = account.value.gameUid;
} else uidCur.value = undefined;
}
/**
* 刷新祈愿数据
* @param {boolean} force 是否强制刷新

View File

@@ -1,3 +1,4 @@
<!-- 用户战绩页面 -->
<template>
<v-app-bar>
<template #prepend>
@@ -21,8 +22,9 @@
prepend-icon="mdi-refresh"
variant="elevated"
@click="refreshRecord()"
>更新</v-btn
>
更新
</v-btn>
<v-btn
:disabled="recordData === undefined"
class="ur-top-btn"

View File

@@ -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> {

View File

@@ -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();
}
/**

View File

@@ -25,15 +25,15 @@ function getInsertGameAccountSql(uid: string, data: TGApp.BBS.Game.Account): str
INSERT INTO GameAccount(uid, gameBiz, gameUid, isChosen, isOfficial, level, nickname, region, regionName, updated)
VALUES ('${uid}', '${data.game_biz}', '${data.game_uid}', ${isChosen}, ${isOfficial}, ${data.level},
'${data.nickname}', '${data.region}', '${data.region_name}', '${timeNow}
') ON CONFLICT(uid, gameUid, gameBiz) DO
UPDATE
SET isChosen = ${isChosen},
isOfficial = ${isOfficial},
level = ${data.level},
nickname = '${data.nickname}',
region = '${data.region}',
regionName = '${data.region_name}',
updated = '${timeNow}';
')
ON CONFLICT(uid, gameUid, gameBiz) DO UPDATE
SET isChosen = ${isChosen},
isOfficial = ${isOfficial},
level = ${data.level},
nickname = '${data.nickname}',
region = '${data.region}',
regionName = '${data.region_name}',
updated = '${timeNow}';
`;
}
@@ -47,11 +47,11 @@ function getInsertAccountSql(user: TGApp.App.Account.User): string {
const table = transUser(user);
return `
INSERT INTO UserAccount(uid, cookie, brief, updated)
VALUES ('${table.uid}', '${table.cookie}', '${table.brief}', '${table.updated}') ON CONFLICT(uid) DO
UPDATE
SET cookie = '${table.cookie}',
brief = '${table.brief}',
updated = '${table.updated}';
VALUES ('${table.uid}', '${table.cookie}', '${table.brief}', '${table.updated}')
ON CONFLICT(uid) DO UPDATE
SET cookie = '${table.cookie}',
brief = '${table.brief}',
updated = '${table.updated}';
`;
}