mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-13 09:28: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";
|
import { fs, window, app, event } from "@tauri-apps/api";
|
||||||
// store
|
// store
|
||||||
import { useAppStore } from "./store/modules/app";
|
import { useAppStore } from "./store/modules/app";
|
||||||
import { useUserStore } from "./store/modules/user";
|
|
||||||
|
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
const userStore = useUserStore();
|
|
||||||
const isMain = ref(true as boolean);
|
const isMain = ref(true as boolean);
|
||||||
const theme = ref(appStore.theme as string);
|
const theme = ref(appStore.theme as string);
|
||||||
|
|
||||||
@@ -52,8 +50,6 @@ onMounted(async () => {
|
|||||||
await win.setTitle(title);
|
await win.setTitle(title);
|
||||||
await checkLoad();
|
await checkLoad();
|
||||||
}
|
}
|
||||||
// 保存 cookie
|
|
||||||
await userStore.initCookie();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 监听主题变化
|
// 监听主题变化
|
||||||
|
|||||||
@@ -106,14 +106,14 @@
|
|||||||
</v-list-group>
|
</v-list-group>
|
||||||
<v-divider />
|
<v-divider />
|
||||||
<div class="bottom-menu">
|
<div class="bottom-menu">
|
||||||
<v-list-item :title="userInfo.nickname" value="user" link href="/user">
|
<v-list-item>
|
||||||
<template #prepend>
|
<template #prepend>
|
||||||
<img :src="userInfo.avatar" alt="userIcon" class="side-icon">
|
<img :src="userInfo.avatar" alt="userIcon" class="side-icon">
|
||||||
</template>
|
</template>
|
||||||
<template #append>
|
<template #default>
|
||||||
<v-icon style="color:var(--sidebar-icon)" @click="refreshUser()">
|
<v-list-item-title>
|
||||||
mdi-refresh
|
{{ userInfo.nickname }}
|
||||||
</v-icon>
|
</v-list-item-title>
|
||||||
</template>
|
</template>
|
||||||
</v-list-item>
|
</v-list-item>
|
||||||
<v-list-item :title="themeTitle" value="theme" @click="switchTheme()">
|
<v-list-item :title="themeTitle" value="theme" @click="switchTheme()">
|
||||||
@@ -148,7 +148,11 @@ const appStore = useAppStore();
|
|||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
|
|
||||||
const userInfo = computed(() => {
|
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);
|
const rail = ref(appStore.sidebar.collapse);
|
||||||
// theme
|
// theme
|
||||||
@@ -183,16 +187,6 @@ onMounted(async () => {
|
|||||||
await listenOnTheme();
|
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 () {
|
async function listenOnTheme () {
|
||||||
await event.listen("readTheme", (e) => {
|
await event.listen("readTheme", (e) => {
|
||||||
const theme = e.payload as string;
|
const theme = e.payload as string;
|
||||||
|
|||||||
@@ -41,6 +41,25 @@
|
|||||||
<v-list-item-subtitle>{{ achievementsStore.lastVersion }}</v-list-item-subtitle>
|
<v-list-item-subtitle>{{ achievementsStore.lastVersion }}</v-list-item-subtitle>
|
||||||
</template>
|
</template>
|
||||||
</v-list-item>
|
</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 inset class="config-header">
|
||||||
系统信息
|
系统信息
|
||||||
</v-list-subheader>
|
</v-list-subheader>
|
||||||
@@ -158,7 +177,7 @@
|
|||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
// vue
|
// vue
|
||||||
import { onMounted, ref } from "vue";
|
import { computed, onMounted, ref } from "vue";
|
||||||
import { getBuildTime } from "../utils/TGBuild";
|
import { getBuildTime } from "../utils/TGBuild";
|
||||||
import TLoading from "../components/t-loading.vue";
|
import TLoading from "../components/t-loading.vue";
|
||||||
import TConfirm from "../components/t-confirm.vue";
|
import TConfirm from "../components/t-confirm.vue";
|
||||||
@@ -196,6 +215,15 @@ const loadingTitle = ref("正在加载..." as string);
|
|||||||
|
|
||||||
// data
|
// data
|
||||||
const showHome = ref(homeStore.getShowValue() as string[]);
|
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
|
// snackbar
|
||||||
const snackbar = ref(false as boolean);
|
const snackbar = ref(false as boolean);
|
||||||
@@ -283,6 +311,12 @@ function tryConfirm (oper: string) {
|
|||||||
confirmOper.value = "resetDB";
|
confirmOper.value = "resetDB";
|
||||||
confirmShow.value = true;
|
confirmShow.value = true;
|
||||||
break;
|
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":
|
case "updateDB":
|
||||||
await updateDB();
|
await updateDB();
|
||||||
break;
|
break;
|
||||||
|
case "refreshUser":
|
||||||
|
await refreshUser();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -409,6 +446,51 @@ function submitHome () {
|
|||||||
snackbar.value = true;
|
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
|
// 输入 Cookie
|
||||||
async function inputCookie () {
|
async function inputCookie () {
|
||||||
const cookie = confirmInput.value;
|
const cookie = confirmInput.value;
|
||||||
@@ -431,7 +513,8 @@ async function inputCookie () {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await TGRequest.User.init(ticket, uid);
|
await TGRequest.User.init(ticket, uid);
|
||||||
await userStore.initCookie();
|
const ck = await TGSqlite.getCookie();
|
||||||
|
await userStore.initCookie(ck);
|
||||||
loadingTitle.value = "正在获取用户信息...";
|
loadingTitle.value = "正在获取用户信息...";
|
||||||
const cookie_token = userStore.getCookieItem("cookie_token");
|
const cookie_token = userStore.getCookieItem("cookie_token");
|
||||||
const res = await TGRequest.User.byCookie.getUserInfo(cookie_token, uid);
|
const res = await TGRequest.User.byCookie.getUserInfo(cookie_token, uid);
|
||||||
@@ -439,6 +522,7 @@ async function inputCookie () {
|
|||||||
if (res.hasOwnProperty("nickname")) {
|
if (res.hasOwnProperty("nickname")) {
|
||||||
const info = res as BTMuli.User.Base.BriefInfo;
|
const info = res as BTMuli.User.Base.BriefInfo;
|
||||||
userStore.setBriefInfo(info);
|
userStore.setBriefInfo(info);
|
||||||
|
appStore.isLogin = true;
|
||||||
}
|
}
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
snackbarText.value = "Cookie 已保存!";
|
snackbarText.value = "Cookie 已保存!";
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* @file store modules app.ts
|
* @file store modules app.ts
|
||||||
* @description App store module
|
* @description App store module
|
||||||
* @author BTMuli<bt-muli@outlook.com>
|
* @author BTMuli<bt-muli@outlook.com>
|
||||||
* @since Alpha v0.1.4
|
* @since Alpha v0.1.5
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// vue
|
// vue
|
||||||
@@ -42,6 +42,8 @@ export const useAppStore = defineStore(
|
|||||||
const devMode = ref(false);
|
const devMode = ref(false);
|
||||||
// 应用主题
|
// 应用主题
|
||||||
const theme = ref("default");
|
const theme = ref("default");
|
||||||
|
// 是否登录
|
||||||
|
const isLogin = ref(false);
|
||||||
|
|
||||||
const dataPath = reactive({
|
const dataPath = reactive({
|
||||||
userDataDir,
|
userDataDir,
|
||||||
@@ -75,6 +77,7 @@ export const useAppStore = defineStore(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
isLogin,
|
||||||
theme,
|
theme,
|
||||||
loading,
|
loading,
|
||||||
buildTime,
|
buildTime,
|
||||||
@@ -97,7 +100,7 @@ export const useAppStore = defineStore(
|
|||||||
{
|
{
|
||||||
key: "app",
|
key: "app",
|
||||||
storage: window.localStorage,
|
storage: window.localStorage,
|
||||||
paths: ["devMode", "loading", "buildTime"],
|
paths: ["devMode", "loading", "buildTime", "isLogin"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "sidebar",
|
key: "sidebar",
|
||||||
|
|||||||
@@ -9,8 +9,6 @@
|
|||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
// pinia
|
// pinia
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
// utils
|
|
||||||
import TGSqlite from "../../utils/TGSqlite";
|
|
||||||
|
|
||||||
export const useUserStore = defineStore(
|
export const useUserStore = defineStore(
|
||||||
"user", () => {
|
"user", () => {
|
||||||
@@ -34,13 +32,14 @@ export const useUserStore = defineStore(
|
|||||||
return cookie.value[key] || "";
|
return cookie.value[key] || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
async function initCookie (): Promise<void> {
|
async function initCookie (ck: Record<string, string>): Promise<void> {
|
||||||
const ck = await TGSqlite.getCookie();
|
|
||||||
if (cookie.value !== ck) {
|
if (cookie.value !== ck) {
|
||||||
cookie.value = ck;
|
cookie.value = ck;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
briefInfo,
|
||||||
|
cookie,
|
||||||
getBriefInfo,
|
getBriefInfo,
|
||||||
setBriefInfo,
|
setBriefInfo,
|
||||||
getCookieItem,
|
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
|
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,
|
headers: header,
|
||||||
body: http.Body.json(params),
|
body: http.Body.json(params),
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
console.log(res);
|
|
||||||
if (res.data.retcode !== 0) return res.data;
|
if (res.data.retcode !== 0) return res.data;
|
||||||
const info = res.data.data.user_info;
|
const info = res.data.data.user_info;
|
||||||
return {
|
return {
|
||||||
nickname: info.nickname,
|
nickname: info.nickname,
|
||||||
uid: info.uid,
|
uid: info.uid,
|
||||||
avatar: info.avatar,
|
avatar: info.avatar_url,
|
||||||
desc: info.introduce,
|
desc: info.introduce,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user