mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-12 09:18:14 +08:00
✨ 将 curAccount 存到 storage 里
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
// vue
|
// 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 TOLoading from "../components/overlay/to-loading.vue";
|
||||||
import TPool from "../components/main/t-pool.vue";
|
import TPool from "../components/main/t-pool.vue";
|
||||||
import TPosition from "../components/main/t-position.vue";
|
import TPosition from "../components/main/t-position.vue";
|
||||||
@@ -13,8 +13,10 @@ import TCalendar from "../components/main/t-calendar.vue";
|
|||||||
// store
|
// store
|
||||||
import { useHomeStore } from "../store/modules/home";
|
import { useHomeStore } from "../store/modules/home";
|
||||||
import { useAppStore } from "../store/modules/app";
|
import { useAppStore } from "../store/modules/app";
|
||||||
|
import { useUserStore } from "../store/modules/user";
|
||||||
// utils
|
// utils
|
||||||
import { getBuildTime } from "../utils/TGBuild";
|
import { getBuildTime } from "../utils/TGBuild";
|
||||||
|
import TGSqlite from "../plugins/Sqlite";
|
||||||
|
|
||||||
// store
|
// store
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
@@ -43,6 +45,15 @@ function readLoading (): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onBeforeMount(async () => {
|
||||||
|
// 获取当前用户
|
||||||
|
const user = await TGSqlite.getCurAccount();
|
||||||
|
// 存储当前用户
|
||||||
|
if (user) {
|
||||||
|
useUserStore().setCurAccount(user);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
loadingTitle.value = "正在加载首页";
|
loadingTitle.value = "正在加载首页";
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
|
|||||||
@@ -10,10 +10,6 @@
|
|||||||
<v-icon>mdi-refresh</v-icon>
|
<v-icon>mdi-refresh</v-icon>
|
||||||
<span>刷新</span>
|
<span>刷新</span>
|
||||||
</v-btn>
|
</v-btn>
|
||||||
<!-- <v-btn class="ua-btn" @click="uploadData">-->
|
|
||||||
<!-- <v-icon>mdi-upload</v-icon>-->
|
|
||||||
<!-- <span>上传</span>-->
|
|
||||||
<!-- </v-btn>-->
|
|
||||||
</div>
|
</div>
|
||||||
</v-tabs>
|
</v-tabs>
|
||||||
<v-window v-model="userTab" class="ua-window">
|
<v-window v-model="userTab" class="ua-window">
|
||||||
@@ -58,7 +54,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
// vue
|
// vue
|
||||||
import { onMounted, ref } from "vue";
|
import { computed, onMounted, ref } from "vue";
|
||||||
import ToLoading from "../../components/overlay/to-loading.vue";
|
import ToLoading from "../../components/overlay/to-loading.vue";
|
||||||
import TuaOverview from "../../components/userabyss/tua-overview.vue";
|
import TuaOverview from "../../components/userabyss/tua-overview.vue";
|
||||||
import TuaDetail from "../../components/userabyss/tua-detail.vue";
|
import TuaDetail from "../../components/userabyss/tua-detail.vue";
|
||||||
@@ -82,7 +78,7 @@ const abyssCookie = ref({
|
|||||||
ltoken: "",
|
ltoken: "",
|
||||||
ltuid: "",
|
ltuid: "",
|
||||||
});
|
});
|
||||||
const user = ref({} as TGApp.Sqlite.Account.Game);
|
const user = computed(() => userStore.getCurAccount());
|
||||||
|
|
||||||
const localAbyss = ref([] as TGApp.Sqlite.Abyss.SingleTable[]);
|
const localAbyss = ref([] as TGApp.Sqlite.Abyss.SingleTable[]);
|
||||||
const localAbyssID = ref([] as number[]);
|
const localAbyssID = ref([] as number[]);
|
||||||
@@ -90,10 +86,6 @@ const curAbyss = ref({} as TGApp.Sqlite.Abyss.SingleTable);
|
|||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
loadingTitle.value = "正在加载深渊数据";
|
loadingTitle.value = "正在加载深渊数据";
|
||||||
const curUser = await TGSqlite.getCurAccount();
|
|
||||||
if (curUser) {
|
|
||||||
user.value = curUser;
|
|
||||||
}
|
|
||||||
abyssCookie.value = {
|
abyssCookie.value = {
|
||||||
cookie_token: userStore.getCookieItem("cookie_token"),
|
cookie_token: userStore.getCookieItem("cookie_token"),
|
||||||
account_id: userStore.getCookieItem("account_id"),
|
account_id: userStore.getCookieItem("account_id"),
|
||||||
@@ -138,24 +130,6 @@ async function getAbyssData (): Promise<void> {
|
|||||||
function toAbyss (id: number): void {
|
function toAbyss (id: number): void {
|
||||||
curAbyss.value = localAbyss.value.find((item) => item.id === id)!;
|
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>
|
</script>
|
||||||
<style lang="css" scoped>
|
<style lang="css" scoped>
|
||||||
.ua-box {
|
.ua-box {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import { useUserStore } from "../../store/modules/user";
|
|||||||
// request
|
// request
|
||||||
import TGRequest from "../../web/request/TGRequest";
|
import TGRequest from "../../web/request/TGRequest";
|
||||||
// utils
|
// utils
|
||||||
import TGSqlite from "../../utils/TGSqlite";
|
import TGSqlite from "../../plugins/Sqlite";
|
||||||
|
|
||||||
// store
|
// store
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
@@ -38,7 +38,7 @@ const loadingTitle = ref("");
|
|||||||
// data
|
// data
|
||||||
const roleList = ref([] as TGApp.Game.Character.ListItem[]);
|
const roleList = ref([] as TGApp.Game.Character.ListItem[]);
|
||||||
const characterCookie = ref({} as TGApp.BBS.Constant.CookieGroup4);
|
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`);
|
const filePath = computed(() => `${appStore.dataPath.userDataDir}/roleList.json`);
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
@@ -60,7 +60,6 @@ async function refresh () {
|
|||||||
loadingTitle.value = "正在获取角色数据";
|
loadingTitle.value = "正在获取角色数据";
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
const res = await TGRequest.User.byLToken.getRoleList(characterCookie.value, user.value);
|
const res = await TGRequest.User.byLToken.getRoleList(characterCookie.value, user.value);
|
||||||
console.log(res);
|
|
||||||
if (Array.isArray(res)) {
|
if (Array.isArray(res)) {
|
||||||
loadingTitle.value = "正在保存角色数据";
|
loadingTitle.value = "正在保存角色数据";
|
||||||
await fs.writeTextFile({
|
await fs.writeTextFile({
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export const useUserStore = defineStore(
|
|||||||
uid: "",
|
uid: "",
|
||||||
desc: "",
|
desc: "",
|
||||||
} as TGApp.App.Account.BriefInfo);
|
} as TGApp.App.Account.BriefInfo);
|
||||||
|
const account = ref({} as TGApp.Sqlite.Account.Game);
|
||||||
const cookie = ref({} as Record<string, string>);
|
const cookie = ref({} as Record<string, string>);
|
||||||
|
|
||||||
function setBriefInfo (info: TGApp.App.Account.BriefInfo): void {
|
function setBriefInfo (info: TGApp.App.Account.BriefInfo): void {
|
||||||
@@ -28,6 +29,14 @@ export const useUserStore = defineStore(
|
|||||||
return briefInfo.value;
|
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 {
|
function getCookieItem (key: string): string {
|
||||||
return cookie.value[key] || "";
|
return cookie.value[key] || "";
|
||||||
}
|
}
|
||||||
@@ -67,12 +76,16 @@ export const useUserStore = defineStore(
|
|||||||
cookie.value = ck;
|
cookie.value = ck;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
briefInfo,
|
briefInfo,
|
||||||
cookie,
|
cookie,
|
||||||
|
account,
|
||||||
getBriefInfo,
|
getBriefInfo,
|
||||||
setBriefInfo,
|
setBriefInfo,
|
||||||
getCookieItem,
|
getCookieItem,
|
||||||
|
setCurAccount,
|
||||||
|
getCurAccount,
|
||||||
getCookieGroup1,
|
getCookieGroup1,
|
||||||
getCookieGroup2,
|
getCookieGroup2,
|
||||||
getCookieGroup3,
|
getCookieGroup3,
|
||||||
@@ -89,6 +102,10 @@ export const useUserStore = defineStore(
|
|||||||
key: "briefInfo",
|
key: "briefInfo",
|
||||||
storage: window.localStorage,
|
storage: window.localStorage,
|
||||||
paths: ["briefInfo"],
|
paths: ["briefInfo"],
|
||||||
|
}, {
|
||||||
|
key: "account",
|
||||||
|
storage: window.localStorage,
|
||||||
|
paths: ["account"],
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user