mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-05-22 05:35:48 +08:00
♻️ 重构深渊页面UID加载&上传逻辑
This commit is contained in:
@@ -109,20 +109,20 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="uaw-d-box">
|
<div class="uaw-d-box">
|
||||||
<TuaDetail
|
<TuaDetail
|
||||||
:uid="uidCur"
|
|
||||||
:id="item.id"
|
|
||||||
v-for="floor in item.floors"
|
v-for="floor in item.floors"
|
||||||
|
:id="item.id"
|
||||||
:key="floor.id"
|
:key="floor.id"
|
||||||
:floor
|
:floor
|
||||||
|
:uid="uidCur"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</v-window-item>
|
</v-window-item>
|
||||||
|
<div v-show="localAbyss.length === 0" class="ua-empty">
|
||||||
|
<img alt="empty" src="/UI/app/empty.webp" />
|
||||||
|
<span>暂无数据,请尝试刷新</span>
|
||||||
|
</div>
|
||||||
</v-window>
|
</v-window>
|
||||||
<div v-show="localAbyss.length === 0" class="user-empty">
|
|
||||||
<img alt="empty" src="/UI/app/empty.webp" />
|
|
||||||
<span>暂无数据,请尝试刷新</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
@@ -135,8 +135,8 @@ import TuaOverview from "@comp/userAbyss/tua-overview.vue";
|
|||||||
import hutao from "@Hutao/index.js";
|
import hutao from "@Hutao/index.js";
|
||||||
import recordReq from "@req/recordReq.js";
|
import recordReq from "@req/recordReq.js";
|
||||||
import TSUserAbyss from "@Sqlm/userAbyss.js";
|
import TSUserAbyss from "@Sqlm/userAbyss.js";
|
||||||
|
import TSUserAccount from "@Sqlm/userAccount.js";
|
||||||
import TSUserAvatar from "@Sqlm/userAvatar.js";
|
import TSUserAvatar from "@Sqlm/userAvatar.js";
|
||||||
import useAppStore from "@store/app.js";
|
|
||||||
import useHutaoStore from "@store/hutao.js";
|
import useHutaoStore from "@store/hutao.js";
|
||||||
import useUserStore from "@store/user.js";
|
import useUserStore from "@store/user.js";
|
||||||
import { getVersion } from "@tauri-apps/api/app";
|
import { getVersion } from "@tauri-apps/api/app";
|
||||||
@@ -151,7 +151,6 @@ import { useRouter } from "vue-router";
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const hutaoStore = useHutaoStore();
|
const hutaoStore = useHutaoStore();
|
||||||
|
|
||||||
const { isLogin } = storeToRefs(useAppStore());
|
|
||||||
const { account, cookie, propMap } = storeToRefs(useUserStore());
|
const { account, cookie, propMap } = storeToRefs(useUserStore());
|
||||||
const { userName } = storeToRefs(hutaoStore);
|
const { userName } = storeToRefs(hutaoStore);
|
||||||
const userTab = ref<number>(0);
|
const userTab = ref<number>(0);
|
||||||
@@ -166,21 +165,25 @@ onMounted(async () => {
|
|||||||
await TGLogger.Info("[UserAbyss][onMounted] 打开角色深渊页面");
|
await TGLogger.Info("[UserAbyss][onMounted] 打开角色深渊页面");
|
||||||
await showLoading.update("正在获取UID列表");
|
await showLoading.update("正在获取UID列表");
|
||||||
await reloadUid();
|
await reloadUid();
|
||||||
await showLoading.update(`正在加载${uidCur.value}的深渊数据`);
|
|
||||||
await showLoading.end();
|
await showLoading.end();
|
||||||
showSnackbar.success(`已加载${uidCur.value}的${localAbyss.value.length}条深渊数据`);
|
showSnackbar.success(`已加载${uidCur.value}的${localAbyss.value.length}条深渊数据`);
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(() => uidCur.value, loadAbyss);
|
watch(() => uidCur.value, loadAbyss);
|
||||||
|
watch(
|
||||||
|
() => account.value,
|
||||||
|
async () => await reloadUid(),
|
||||||
|
);
|
||||||
|
|
||||||
async function reloadUid(): Promise<void> {
|
async function reloadUid(uid?: string): Promise<void> {
|
||||||
uidList.value = await TSUserAbyss.getAllUid();
|
uidList.value = await TSUserAbyss.getAllUid();
|
||||||
if (uidList.value.includes(account.value.gameUid)) uidCur.value = account.value.gameUid;
|
if (uidList.value.length === 0) uidList.value = [account.value.gameUid];
|
||||||
else if (uidList.value.length > 0) uidCur.value = uidList.value[0];
|
if (uidList.value.includes(account.value.gameUid)) {
|
||||||
else if (isLogin.value) {
|
if (uid === undefined) uidCur.value = account.value.gameUid;
|
||||||
uidList.value = [account.value.gameUid];
|
} else {
|
||||||
uidCur.value = account.value.gameUid;
|
uidList.value = [account.value.gameUid, ...uidList.value];
|
||||||
} else uidCur.value = undefined;
|
if (uid === undefined) uidCur.value = uidList.value[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function toCombat(): Promise<void> {
|
async function toCombat(): Promise<void> {
|
||||||
@@ -207,66 +210,69 @@ async function loadAbyss(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function refreshAbyss(): Promise<void> {
|
async function refreshAbyss(): Promise<void> {
|
||||||
if (!cookie.value) {
|
let rfAccount = account.value;
|
||||||
showSnackbar.warn("未登录");
|
let rfCk = cookie.value;
|
||||||
await TGLogger.Warn("[UserAbyss][getAbyssData] 未登录");
|
if (!uidCur.value) {
|
||||||
return;
|
if (!rfCk) {
|
||||||
}
|
showSnackbar.warn("请先登录");
|
||||||
if (uidCur.value && uidCur.value !== account.value.gameUid) {
|
await TGLogger.Warn(`[Abyss][refreshAbyss][${rfAccount.gameUid}] 未登录`);
|
||||||
const switchCheck = await showDialog.check(
|
|
||||||
"是否切换游戏账户",
|
|
||||||
`确认则尝试切换至 ${uidCur.value}`,
|
|
||||||
);
|
|
||||||
if (switchCheck) {
|
|
||||||
await useUserStore().switchGameAccount(uidCur.value);
|
|
||||||
await refreshAbyss();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const freshCheck = await showDialog.check(
|
} else {
|
||||||
"确定刷新?",
|
const gcFind = await TSUserAccount.game.getAccountByGid(uidCur.value.toString());
|
||||||
`用户${account.value.gameUid}与当前UID${uidCur.value}不一致`,
|
console.log(uidCur.value, gcFind);
|
||||||
);
|
if (!gcFind) {
|
||||||
if (!freshCheck) {
|
const check = await showDialog.check(
|
||||||
showSnackbar.cancel("已取消深渊数据刷新");
|
`确定刷新?`,
|
||||||
return;
|
`未找到 ${uidCur.value} 对应 UID,将刷新 ${rfAccount.gameUid} 数据`,
|
||||||
|
);
|
||||||
|
if (!check) return;
|
||||||
|
} else {
|
||||||
|
const acFind = await TSUserAccount.account.getAccount(gcFind.uid);
|
||||||
|
if (!acFind) {
|
||||||
|
const check = await showDialog.check(
|
||||||
|
`确定刷新?`,
|
||||||
|
`未找到 ${uidCur.value} 对应 CK,将刷新 ${rfAccount.gameUid} 数据`,
|
||||||
|
);
|
||||||
|
if (!check) return;
|
||||||
|
} else {
|
||||||
|
rfAccount = gcFind;
|
||||||
|
rfCk = acFind.cookie;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await TGLogger.Info("[UserAbyss][getAbyssData] 更新深渊数据");
|
await TGLogger.Info("[Abyss][refreshAbyss] 更新深渊数据");
|
||||||
await showLoading.start(`正在获取${account.value.gameUid}的深渊数据`, "正在获取上期数据");
|
await showLoading.start(`正在获取 ${rfAccount.gameUid} 的深渊数据`, "正在获取上期数据");
|
||||||
const resP = await recordReq.spiralAbyss(cookie.value, account.value, "2");
|
const resP = await recordReq.spiralAbyss(rfCk!, rfAccount, "2");
|
||||||
console.log(resP);
|
console.log(resP);
|
||||||
if ("retcode" in resP) {
|
if ("retcode" in resP) {
|
||||||
await showLoading.end();
|
await showLoading.end();
|
||||||
showSnackbar.error(`[${resP.retcode}]${resP.message}`);
|
showSnackbar.error(`[${resP.retcode}]${resP.message}`);
|
||||||
await TGLogger.Error(
|
await TGLogger.Error(`[Abyss][refreshAbyss] 获取${rfAccount.gameUid}的上期深渊数据失败`);
|
||||||
`[UserAbyss][getAbyssData] 获取${account.value.gameUid}的上期深渊数据失败`,
|
await TGLogger.Error(`[Abyss][refreshAbyss] ${resP.retcode} ${resP.message}`);
|
||||||
);
|
|
||||||
await TGLogger.Error(`[UserAbyss][getAbyssData] ${resP.retcode} ${resP.message}`);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await TGLogger.Info("[UserAbyss][getAbyssData] 成功获取上期深渊数据");
|
await TGLogger.Info("[Abyss][refreshAbyss] 成功获取上期深渊数据");
|
||||||
await showLoading.update("正在保存上期深渊数据");
|
await showLoading.update("正在保存上期深渊数据");
|
||||||
await TSUserAbyss.saveAbyss(account.value.gameUid, resP);
|
await TSUserAbyss.saveAbyss(rfAccount.gameUid, resP);
|
||||||
await showLoading.update("正在获取本期深渊数据");
|
await showLoading.update("正在获取本期深渊数据");
|
||||||
const res = await recordReq.spiralAbyss(cookie.value, account.value, "1");
|
const res = await recordReq.spiralAbyss(rfCk!, rfAccount, "1");
|
||||||
console.log(res);
|
console.log(res);
|
||||||
if ("retcode" in res) {
|
if ("retcode" in res) {
|
||||||
await showLoading.end();
|
await showLoading.end();
|
||||||
showSnackbar.error(`[${res.retcode}]${res.message}`);
|
showSnackbar.error(`[${res.retcode}]${res.message}`);
|
||||||
await TGLogger.Error(
|
await TGLogger.Error(`[Abyss][refreshAbyss] 获取${rfAccount.gameUid}的本期深渊数据失败`);
|
||||||
`[UserAbyss][getAbyssData] 获取${account.value.gameUid}的本期深渊数据失败`,
|
await TGLogger.Error(`[Abyss][refreshAbyss] ${res.retcode} ${res.message}`);
|
||||||
);
|
|
||||||
await TGLogger.Error(`[UserAbyss][getAbyssData] ${res.retcode} ${res.message}`);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await showLoading.update("正在保存本期深渊数据");
|
await showLoading.update("正在保存本期深渊数据");
|
||||||
await TSUserAbyss.saveAbyss(account.value.gameUid, res);
|
await TSUserAbyss.saveAbyss(rfAccount.gameUid, res);
|
||||||
await TGLogger.Info(`[UserAbyss][getAbyssData] 成功获取${account.value.gameUid}的本期深渊数据`);
|
await TGLogger.Info(`[Abyss][refreshAbyss] 成功获取${rfAccount.gameUid}的本期深渊数据`);
|
||||||
await showLoading.update("正在加载深渊数据");
|
await showLoading.update("正在加载深渊数据");
|
||||||
await reloadUid();
|
await reloadUid(uidCur.value);
|
||||||
await loadAbyss();
|
await loadAbyss();
|
||||||
await showLoading.end();
|
await showLoading.end();
|
||||||
showSnackbar.success(`已加载${account.value.gameUid}的${localAbyss.value.length}条深渊数据`);
|
showSnackbar.success(`已加载${rfAccount.gameUid}的${localAbyss.value.length}条深渊数据`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function shareAbyss(): Promise<void> {
|
async function shareAbyss(): Promise<void> {
|
||||||
@@ -348,22 +354,18 @@ async function uploadAbyss(): Promise<void> {
|
|||||||
const check = await showDialog.check("确定上传?", "未设置胡桃云账号");
|
const check = await showDialog.check("确定上传?", "未设置胡桃云账号");
|
||||||
if (!check) return;
|
if (!check) return;
|
||||||
}
|
}
|
||||||
if (!cookie.value) {
|
await TGLogger.Info("[Abyss][uploadAbyss] 上传深渊数据");
|
||||||
showSnackbar.warn("请登录米社账号");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await TGLogger.Info("[UserAbyss][uploadAbyss] 上传深渊数据");
|
|
||||||
const maxId = Math.max(...localAbyss.value.map((i) => i.id));
|
const maxId = Math.max(...localAbyss.value.map((i) => i.id));
|
||||||
const abyssData = localAbyss.value.find((item) => item.id === maxId);
|
const abyssData = localAbyss.value.find((item) => item.id === maxId);
|
||||||
if (!abyssData) {
|
if (!abyssData) {
|
||||||
showSnackbar.warn("未找到深渊数据");
|
showSnackbar.warn("未找到深渊数据");
|
||||||
await TGLogger.Warn("[UserAbyss][uploadAbyss] 未找到深渊数据");
|
await TGLogger.Warn("[Abyss][uploadAbyss] 未找到深渊数据");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const maxFloor = Number(abyssData.maxFloor.split("-")[0]);
|
const maxFloor = Number(abyssData.maxFloor.split("-")[0]);
|
||||||
if (isNaN(maxFloor) || maxFloor <= 9) {
|
if (isNaN(maxFloor) || maxFloor <= 9) {
|
||||||
showSnackbar.warn("尚未完成深渊,请完成深渊后重试!");
|
showSnackbar.warn("尚未完成深渊,请完成深渊后重试!");
|
||||||
await TGLogger.Warn(`[UserAbyss][uploadAbyss] 尚未完成深渊 ${abyssData.maxFloor}`);
|
await TGLogger.Warn(`[Abyss][uploadAbyss] 尚未完成深渊 ${abyssData.maxFloor}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const startTime = new Date(abyssData.startTime).getTime();
|
const startTime = new Date(abyssData.startTime).getTime();
|
||||||
@@ -371,16 +373,31 @@ async function uploadAbyss(): Promise<void> {
|
|||||||
const nowTime = new Date().getTime();
|
const nowTime = new Date().getTime();
|
||||||
if (nowTime < startTime || nowTime > endTime) {
|
if (nowTime < startTime || nowTime > endTime) {
|
||||||
showSnackbar.warn("非最新深渊数据,请刷新深渊数据后重试!");
|
showSnackbar.warn("非最新深渊数据,请刷新深渊数据后重试!");
|
||||||
await TGLogger.Warn("[UserAbyss][uploadAbyss] 非最新深渊数据");
|
await TGLogger.Warn("[Abyss][uploadAbyss] 非最新深渊数据");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let upAccount = account.value;
|
||||||
|
let upCk = cookie.value;
|
||||||
|
const gcFind = await TSUserAccount.game.getAccountByGid(uidCur.value!.toString());
|
||||||
|
console.log(uidCur.value, gcFind);
|
||||||
|
if (!gcFind) {
|
||||||
|
showSnackbar.warn(`未找到 ${uidCur.value} 对应 UID,无法刷新角色数据进行上传`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
upAccount = gcFind;
|
||||||
|
const acFind = await TSUserAccount.account.getAccount(gcFind.uid);
|
||||||
|
if (!acFind) {
|
||||||
|
showSnackbar.warn(`未找到 ${uidCur.value} 对应 CK,无法刷新角色数据进行上传`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
upCk = acFind.cookie;
|
||||||
try {
|
try {
|
||||||
await showLoading.start(`正在上传${account.value.gameUid}的深渊数据`, `期数:${abyssData.id}`);
|
await showLoading.start(`正在上传 ${upAccount.gameUid} 的深渊数据`, `期数:${abyssData.id}`);
|
||||||
const transAbyss = hutao.Abyss.utils.transData(abyssData);
|
const transAbyss = hutao.Abyss.utils.transData(abyssData);
|
||||||
if (userName.value) transAbyss.ReservedUserName = userName.value;
|
if (userName.value) transAbyss.ReservedUserName = userName.value;
|
||||||
const check = await refreshAvatars(cookie.value, account.value);
|
const check = await refreshAvatars(upCk!, upAccount);
|
||||||
if (!check) return;
|
if (!check) return;
|
||||||
const roles = await TSUserAvatar.getAvatars(Number(account.value.gameUid));
|
const roles = await TSUserAvatar.getAvatars(Number(upAccount.gameUid));
|
||||||
if (!roles) {
|
if (!roles) {
|
||||||
await showLoading.end();
|
await showLoading.end();
|
||||||
showSnackbar.warn("未找到角色数据");
|
showSnackbar.warn("未找到角色数据");
|
||||||
@@ -393,21 +410,22 @@ async function uploadAbyss(): Promise<void> {
|
|||||||
const res = await hutao.Abyss.upload(transAbyss);
|
const res = await hutao.Abyss.upload(transAbyss);
|
||||||
if (res.retcode !== 0) {
|
if (res.retcode !== 0) {
|
||||||
showSnackbar.error(`[${res.retcode}]${res.message}`);
|
showSnackbar.error(`[${res.retcode}]${res.message}`);
|
||||||
await TGLogger.Error("[UserAbyss][uploadAbyss] 上传深渊数据失败");
|
await TGLogger.Error("[Abyss][uploadAbyss] 上传深渊数据失败");
|
||||||
await TGLogger.Error(`[UserAbyss][uploadAbyss] ${res.retcode} ${res.message}`);
|
await TGLogger.Error(`[Abyss][uploadAbyss] ${res.retcode} ${res.message}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
showSnackbar.success(res.message ?? "上传深渊数据成功,即将刷新祈愿时长");
|
showSnackbar.success(res.message ?? "上传深渊数据成功,即将刷新祈愿时长");
|
||||||
await TGLogger.Info("[UserAbyss][uploadAbyss] 上传深渊数据成功");
|
await TGLogger.Info("[Abyss][uploadAbyss] 上传深渊数据成功");
|
||||||
await TGLogger.Info(`[${res.retcode}] ${res.message}`);
|
await TGLogger.Info(`[${res.retcode}] ${res.message}`);
|
||||||
// 等待5s刷新时长
|
// 等待5s刷新时长
|
||||||
|
await showLoading.update("正在刷新胡桃云数据");
|
||||||
await new Promise<void>((resolve) => setTimeout(resolve, 5000));
|
await new Promise<void>((resolve) => setTimeout(resolve, 5000));
|
||||||
await hutaoStore.tryRefreshInfo();
|
await hutaoStore.tryRefreshInfo();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof Error) {
|
if (e instanceof Error) {
|
||||||
showSnackbar.error(e.message);
|
showSnackbar.error(e.message);
|
||||||
await TGLogger.Error("[UserAbyss][uploadAbyss] 上传深渊数据失败");
|
await TGLogger.Error("[Abyss][uploadAbyss] 上传深渊数据失败");
|
||||||
await TGLogger.Error(`[UserAbyss][uploadAbyss] ${e.message}`);
|
await TGLogger.Error(`[Abyss][uploadAbyss] ${e.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await showLoading.end();
|
await showLoading.end();
|
||||||
@@ -427,7 +445,7 @@ async function refreshAvatars(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
await showLoading.update("正在更新角色列表");
|
await showLoading.update("正在更新角色列表");
|
||||||
const listRes = await recordReq.character.list(ck, account.value);
|
const listRes = await recordReq.character.list(ck, ac);
|
||||||
if ("retcode" in listRes) {
|
if ("retcode" in listRes) {
|
||||||
await showLoading.update("角色列表更新失败");
|
await showLoading.update("角色列表更新失败");
|
||||||
showSnackbar.error(`[${listRes.message}] ${listRes.message}`);
|
showSnackbar.error(`[${listRes.message}] ${listRes.message}`);
|
||||||
@@ -547,9 +565,8 @@ async function refreshAvatars(
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
|
border-radius: 4px;
|
||||||
background: var(--app-page-bg);
|
background: var(--app-page-bg);
|
||||||
border-bottom-right-radius: 4px;
|
|
||||||
border-top-right-radius: 4px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.ua-window-item {
|
.ua-window-item {
|
||||||
@@ -604,20 +621,19 @@ async function refreshAvatars(
|
|||||||
gap: 8px;
|
gap: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.user-empty {
|
.ua-empty {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: calc(50vh - 200px);
|
top: 0;
|
||||||
left: calc(50vw - 400px);
|
left: 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
width: 800px;
|
width: 100%;
|
||||||
height: 400px;
|
height: 100%;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
border-radius: 4px;
|
justify-content: center;
|
||||||
background: var(--common-shadow-t-2);
|
|
||||||
box-shadow: 0 0 5px var(--common-shadow-2);
|
|
||||||
color: var(--common-text-title);
|
color: var(--common-text-title);
|
||||||
font-family: var(--font-title);
|
font-family: var(--font-title);
|
||||||
font-size: 1.5rem;
|
font-size: 1.5rem;
|
||||||
|
row-gap: 12px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user