♻️ userStore 及 cookie 相关类型重构 #51

This commit is contained in:
BTMuli
2023-12-16 22:07:31 +08:00
parent 00386bc7ee
commit 4370bbaa57
16 changed files with 267 additions and 236 deletions

View File

@@ -88,7 +88,7 @@ const loadingSub = ref<string>();
// data
const userTab = ref<number>(0);
const user = computed<TGApp.Sqlite.Account.Game>(() => userStore.getCurAccount());
const user = ref<TGApp.Sqlite.Account.Game>(userStore.getCurAccount());
const localAbyss = ref<TGApp.Sqlite.Abyss.SingleTable[]>([]);
const localAbyssID = ref<number[]>([]);
@@ -114,12 +114,19 @@ async function initAbyssData(): Promise<void> {
async function getAbyssData(): Promise<void> {
loadingTitle.value = "正在获取深渊数据";
loading.value = true;
const abyssCookie = userStore.getCookieGroup4();
const cookie: Record<string, string> = {
account_id: abyssCookie.account_id,
cookie_token: abyssCookie.cookie_token,
ltoken: abyssCookie.ltoken,
ltuid: abyssCookie.ltuid,
if (!userStore.cookie) {
showSnackbar({
text: "未登录",
color: "error",
});
loading.value = false;
return;
}
const cookie = {
account_id: userStore.cookie.account_id,
cookie_token: userStore.cookie.cookie_token,
ltoken: userStore.cookie.ltoken,
ltuid: userStore.cookie.ltuid,
};
loadingTitle.value = "正在获取上期深渊数据";
const resP = await TGRequest.User.byCookie.getAbyss(cookie, "2", user.value);

View File

@@ -54,7 +54,7 @@
/>
</template>
<script lang="ts" setup>
import { computed, onMounted, ref } from "vue";
import { onMounted, ref } from "vue";
import DucDetailOverlay from "../../components/devCharacter/duc-detail-overlay.vue";
import showSnackbar from "../../components/func/snackbar";
@@ -78,7 +78,6 @@ const loadingSub = ref<string>();
// data
const isEmpty = ref(true);
const roleList = ref<TGApp.Sqlite.Character.UserRole[]>([]);
const roleCookie = computed(() => userStore.getCookieGroup4());
// overlay
const visible = ref(false);
@@ -134,7 +133,21 @@ async function loadRole(): Promise<void> {
async function refreshRoles(): Promise<void> {
loadingTitle.value = "正在获取角色数据";
loading.value = true;
const res = await TGRequest.User.byLToken.getRoleList(roleCookie.value, user);
if (!userStore.cookie) {
showSnackbar({
text: "请先登录",
color: "error",
});
loading.value = false;
return;
}
const cookie = {
account_id: userStore.cookie.account_id,
cookie_token: userStore.cookie.cookie_token,
ltoken: userStore.cookie.ltoken,
ltuid: userStore.cookie.ltuid,
};
const res = await TGRequest.User.byLToken.getRoleList(cookie, user);
if (Array.isArray(res)) {
loadingTitle.value = "正在保存角色数据";
await TGSqlite.saveUserCharacter(user.gameUid, res);
@@ -153,12 +166,20 @@ async function refreshRoles(): Promise<void> {
async function refreshTalent(): Promise<void> {
loadingTitle.value = "正在获取天赋数据";
loading.value = true;
const talentCookie = userStore.getCookieGroup2();
if (!userStore.cookie) {
showSnackbar({
text: "请先登录",
color: "error",
});
loading.value = false;
return;
}
for (const role of roleList.value) {
loadingTitle.value = `正在获取${role.name}的天赋数据`;
loadingSub.value = `CID${role.cid}`;
const res = await TGRequest.User.calculate.getSyncAvatarDetail(
talentCookie,
userStore.cookie.account_id,
userStore.cookie.cookie_token,
user.gameUid,
role.cid,
);

View File

@@ -119,6 +119,14 @@ async function confirmRefresh(): Promise<void> {
}
loadingTitle.value = "正在获取 authkey";
loading.value = true;
if (!userStore.cookie) {
showSnackbar({
color: "error",
text: "请先登录",
});
loading.value = false;
return;
}
const cookie = {
stoken: userStore.cookie.stoken,
mid: userStore.cookie.mid,

View File

@@ -32,7 +32,7 @@
</div>
</template>
<script lang="ts" setup>
import { computed, onMounted, ref } from "vue";
import { onMounted, ref } from "vue";
import showSnackbar from "../../components/func/snackbar";
import TSubLine from "../../components/main/t-subline.vue";
@@ -58,7 +58,6 @@ const loadingSub = ref<string>();
// data
const isEmpty = ref<boolean>(true);
const recordData = ref<TGApp.Sqlite.Record.SingleTable>(<TGApp.Sqlite.Record.SingleTable>{});
const recordCookie = computed<TGApp.BBS.Constant.CookieGroup2>(() => userStore.getCookieGroup2());
onMounted(async () => {
loadingTitle.value = "正在加载战绩数据";
@@ -83,7 +82,19 @@ async function initUserRecordData(): Promise<void> {
async function refresh(): Promise<void> {
loadingTitle.value = "正在获取战绩数据";
loading.value = true;
const res = await TGRequest.User.getRecord(recordCookie.value, user);
if (!userStore.cookie) {
showSnackbar({
text: "请先登录",
color: "error",
});
loading.value = false;
return;
}
const cookie = {
account_id: userStore.cookie.account_id,
cookie_token: userStore.cookie.cookie_token,
};
const res = await TGRequest.User.getRecord(cookie, user);
if (!("retcode" in res)) {
console.log(res);
loadingTitle.value = "正在保存战绩数据";