将 curAccount 存到 storage 里

This commit is contained in:
BTMuli
2023-06-02 21:20:47 +08:00
parent bc49749195
commit 6714a94502
4 changed files with 33 additions and 32 deletions

View File

@@ -5,7 +5,7 @@
<script lang="ts" setup>
// vue
import { markRaw, onMounted, onUnmounted, onUpdated, ref } from "vue";
import { markRaw, onBeforeMount, onMounted, onUnmounted, onUpdated, ref } from "vue";
import TOLoading from "../components/overlay/to-loading.vue";
import TPool from "../components/main/t-pool.vue";
import TPosition from "../components/main/t-position.vue";
@@ -13,8 +13,10 @@ import TCalendar from "../components/main/t-calendar.vue";
// store
import { useHomeStore } from "../store/modules/home";
import { useAppStore } from "../store/modules/app";
import { useUserStore } from "../store/modules/user";
// utils
import { getBuildTime } from "../utils/TGBuild";
import TGSqlite from "../plugins/Sqlite";
// store
const appStore = useAppStore();
@@ -43,6 +45,15 @@ function readLoading (): void {
}
}
onBeforeMount(async () => {
// 获取当前用户
const user = await TGSqlite.getCurAccount();
// 存储当前用户
if (user) {
useUserStore().setCurAccount(user);
}
});
onMounted(async () => {
loadingTitle.value = "正在加载首页";
loading.value = true;

View File

@@ -10,10 +10,6 @@
<v-icon>mdi-refresh</v-icon>
<span>刷新</span>
</v-btn>
<!-- <v-btn class="ua-btn" @click="uploadData">-->
<!-- <v-icon>mdi-upload</v-icon>-->
<!-- <span>上传</span>-->
<!-- </v-btn>-->
</div>
</v-tabs>
<v-window v-model="userTab" class="ua-window">
@@ -58,7 +54,7 @@
</template>
<script lang="ts" setup>
// vue
import { onMounted, ref } from "vue";
import { computed, onMounted, ref } from "vue";
import ToLoading from "../../components/overlay/to-loading.vue";
import TuaOverview from "../../components/userabyss/tua-overview.vue";
import TuaDetail from "../../components/userabyss/tua-detail.vue";
@@ -82,7 +78,7 @@ const abyssCookie = ref({
ltoken: "",
ltuid: "",
});
const user = ref({} as TGApp.Sqlite.Account.Game);
const user = computed(() => userStore.getCurAccount());
const localAbyss = ref([] as TGApp.Sqlite.Abyss.SingleTable[]);
const localAbyssID = ref([] as number[]);
@@ -90,10 +86,6 @@ const curAbyss = ref({} as TGApp.Sqlite.Abyss.SingleTable);
onMounted(async () => {
loadingTitle.value = "正在加载深渊数据";
const curUser = await TGSqlite.getCurAccount();
if (curUser) {
user.value = curUser;
}
abyssCookie.value = {
cookie_token: userStore.getCookieItem("cookie_token"),
account_id: userStore.getCookieItem("account_id"),
@@ -138,24 +130,6 @@ async function getAbyssData (): Promise<void> {
function toAbyss (id: number): void {
curAbyss.value = localAbyss.value.find((item) => item.id === id)!;
}
// async function uploadData(){
// const latestAbyss = localAbyss.value[0];
// const uploadData:TGApp.Plugins.Hutao.AbyssRecordUpload = transAbyssToHutao(latestAbyss, user.value);
// }
//
// function transAbyssToHutao(abyss:TGApp.Sqlite.Abyss.SingleTable, user:TGApp.Sqlite.Account.Game): TGApp.Plugins.Hutao.AbyssRecordUpload {
// let res = {
// uid: user.gameUid,
// identity: "tauri-genshin",
// spiralAbyss: {} as TGApp.Plugins.Hutao.AbyssRecord,
// avatars: [] as TGApp.Plugins.Hutao.AbyssAvatar[],
// reservedUserName: user.nickname,
// } as TGApp.Plugins.Hutao.AbyssRecordUpload;
// const damageRank:TGApp.Sqlite.Abyss.Character = JSON.parse(abyss.damageRank)[0];
// const takeDamageRank:TGApp.Sqlite.Abyss.Character = JSON.parse(abyss.takeDamageRank)[0];
// const floors:TGApp.Sqlite.Abyss.Floor[] = JSON.parse(abyss.floors);
// }
</script>
<style lang="css" scoped>
.ua-box {

View File

@@ -25,7 +25,7 @@ import { useUserStore } from "../../store/modules/user";
// request
import TGRequest from "../../web/request/TGRequest";
// utils
import TGSqlite from "../../utils/TGSqlite";
import TGSqlite from "../../plugins/Sqlite";
// store
const appStore = useAppStore();
@@ -38,7 +38,7 @@ const loadingTitle = ref("");
// data
const roleList = ref([] as TGApp.Game.Character.ListItem[]);
const characterCookie = ref({} as TGApp.BBS.Constant.CookieGroup4);
const user = ref({} as TGApp.Sqlite.Account.Game);
const user = computed(() => userStore.getCurAccount());
const filePath = computed(() => `${appStore.dataPath.userDataDir}/roleList.json`);
onMounted(async () => {
@@ -60,7 +60,6 @@ async function refresh () {
loadingTitle.value = "正在获取角色数据";
loading.value = true;
const res = await TGRequest.User.byLToken.getRoleList(characterCookie.value, user.value);
console.log(res);
if (Array.isArray(res)) {
loadingTitle.value = "正在保存角色数据";
await fs.writeTextFile({

View File

@@ -18,6 +18,7 @@ export const useUserStore = defineStore(
uid: "",
desc: "",
} as TGApp.App.Account.BriefInfo);
const account = ref({} as TGApp.Sqlite.Account.Game);
const cookie = ref({} as Record<string, string>);
function setBriefInfo (info: TGApp.App.Account.BriefInfo): void {
@@ -28,6 +29,14 @@ export const useUserStore = defineStore(
return briefInfo.value;
}
function setCurAccount (user: TGApp.Sqlite.Account.Game) {
account.value = user;
}
function getCurAccount (): TGApp.Sqlite.Account.Game {
return account.value;
}
function getCookieItem (key: string): string {
return cookie.value[key] || "";
}
@@ -67,12 +76,16 @@ export const useUserStore = defineStore(
cookie.value = ck;
}
}
return {
briefInfo,
cookie,
account,
getBriefInfo,
setBriefInfo,
getCookieItem,
setCurAccount,
getCurAccount,
getCookieGroup1,
getCookieGroup2,
getCookieGroup3,
@@ -89,6 +102,10 @@ export const useUserStore = defineStore(
key: "briefInfo",
storage: window.localStorage,
paths: ["briefInfo"],
}, {
key: "account",
storage: window.localStorage,
paths: ["account"],
}],
},
);