mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-12 09:18:14 +08:00
🎨 根据实际情况修正
This commit is contained in:
@@ -33,10 +33,8 @@ import TBackTop from "./components/t-backTop.vue";
|
||||
import { fs, window, app, event } from "@tauri-apps/api";
|
||||
// store
|
||||
import { useAppStore } from "./store/modules/app";
|
||||
import { useUserStore } from "./store/modules/user";
|
||||
|
||||
const appStore = useAppStore();
|
||||
const userStore = useUserStore();
|
||||
const isMain = ref(true as boolean);
|
||||
const theme = ref(appStore.theme as string);
|
||||
|
||||
@@ -52,8 +50,6 @@ onMounted(async () => {
|
||||
await win.setTitle(title);
|
||||
await checkLoad();
|
||||
}
|
||||
// 保存 cookie
|
||||
await userStore.initCookie();
|
||||
});
|
||||
|
||||
// 监听主题变化
|
||||
|
||||
@@ -106,14 +106,14 @@
|
||||
</v-list-group>
|
||||
<v-divider />
|
||||
<div class="bottom-menu">
|
||||
<v-list-item :title="userInfo.nickname" value="user" link href="/user">
|
||||
<v-list-item>
|
||||
<template #prepend>
|
||||
<img :src="userInfo.avatar" alt="userIcon" class="side-icon">
|
||||
</template>
|
||||
<template #append>
|
||||
<v-icon style="color:var(--sidebar-icon)" @click="refreshUser()">
|
||||
mdi-refresh
|
||||
</v-icon>
|
||||
<template #default>
|
||||
<v-list-item-title>
|
||||
{{ userInfo.nickname }}
|
||||
</v-list-item-title>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-list-item :title="themeTitle" value="theme" @click="switchTheme()">
|
||||
@@ -148,7 +148,11 @@ const appStore = useAppStore();
|
||||
const userStore = useUserStore();
|
||||
|
||||
const userInfo = computed(() => {
|
||||
return userStore.getBriefInfo();
|
||||
const info = userStore.getBriefInfo();
|
||||
return {
|
||||
nickname: info.nickname || "未登录",
|
||||
avatar: info.avatar || "source/UI/defaultUser.webp",
|
||||
};
|
||||
});
|
||||
const rail = ref(appStore.sidebar.collapse);
|
||||
// theme
|
||||
@@ -183,16 +187,6 @@ onMounted(async () => {
|
||||
await listenOnTheme();
|
||||
});
|
||||
|
||||
async function refreshUser () {
|
||||
const cookie_token = userStore.getCookieItem("cookie_token");
|
||||
const account_id = userStore.getCookieItem("account_id");
|
||||
const res = await TGRequest.User.byCookie.getUserInfo(cookie_token, account_id);
|
||||
if (res.hasOwnProperty("nickname")) {
|
||||
const info = res as BTMuli.User.Base.BriefInfo;
|
||||
userStore.setBriefInfo(info);
|
||||
}
|
||||
}
|
||||
|
||||
async function listenOnTheme () {
|
||||
await event.listen("readTheme", (e) => {
|
||||
const theme = e.payload as string;
|
||||
|
||||
@@ -41,6 +41,25 @@
|
||||
<v-list-item-subtitle>{{ achievementsStore.lastVersion }}</v-list-item-subtitle>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-list-item title="登录信息">
|
||||
<v-list-item-subtitle v-show="userInfo.nickname!=='未登录'">
|
||||
{{ userInfo.nickname }} uid:{{ userInfo.uid }}
|
||||
</v-list-item-subtitle>
|
||||
<v-list-item-subtitle v-show="userInfo.nickname==='未登录'">
|
||||
未登录,请输入 Cookie 登录!
|
||||
</v-list-item-subtitle>
|
||||
<template #prepend>
|
||||
<img class="config-icon" :src="userInfo.avatar" alt="Login">
|
||||
</template>
|
||||
<template #append>
|
||||
<v-btn class="card-btn" @click="tryConfirm('refreshUser')">
|
||||
<template #prepend>
|
||||
<img src="../assets/icons/circle-check.svg" alt="check">
|
||||
刷新数据
|
||||
</template>
|
||||
</v-btn>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-list-subheader inset class="config-header">
|
||||
系统信息
|
||||
</v-list-subheader>
|
||||
@@ -158,7 +177,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
// vue
|
||||
import { onMounted, ref } from "vue";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { getBuildTime } from "../utils/TGBuild";
|
||||
import TLoading from "../components/t-loading.vue";
|
||||
import TConfirm from "../components/t-confirm.vue";
|
||||
@@ -196,6 +215,15 @@ const loadingTitle = ref("正在加载..." as string);
|
||||
|
||||
// data
|
||||
const showHome = ref(homeStore.getShowValue() as string[]);
|
||||
const userInfo = computed(() => {
|
||||
const info = userStore.getBriefInfo();
|
||||
return {
|
||||
nickname: info.nickname || "未登录",
|
||||
uid: info.uid || "-1",
|
||||
desc: info.desc || "未登录",
|
||||
avatar: info.avatar || "/source/UI/defaultUser.webp",
|
||||
};
|
||||
});
|
||||
|
||||
// snackbar
|
||||
const snackbar = ref(false as boolean);
|
||||
@@ -283,6 +311,12 @@ function tryConfirm (oper: string) {
|
||||
confirmOper.value = "resetDB";
|
||||
confirmShow.value = true;
|
||||
break;
|
||||
case "refreshUser":
|
||||
confirmText.value = "确认刷新用户信息吗?";
|
||||
confirmSub.value = "将会重新获取用户信息";
|
||||
confirmOper.value = "refreshUser";
|
||||
confirmShow.value = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,6 +353,9 @@ async function doConfirm (oper: string) {
|
||||
case "updateDB":
|
||||
await updateDB();
|
||||
break;
|
||||
case "refreshUser":
|
||||
await refreshUser();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -409,6 +446,51 @@ function submitHome () {
|
||||
snackbar.value = true;
|
||||
}
|
||||
|
||||
// 刷新用户数据
|
||||
async function refreshUser () {
|
||||
const ck = userStore.cookie;
|
||||
let failCount = 0;
|
||||
loadingTitle.value = "正在验证 ltoken...";
|
||||
loading.value = true;
|
||||
const verifyLTokenRes = await TGRequest.User.byLToken.verify(ck.ltoken, ck.ltuid);
|
||||
if (typeof verifyLTokenRes === "string") {
|
||||
loadingTitle.value = "验证成功!正在刷新 cookie_token";
|
||||
} else {
|
||||
loadingTitle.value = "验证失败!正在刷新 cookie_token";
|
||||
failCount++;
|
||||
}
|
||||
const cookieTokenRes = await TGRequest.User.bySToken.getCookieToken(ck.stuid, ck.stoken);
|
||||
if (typeof cookieTokenRes === "string") {
|
||||
ck.cookie_token = cookieTokenRes;
|
||||
await TGSqlite.saveAppData("cookie", JSON.stringify(ck));
|
||||
await userStore.initCookie(ck);
|
||||
console.log(JSON.stringify(ck));
|
||||
loadingTitle.value = "刷新成功!正在获取用户信息";
|
||||
} else {
|
||||
loadingTitle.value = "刷新失败!正在获取用户信息";
|
||||
failCount++;
|
||||
}
|
||||
const infoRes = await TGRequest.User.byCookie.getUserInfo(ck.cookie_token, ck.account_id);
|
||||
if (infoRes.hasOwnProperty("nickname")) {
|
||||
const info = infoRes as BTMuli.User.Base.BriefInfo;
|
||||
userStore.setBriefInfo(info);
|
||||
loadingTitle.value = "获取成功!";
|
||||
} else {
|
||||
loadingTitle.value = "获取失败!";
|
||||
failCount++;
|
||||
}
|
||||
if (failCount === 3) {
|
||||
snackbarText.value = "刷新失败!请重新输入 cookie!";
|
||||
snackbarColor.value = "error";
|
||||
snackbar.value = true;
|
||||
} else {
|
||||
snackbarText.value = "刷新成功!";
|
||||
snackbarColor.value = "success";
|
||||
snackbar.value = true;
|
||||
}
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
// 输入 Cookie
|
||||
async function inputCookie () {
|
||||
const cookie = confirmInput.value;
|
||||
@@ -431,7 +513,8 @@ async function inputCookie () {
|
||||
}
|
||||
try {
|
||||
await TGRequest.User.init(ticket, uid);
|
||||
await userStore.initCookie();
|
||||
const ck = await TGSqlite.getCookie();
|
||||
await userStore.initCookie(ck);
|
||||
loadingTitle.value = "正在获取用户信息...";
|
||||
const cookie_token = userStore.getCookieItem("cookie_token");
|
||||
const res = await TGRequest.User.byCookie.getUserInfo(cookie_token, uid);
|
||||
@@ -439,6 +522,7 @@ async function inputCookie () {
|
||||
if (res.hasOwnProperty("nickname")) {
|
||||
const info = res as BTMuli.User.Base.BriefInfo;
|
||||
userStore.setBriefInfo(info);
|
||||
appStore.isLogin = true;
|
||||
}
|
||||
loading.value = false;
|
||||
snackbarText.value = "Cookie 已保存!";
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @file store modules app.ts
|
||||
* @description App store module
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.1.4
|
||||
* @since Alpha v0.1.5
|
||||
*/
|
||||
|
||||
// vue
|
||||
@@ -42,6 +42,8 @@ export const useAppStore = defineStore(
|
||||
const devMode = ref(false);
|
||||
// 应用主题
|
||||
const theme = ref("default");
|
||||
// 是否登录
|
||||
const isLogin = ref(false);
|
||||
|
||||
const dataPath = reactive({
|
||||
userDataDir,
|
||||
@@ -75,6 +77,7 @@ export const useAppStore = defineStore(
|
||||
}
|
||||
|
||||
return {
|
||||
isLogin,
|
||||
theme,
|
||||
loading,
|
||||
buildTime,
|
||||
@@ -97,7 +100,7 @@ export const useAppStore = defineStore(
|
||||
{
|
||||
key: "app",
|
||||
storage: window.localStorage,
|
||||
paths: ["devMode", "loading", "buildTime"],
|
||||
paths: ["devMode", "loading", "buildTime", "isLogin"],
|
||||
},
|
||||
{
|
||||
key: "sidebar",
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
import { ref } from "vue";
|
||||
// pinia
|
||||
import { defineStore } from "pinia";
|
||||
// utils
|
||||
import TGSqlite from "../../utils/TGSqlite";
|
||||
|
||||
export const useUserStore = defineStore(
|
||||
"user", () => {
|
||||
@@ -34,13 +32,14 @@ export const useUserStore = defineStore(
|
||||
return cookie.value[key] || "";
|
||||
}
|
||||
|
||||
async function initCookie (): Promise<void> {
|
||||
const ck = await TGSqlite.getCookie();
|
||||
async function initCookie (ck: Record<string, string>): Promise<void> {
|
||||
if (cookie.value !== ck) {
|
||||
cookie.value = ck;
|
||||
}
|
||||
}
|
||||
return {
|
||||
briefInfo,
|
||||
cookie,
|
||||
getBriefInfo,
|
||||
setBriefInfo,
|
||||
getCookieItem,
|
||||
@@ -48,6 +47,14 @@ export const useUserStore = defineStore(
|
||||
};
|
||||
},
|
||||
{
|
||||
persist: true,
|
||||
persist: [{
|
||||
key: "cookie",
|
||||
storage: window.localStorage,
|
||||
paths: ["cookie"],
|
||||
}, {
|
||||
key: "briefInfo",
|
||||
storage: window.localStorage,
|
||||
paths: ["briefInfo"],
|
||||
}],
|
||||
},
|
||||
);
|
||||
|
||||
@@ -7,4 +7,4 @@
|
||||
|
||||
const BBS_API = "https://bbs-api.miyoushe.com/"; // 基础 API
|
||||
|
||||
export const BBSUserInfoAPI = `${BBS_API}user/wapi/getUserFullInfo`; // 用户信息 API
|
||||
export const BBSUserInfoApi = `${BBS_API}user/wapi/getUserFullInfo`; // 用户信息 API
|
||||
|
||||
@@ -34,13 +34,12 @@ export async function getUserInfoByCookie (cookie_token: string, account_id: str
|
||||
headers: header,
|
||||
body: http.Body.json(params),
|
||||
}).then((res) => {
|
||||
console.log(res);
|
||||
if (res.data.retcode !== 0) return res.data;
|
||||
const info = res.data.data.user_info;
|
||||
return {
|
||||
nickname: info.nickname,
|
||||
uid: info.uid,
|
||||
avatar: info.avatar,
|
||||
avatar: info.avatar_url,
|
||||
desc: info.introduce,
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user