🌱 开始写数据解析

This commit is contained in:
BTMuli
2023-05-26 22:53:29 +08:00
parent 6f0813b27a
commit ddec6bdc6f
2 changed files with 60 additions and 21 deletions

View File

@@ -1,49 +1,88 @@
<template> <template>
<h1>角色数据获取展示详情</h1> <ToLoading v-model="loading" :title="loadingTitle" />
<v-btn @click="getRoleList"> <div class="uc-top">
获取角色列表 <div class="uc-top-title">我的角色</div>
<v-btn @click="refresh" variant="outlined">
更新数据
</v-btn> </v-btn>
</div>
{{ roleList }} {{ roleList }}
</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";
// tauri
import { fs } from "@tauri-apps/api";
// store // store
import { useAppStore } from "../../store/modules/app";
import { useUserStore } from "../../store/modules/user"; 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 "../../utils/TGSqlite";
// store
const appStore = useAppStore();
const userStore = useUserStore(); const userStore = useUserStore();
const roleList = ref([]);
// loading
const loading = ref(false);
const loadingTitle = ref("");
// data // data
const characterCookie = ref({ const roleList = ref([]);
cookie_token: "", const characterCookie = ref({} as TGApp.BBS.Constant.CookieGroup4);
account_id: "",
ltoken: "",
ltuid: "",
});
const user = ref({} as TGApp.Sqlite.Account.Game); const user = ref({} as TGApp.Sqlite.Account.Game);
const filePath = computed(() => `${appStore.dataPath.userDataDir}/roleList.json`);
onMounted(async () => { onMounted(async () => {
loadingTitle.value = "正在获取角色数据";
loading.value = true;
const curUser = await TGSqlite.getCurAccount(); const curUser = await TGSqlite.getCurAccount();
if (curUser) { if (curUser) {
user.value = curUser; user.value = curUser;
} }
characterCookie.value = { characterCookie.value = userStore.getCookieGroup4();
cookie_token: userStore.getCookieItem("cookie_token"), const fileGet = await fs.readTextFile(filePath.value);
account_id: userStore.getCookieItem("account_id"), if (fileGet) {
ltoken: userStore.getCookieItem("ltoken"), roleList.value = JSON.parse(fileGet);
ltuid: userStore.getCookieItem("ltuid"), }
}; loading.value = false;
}); });
async function getRoleList () { async function refresh () {
loadingTitle.value = "正在获取角色数据";
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); console.log(res);
if (Array.isArray(res)) {
loadingTitle.value = "正在保存角色数据";
await fs.writeTextFile({
path: filePath.value,
contents: JSON.stringify(res),
});
loadingTitle.value = "正在更新角色数据";
roleList.value = res;
}
loading.value = false;
} }
</script> </script>
<style lang="css" scoped> <style lang="css" scoped>
.uc-top {
background: rgba(0, 0, 0, 0.2);
width: 100%;
height: 50px;
border-radius: 5px;
padding: 10px;
display: flex;
align-items: center;
font-family: Genshin, sans-serif;
font-size: 20px;
color: #faf7e8;
}
.uc-top-title {
margin-right: 10px;
}
</style> </style>

View File

@@ -18,12 +18,12 @@ import TGUtils from "../utils/TGUtils";
* @param {TGApp.Sqlite.Account.Game} account 游戏账号 * @param {TGApp.Sqlite.Account.Game} account 游戏账号
* @returns {Promise<TGApp.Game.Character.ListItem[]|TGApp.BBS.Response.Base>} 用户角色列表 * @returns {Promise<TGApp.Game.Character.ListItem[]|TGApp.BBS.Response.Base>} 用户角色列表
*/ */
export async function getGameRoleListByLToken (cookie: Record<string, string>, account: TGApp.Sqlite.Account.Game): Promise<TGApp.Game.Character.ListItem[] | TGApp.BBS.Response.Base> { export async function getGameRoleListByLToken(cookie: TGApp.BBS.Constant.CookieGroup4, account: TGApp.Sqlite.Account.Game): Promise<TGApp.Game.Character.ListItem[] | TGApp.BBS.Response.Base> {
const url = TGApi.GameData.byCookie.getCharacter; const url = TGApi.GameData.byCookie.getCharacter;
const uid = account.gameUid; const uid = account.gameUid;
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
const data = { role_id: uid, server: TGUtils.Tools.getServerByUid(uid) }; const data = { role_id: uid, server: TGUtils.Tools.getServerByUid(uid) };
const header = TGUtils.User.getHeader(cookie, "POST", JSON.stringify(data), "common"); const header = TGUtils.User.getHeader(cookie as unknown as Record<string,string>, "POST", JSON.stringify(data), "common");
return await http.fetch<TGApp.Game.Character.ListResponse>(url, { return await http.fetch<TGApp.Game.Character.ListResponse>(url, {
method: "POST", method: "POST",
headers: header, headers: header,