mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-19 10:23:21 +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)) {
|
||||
|
||||
Reference in New Issue
Block a user