Skip to content

Commit

Permalink
⚡️ 一些优化
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Mar 21, 2024
1 parent d9cb95e commit 8707a82
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
56 changes: 35 additions & 21 deletions src/pages/User/Characters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
</template>
<script lang="ts" setup>
import { storeToRefs } from "pinia";
import { onMounted, ref } from "vue";
import { onBeforeMount, onMounted, ref } from "vue";
import DucDetailOverlay from "../../components/devCharacter/duc-detail-overlay.vue";
import showSnackbar from "../../components/func/snackbar";
Expand All @@ -70,7 +70,7 @@ import TGRequest from "../../web/request/TGRequest";
// store
const userStore = storeToRefs(useUserStore());
const user = userStore.account.value;
const user = ref<TGApp.Sqlite.Account.Game>();
// loading
const loading = ref<boolean>(false);
Expand Down Expand Up @@ -104,6 +104,12 @@ function clickOverlay(pos: "left" | "right") {
dataVal.value = roleList.value[selectIndex.value];
}
onBeforeMount(() => {
if (userStore.account.value) {
user.value = userStore.account.value;
}
});
onMounted(async () => {
await TGLogger.Info("[Character][onMounted] 进入角色页面");
loadingTitle.value = "正在获取角色数据";
Expand All @@ -120,7 +126,8 @@ function switchOld(): void {
}
async function loadRole(): Promise<void> {
const roleData = await TGSqlite.getUserCharacter(user.gameUid);
if (!user.value) return;
const roleData = await TGSqlite.getUserCharacter(user.value.gameUid);
if (roleData !== false) {
roleData.sort((a, b) => {
if (a.star !== b.star) return b.star - a.star;
Expand All @@ -130,15 +137,18 @@ async function loadRole(): Promise<void> {
roleList.value = roleData;
dataVal.value = roleData[selectIndex.value];
isEmpty.value = false;
await TGLogger.Info(`[Character][loadRole][${user.gameUid}] 成功加载角色数据`);
await TGLogger.Info(`[Character][loadRole][${user.gameUid}] 共获取到${roleData.length}个角色`);
await TGLogger.Info(`[Character][loadRole][${user.value.gameUid}] 成功加载角色数据`);
await TGLogger.Info(
`[Character][loadRole][${user.value.gameUid}] 共获取到${roleData.length}个角色`,
);
} else {
await TGLogger.Warn(`[Character][loadRole][${user.gameUid}] 未获取到角色数据`);
await TGLogger.Warn(`[Character][loadRole][${user.value.gameUid}] 未获取到角色数据`);
}
}
async function refreshRoles(): Promise<void> {
await TGLogger.Info(`[Character][refreshRoles][${user.gameUid}] 正在更新角色数据`);
if (!user.value) return;
await TGLogger.Info(`[Character][refreshRoles][${user.value.gameUid}] 正在更新角色数据`);
loadingTitle.value = "正在获取角色数据";
loading.value = true;
if (!userStore.cookie.value) {
Expand All @@ -155,28 +165,31 @@ async function refreshRoles(): Promise<void> {
ltoken: userStore.cookie.value.ltoken,
ltuid: userStore.cookie.value.ltuid,
};
const res = await TGRequest.User.byLToken.getRoleList(cookie, user);
const res = await TGRequest.User.byLToken.getRoleList(cookie, user.value);
if (Array.isArray(res)) {
await TGLogger.Info(`[Character][refreshRoles][${user.gameUid}] 获取角色数据成功`);
await TGLogger.Info(`[Character][refreshRoles][${user.gameUid}] 共获取到${res.length}个角色`);
await TGLogger.Info(`[Character][refreshRoles][${user.value.gameUid}] 获取角色数据成功`);
await TGLogger.Info(
`[Character][refreshRoles][${user.value.gameUid}] 共获取到${res.length}个角色`,
);
loadingTitle.value = "正在保存角色数据";
await TGSqlite.saveUserCharacter(user.gameUid, res);
await TGSqlite.saveUserCharacter(user.value.gameUid, res);
loadingTitle.value = "正在更新角色数据";
await loadRole();
} else {
showSnackbar({
text: `[${res.retcode}] ${res.message}`,
color: "error",
});
await TGLogger.Error(`[Character][refreshRoles][${user.gameUid}] 更新角色数据失败`);
await TGLogger.Error(`[Character][refreshRoles][${user.value.gameUid}] 更新角色数据失败`);
await TGLogger.Error(
`[Character][refreshRoles][${user.gameUid}] ${res.retcode} ${res.message}`,
`[Character][refreshRoles][${user.value.gameUid}] ${res.retcode} ${res.message}`,
);
}
loading.value = false;
}
async function refreshTalent(): Promise<void> {
if (!user.value) return;
loadingTitle.value = "正在获取天赋数据";
loading.value = true;
if (!userStore.cookie.value) {
Expand All @@ -193,7 +206,7 @@ async function refreshTalent(): Promise<void> {
const res = await TGRequest.User.calculate.getSyncAvatarDetail(
userStore.cookie.value.account_id,
userStore.cookie.value.cookie_token,
user.gameUid,
user.value.gameUid,
role.cid,
);
if ("skill_list" in res) {
Expand All @@ -210,17 +223,17 @@ async function refreshTalent(): Promise<void> {
});
const skillStr = talent.map((i) => `${i.id}:${i.level}`).join(",");
await TGLogger.Info(
`[Character][refreshTalent][${user.gameUid}] 成功获取到${role.name}的天赋数据 ${skillStr}`,
`[Character][refreshTalent][${user.value.gameUid}] 成功获取到${role.name}的天赋数据 ${skillStr}`,
);
await TGSqlite.saveUserCharacterTalent(user.gameUid, role.cid, talent);
await TGSqlite.saveUserCharacterTalent(user.value.gameUid, role.cid, talent);
} else {
loadingTitle.value = `获取${role.name}的天赋数据失败`;
loadingSub.value = `[${res.retcode}] ${res.message}`;
await TGLogger.Error(
`[Character][refreshTalent][${user.gameUid}] 获取 ${role.name} 的天赋数据失败`,
`[Character][refreshTalent][${user.value.gameUid}] 获取 ${role.name} 的天赋数据失败`,
);
await TGLogger.Error(
`[Character][refreshTalent][${user.gameUid}] ${res.retcode} ${res.message}`,
`[Character][refreshTalent][${user.value.gameUid}] ${res.retcode} ${res.message}`,
);
setTimeout(() => {}, 1000);
}
Expand All @@ -237,16 +250,17 @@ async function refreshTalent(): Promise<void> {
}
async function shareRoles(): Promise<void> {
await TGLogger.Info(`[Character][shareRoles][${user.gameUid}] 正在生成分享图片`);
if (!user.value) return;
await TGLogger.Info(`[Character][shareRoles][${user.value.gameUid}] 正在生成分享图片`);
const rolesBox = <HTMLElement>document.querySelector(".uc-box");
const fileName = `【角色列表】-${user.gameUid}`;
const fileName = `【角色列表】-${user.value.gameUid}`;
loadingTitle.value = "正在生成图片";
loadingSub.value = `${fileName}.png`;
loading.value = true;
await generateShareImg(fileName, rolesBox);
loadingSub.value = "";
loading.value = false;
await TGLogger.Info(`[Character][shareRoles][${user.gameUid}] 生成分享图片成功`);
await TGLogger.Info(`[Character][shareRoles][${user.value.gameUid}] 生成分享图片成功`);
}
function getUpdateTime(): string {
Expand Down
3 changes: 3 additions & 0 deletions src/pages/common/Config.vue
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,12 @@ async function confirmDelCache(): Promise<void> {
await TGLogger.Info("[Config][confirmDelCache] 取消清除缓存");
return;
}
loadingTitle.value = "正在清除缓存...";
loading.value = true;
for (const dir of CacheDir) {
await fs.removeDir(dir, { recursive: true });
}
loading.value = false;
showSnackbar({
text: "缓存已清除!即将退出应用!",
});
Expand Down

0 comments on commit 8707a82

Please sign in to comment.