mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-18 10:18:14 +08:00
♻️ 重构 userStore 用法
This commit is contained in:
@@ -66,6 +66,7 @@
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { storeToRefs } from "pinia";
|
||||
import { onMounted, ref } from "vue";
|
||||
|
||||
import showSnackbar from "../../components/func/snackbar";
|
||||
@@ -80,7 +81,7 @@ import { generateShareImg } from "../../utils/TGShare";
|
||||
import TGRequest from "../../web/request/TGRequest";
|
||||
|
||||
// store
|
||||
const userStore = useUserStore();
|
||||
const userStore = storeToRefs(useUserStore());
|
||||
// loading
|
||||
const loading = ref<boolean>(true);
|
||||
const loadingTitle = ref<string>();
|
||||
@@ -88,7 +89,7 @@ const loadingSub = ref<string>();
|
||||
|
||||
// data
|
||||
const userTab = ref<number>(0);
|
||||
const user = ref<TGApp.Sqlite.Account.Game>(userStore.getCurAccount());
|
||||
const user = ref<TGApp.Sqlite.Account.Game>(userStore.account.value);
|
||||
|
||||
const localAbyss = ref<TGApp.Sqlite.Abyss.SingleTable[]>([]);
|
||||
const localAbyssID = ref<number[]>([]);
|
||||
@@ -114,7 +115,7 @@ async function initAbyssData(): Promise<void> {
|
||||
async function getAbyssData(): Promise<void> {
|
||||
loadingTitle.value = "正在获取深渊数据";
|
||||
loading.value = true;
|
||||
if (!userStore.cookie) {
|
||||
if (!userStore.cookie.value) {
|
||||
showSnackbar({
|
||||
text: "未登录",
|
||||
color: "error",
|
||||
@@ -123,10 +124,10 @@ async function getAbyssData(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
const cookie = {
|
||||
account_id: userStore.cookie.account_id,
|
||||
cookie_token: userStore.cookie.cookie_token,
|
||||
ltoken: userStore.cookie.ltoken,
|
||||
ltuid: userStore.cookie.ltuid,
|
||||
account_id: userStore.cookie.value.account_id,
|
||||
cookie_token: userStore.cookie.value.cookie_token,
|
||||
ltoken: userStore.cookie.value.ltoken,
|
||||
ltuid: userStore.cookie.value.ltuid,
|
||||
};
|
||||
loadingTitle.value = "正在获取上期深渊数据";
|
||||
const resP = await TGRequest.User.byCookie.getAbyss(cookie, "2", user.value);
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
/>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { storeToRefs } from "pinia";
|
||||
import { onMounted, ref } from "vue";
|
||||
|
||||
import DucDetailOverlay from "../../components/devCharacter/duc-detail-overlay.vue";
|
||||
@@ -67,8 +68,8 @@ import { generateShareImg } from "../../utils/TGShare";
|
||||
import TGRequest from "../../web/request/TGRequest";
|
||||
|
||||
// store
|
||||
const userStore = useUserStore();
|
||||
const user = userStore.getCurAccount();
|
||||
const userStore = storeToRefs(useUserStore());
|
||||
const user = userStore.account.value;
|
||||
|
||||
// loading
|
||||
const loading = ref<boolean>(false);
|
||||
@@ -133,7 +134,7 @@ async function loadRole(): Promise<void> {
|
||||
async function refreshRoles(): Promise<void> {
|
||||
loadingTitle.value = "正在获取角色数据";
|
||||
loading.value = true;
|
||||
if (!userStore.cookie) {
|
||||
if (!userStore.cookie.value) {
|
||||
showSnackbar({
|
||||
text: "请先登录",
|
||||
color: "error",
|
||||
@@ -142,10 +143,10 @@ async function refreshRoles(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
const cookie = {
|
||||
account_id: userStore.cookie.account_id,
|
||||
cookie_token: userStore.cookie.cookie_token,
|
||||
ltoken: userStore.cookie.ltoken,
|
||||
ltuid: userStore.cookie.ltuid,
|
||||
account_id: userStore.cookie.value.account_id,
|
||||
cookie_token: userStore.cookie.value.cookie_token,
|
||||
ltoken: userStore.cookie.value.ltoken,
|
||||
ltuid: userStore.cookie.value.ltuid,
|
||||
};
|
||||
const res = await TGRequest.User.byLToken.getRoleList(cookie, user);
|
||||
if (Array.isArray(res)) {
|
||||
@@ -166,7 +167,7 @@ async function refreshRoles(): Promise<void> {
|
||||
async function refreshTalent(): Promise<void> {
|
||||
loadingTitle.value = "正在获取天赋数据";
|
||||
loading.value = true;
|
||||
if (!userStore.cookie) {
|
||||
if (!userStore.cookie.value) {
|
||||
showSnackbar({
|
||||
text: "请先登录",
|
||||
color: "error",
|
||||
@@ -178,8 +179,8 @@ async function refreshTalent(): Promise<void> {
|
||||
loadingTitle.value = `正在获取${role.name}的天赋数据`;
|
||||
loadingSub.value = `CID:${role.cid}`;
|
||||
const res = await TGRequest.User.calculate.getSyncAvatarDetail(
|
||||
userStore.cookie.account_id,
|
||||
userStore.cookie.cookie_token,
|
||||
userStore.cookie.value.account_id,
|
||||
userStore.cookie.value.cookie_token,
|
||||
user.gameUid,
|
||||
role.cid,
|
||||
);
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { dialog, fs, path } from "@tauri-apps/api";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed, onMounted, ref, watch } from "vue";
|
||||
|
||||
import showConfirm from "../../components/func/confirm";
|
||||
@@ -63,9 +64,9 @@ import { backupUigfData, exportUigfData, readUigfData, verifyUigfData } from "..
|
||||
import TGRequest from "../../web/request/TGRequest";
|
||||
|
||||
// store
|
||||
const userStore = useUserStore();
|
||||
const userStore = storeToRefs(useUserStore());
|
||||
const appStore = useAppStore();
|
||||
const account = userStore.getCurAccount();
|
||||
const account = userStore.account.value;
|
||||
const authkey = ref<string>("");
|
||||
|
||||
// loading
|
||||
@@ -119,7 +120,7 @@ async function confirmRefresh(): Promise<void> {
|
||||
}
|
||||
loadingTitle.value = "正在获取 authkey";
|
||||
loading.value = true;
|
||||
if (!userStore.cookie) {
|
||||
if (!userStore.cookie.value) {
|
||||
showSnackbar({
|
||||
color: "error",
|
||||
text: "请先登录",
|
||||
@@ -128,10 +129,10 @@ async function confirmRefresh(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
const cookie = {
|
||||
stoken: userStore.cookie.stoken,
|
||||
mid: userStore.cookie.mid,
|
||||
stoken: userStore.cookie.value.stoken,
|
||||
mid: userStore.cookie.value.mid,
|
||||
};
|
||||
const gameUid = userStore.getCurAccount().gameUid;
|
||||
const gameUid = account.gameUid;
|
||||
const authkeyRes = await TGRequest.User.getAuthkey(cookie, gameUid);
|
||||
if (typeof authkeyRes === "string") {
|
||||
authkey.value = authkeyRes;
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { storeToRefs } from "pinia";
|
||||
import { onMounted, ref } from "vue";
|
||||
|
||||
import showSnackbar from "../../components/func/snackbar";
|
||||
@@ -47,8 +48,8 @@ import { generateShareImg } from "../../utils/TGShare";
|
||||
import TGRequest from "../../web/request/TGRequest";
|
||||
|
||||
// store
|
||||
const userStore = useUserStore();
|
||||
const user = userStore.getCurAccount();
|
||||
const userStore = storeToRefs(useUserStore());
|
||||
const user = userStore.account.value;
|
||||
|
||||
// loading
|
||||
const loading = ref<boolean>(false);
|
||||
@@ -82,7 +83,7 @@ async function initUserRecordData(): Promise<void> {
|
||||
async function refresh(): Promise<void> {
|
||||
loadingTitle.value = "正在获取战绩数据";
|
||||
loading.value = true;
|
||||
if (!userStore.cookie) {
|
||||
if (!userStore.cookie.value) {
|
||||
showSnackbar({
|
||||
text: "请先登录",
|
||||
color: "error",
|
||||
@@ -91,8 +92,8 @@ async function refresh(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
const cookie = {
|
||||
account_id: userStore.cookie.account_id,
|
||||
cookie_token: userStore.cookie.cookie_token,
|
||||
account_id: userStore.cookie.value.account_id,
|
||||
cookie_token: userStore.cookie.value.cookie_token,
|
||||
};
|
||||
const res = await TGRequest.User.getRecord(cookie, user);
|
||||
if (!("retcode" in res)) {
|
||||
|
||||
@@ -149,6 +149,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { app, fs, invoke, os, process as TauriProcess } from "@tauri-apps/api";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
|
||||
import showConfirm from "../../components/func/confirm";
|
||||
@@ -170,7 +171,7 @@ import { restoreAbyssData, restoreCookieData } from "../../web/utils/restoreData
|
||||
|
||||
// Store
|
||||
const appStore = useAppStore();
|
||||
const userStore = useUserStore();
|
||||
const userStore = storeToRefs(useUserStore());
|
||||
const homeStore = useHomeStore();
|
||||
const achievementsStore = useAchievementsStore();
|
||||
|
||||
@@ -202,13 +203,13 @@ const showReset = ref<boolean>(false);
|
||||
// data
|
||||
const showHome = ref<string[]>(homeStore.getShowValue());
|
||||
const userInfo = computed(() => {
|
||||
const info = userStore.getBriefInfo();
|
||||
if (info && info.nickname) {
|
||||
const info = userStore.briefInfo;
|
||||
if (info.value && info.value.nickname) {
|
||||
return {
|
||||
nickname: info.nickname,
|
||||
uid: info.uid,
|
||||
desc: info.desc,
|
||||
avatar: info.avatar,
|
||||
nickname: info.value.nickname,
|
||||
uid: info.value.uid,
|
||||
desc: info.value.desc,
|
||||
avatar: info.value.avatar,
|
||||
};
|
||||
}
|
||||
return {
|
||||
@@ -286,8 +287,8 @@ async function confirmRefreshUser(): Promise<void> {
|
||||
});
|
||||
return;
|
||||
}
|
||||
const ck = userStore.cookie;
|
||||
if (JSON.stringify(ck) === "{}") {
|
||||
const ck = userStore.cookie.value;
|
||||
if (ck === undefined || JSON.stringify(ck) === "{}") {
|
||||
showSnackbar({
|
||||
color: "error",
|
||||
text: "扫码登录后才能刷新用户信息!",
|
||||
@@ -328,7 +329,8 @@ async function confirmRefreshUser(): Promise<void> {
|
||||
loadingTitle.value = "刷新失败!正在获取用户头像、昵称信息";
|
||||
failCount++;
|
||||
}
|
||||
await userStore.saveCookie(ck);
|
||||
userStore.cookie.value = ck;
|
||||
await TGSqlite.saveAppData("cookie", JSON.stringify(ck));
|
||||
const infoRes = await TGRequest.User.byCookie.getUserInfo(ck.cookie_token, ck.account_id);
|
||||
if ("retcode" in infoRes) {
|
||||
console.error(infoRes);
|
||||
@@ -341,7 +343,8 @@ async function confirmRefreshUser(): Promise<void> {
|
||||
avatar: infoRes.avatar_url,
|
||||
desc: infoRes.introduce,
|
||||
};
|
||||
await userStore.saveBriefInfo(briefInfo);
|
||||
userStore.briefInfo.value = briefInfo;
|
||||
await TGSqlite.saveAppData("userInfo", JSON.stringify(briefInfo));
|
||||
loadingTitle.value = "获取成功!正在获取用户游戏账号信息";
|
||||
}
|
||||
const accountRes = await TGRequest.User.byCookie.getAccounts(ck.cookie_token, ck.account_id);
|
||||
@@ -349,7 +352,7 @@ async function confirmRefreshUser(): Promise<void> {
|
||||
loadingTitle.value = "获取成功!正在保存到数据库!";
|
||||
await TGSqlite.saveAccount(accountRes);
|
||||
const curAccount = await TGSqlite.getCurAccount();
|
||||
if (curAccount) userStore.setCurAccount(curAccount);
|
||||
if (curAccount) userStore.account.value = curAccount;
|
||||
} else {
|
||||
console.error(accountRes);
|
||||
loadingTitle.value = "获取失败!";
|
||||
@@ -434,7 +437,7 @@ async function confirmRestore(): Promise<void> {
|
||||
}
|
||||
loadingSub.value = "正在恢复祈愿数据";
|
||||
res = await restoreCookieData();
|
||||
userStore.cookie = await TGSqlite.getCookie();
|
||||
userStore.cookie.value = await TGSqlite.getCookie();
|
||||
if (!res) {
|
||||
fail.push("Cookie");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user