mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-15 09:48:14 +08:00
♻️ 全面整理重构
This commit is contained in:
@@ -23,35 +23,33 @@
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { app } from "@tauri-apps/api";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { onMounted, ref } from "vue";
|
||||
|
||||
import { useAppStore } from "../../store/modules/app.js";
|
||||
import { useAppStore } from "@/store/modules/app.js";
|
||||
|
||||
const appStore = useAppStore();
|
||||
const { buildTime } = storeToRefs(useAppStore());
|
||||
const versionApp = ref<string>();
|
||||
const buildTime = computed(() => appStore.buildTime);
|
||||
|
||||
onMounted(async () => {
|
||||
versionApp.value = await app.getVersion();
|
||||
});
|
||||
onMounted(async () => (versionApp.value = await app.getVersion()));
|
||||
|
||||
function toRelease() {
|
||||
function toRelease(): void {
|
||||
window.open("https://github.com/BTMuli/TeyvatGuide/releases/latest");
|
||||
}
|
||||
|
||||
function toGroup() {
|
||||
function toGroup(): void {
|
||||
window.open("https://h5.qun.qq.com/s/3cgX0hJ4GA");
|
||||
}
|
||||
|
||||
function toGithub() {
|
||||
function toGithub(): void {
|
||||
window.open("https://github.com/BTMuli/TeyvatGuide");
|
||||
}
|
||||
|
||||
function toStore() {
|
||||
function toStore(): void {
|
||||
window.open("https://www.microsoft.com/store/productId/9NLBNNNBNSJN");
|
||||
}
|
||||
|
||||
function toSite() {
|
||||
function toSite(): void {
|
||||
window.open("https://app.btmuli.ink/docs/TeyvatGuide/changelogs.html");
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<v-list class="config-list">
|
||||
<v-list-subheader :inset="true" class="config-header" title="路径" />
|
||||
<v-divider :inset="true" class="border-opacity-75" />
|
||||
<v-list-item title="用户数据目录" :subtitle="appStore.userDir.value">
|
||||
<v-list-item title="用户数据目录" :subtitle="userDir">
|
||||
<template #prepend>
|
||||
<div class="config-icon">
|
||||
<v-icon>mdi-folder-key</v-icon>
|
||||
@@ -16,7 +16,7 @@
|
||||
</div>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-list-item title="应用数据库路径" :subtitle="appStore.dbPath.value">
|
||||
<v-list-item title="应用数据库路径" :subtitle="dbPath">
|
||||
<template #prepend>
|
||||
<div class="config-icon">
|
||||
<v-icon>mdi-folder-account</v-icon>
|
||||
@@ -29,11 +29,7 @@
|
||||
</div>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-list-item
|
||||
title="游戏安装目录"
|
||||
:subtitle="appStore.gameDir.value"
|
||||
v-if="platform() === 'windows'"
|
||||
>
|
||||
<v-list-item title="游戏安装目录" :subtitle="gameDir" v-if="platform() === 'windows'">
|
||||
<template #prepend>
|
||||
<div class="config-icon">
|
||||
<v-icon>mdi-gamepad</v-icon>
|
||||
@@ -47,7 +43,7 @@
|
||||
</div>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-list-item title="日志目录" :subtitle="appStore.logDir.value">
|
||||
<v-list-item title="日志目录" :subtitle="logDir">
|
||||
<template #prepend>
|
||||
<div class="config-icon">
|
||||
<v-icon>mdi-folder-multiple</v-icon>
|
||||
@@ -64,6 +60,9 @@
|
||||
</v-list>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import showDialog from "@comp/func/dialog.js";
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
import TGSqlite from "@Sqlite/index.js";
|
||||
import { path } from "@tauri-apps/api";
|
||||
import { open } from "@tauri-apps/plugin-dialog";
|
||||
import { exists, readDir, remove } from "@tauri-apps/plugin-fs";
|
||||
@@ -71,45 +70,36 @@ import { platform } from "@tauri-apps/plugin-os";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { onMounted } from "vue";
|
||||
|
||||
import TGSqlite from "../../plugins/Sqlite/index.js";
|
||||
import { useAppStore } from "../../store/modules/app.js";
|
||||
import { backUpUserData } from "../../utils/dataBS.js";
|
||||
import TGShell from "../../utils/TGShell.js";
|
||||
import showDialog from "../func/dialog.js";
|
||||
import showSnackbar from "../func/snackbar.js";
|
||||
import { useAppStore } from "@/store/modules/app.js";
|
||||
import { backUpUserData } from "@/utils/dataBS.js";
|
||||
import TGShell from "@/utils/TGShell.js";
|
||||
|
||||
const appStore = storeToRefs(useAppStore());
|
||||
const { dbPath, logDir, userDir, gameDir } = storeToRefs(useAppStore());
|
||||
|
||||
onMounted(async () => {
|
||||
const logDir = await path.appLogDir();
|
||||
const dbPath = `${await path.appConfigDir()}${path.sep()}TeyvatGuide.db`;
|
||||
const logDirGet = await path.appLogDir();
|
||||
const dbPathGet = `${await path.appConfigDir()}${path.sep()}TeyvatGuide.db`;
|
||||
let message = "";
|
||||
if (appStore.dbPath.value !== dbPath) {
|
||||
appStore.dbPath.value = dbPath;
|
||||
await TGSqlite.saveAppData("dbPath", dbPath);
|
||||
if (dbPath.value !== dbPathGet) {
|
||||
dbPath.value = dbPathGet;
|
||||
await TGSqlite.saveAppData("dbPath", dbPathGet);
|
||||
message += "数据库路径 ";
|
||||
}
|
||||
if (appStore.logDir.value !== logDir) {
|
||||
appStore.logDir.value = logDir;
|
||||
if (logDir.value !== logDirGet) {
|
||||
logDir.value = logDirGet;
|
||||
message += "日志路径 ";
|
||||
}
|
||||
if (message !== "") {
|
||||
showSnackbar.success(`${message}已更新!`);
|
||||
}
|
||||
if (message !== "") showSnackbar.success(`${message}已更新!`);
|
||||
});
|
||||
|
||||
async function confirmCUD(): Promise<void> {
|
||||
const oriDir = appStore.userDir.value;
|
||||
const oriDir = userDir.value;
|
||||
const changeCheck = await showDialog.check("确认修改用户数据路径吗?");
|
||||
if (!changeCheck) {
|
||||
showSnackbar.cancel("已取消修改");
|
||||
return;
|
||||
}
|
||||
const dir: string | null = await open({
|
||||
directory: true,
|
||||
defaultPath: oriDir,
|
||||
multiple: false,
|
||||
});
|
||||
const dir: string | null = await open({ directory: true, defaultPath: oriDir, multiple: false });
|
||||
if (dir === null) {
|
||||
showSnackbar.warn("路径不能为空!");
|
||||
return;
|
||||
@@ -118,7 +108,7 @@ async function confirmCUD(): Promise<void> {
|
||||
showSnackbar.warn("路径未修改!");
|
||||
return;
|
||||
}
|
||||
appStore.userDir.value = dir;
|
||||
userDir.value = dir;
|
||||
await TGSqlite.saveAppData("userDir", dir);
|
||||
await backUpUserData(dir);
|
||||
showSnackbar.success("已修改用户数据路径!");
|
||||
@@ -135,10 +125,10 @@ async function confirmCGD(): Promise<void> {
|
||||
showSnackbar.warn("不支持的平台!");
|
||||
return;
|
||||
}
|
||||
const oriEmpty = appStore.gameDir.value === "未设置";
|
||||
const oriEmpty = gameDir.value === "未设置";
|
||||
const editCheck = await showDialog.check(
|
||||
oriEmpty ? "确认设置游戏目录?" : "确认修改游戏目录?",
|
||||
oriEmpty ? "请选择启动器所在目录" : `当前:${appStore.gameDir.value}`,
|
||||
oriEmpty ? "请选择启动器所在目录" : `当前:${gameDir.value}`,
|
||||
);
|
||||
if (!editCheck) {
|
||||
showSnackbar.cancel(oriEmpty ? "已取消设置" : "已取消修改");
|
||||
@@ -146,14 +136,14 @@ async function confirmCGD(): Promise<void> {
|
||||
}
|
||||
const dir: string | null = await open({
|
||||
directory: true,
|
||||
defaultPath: oriEmpty ? undefined : appStore.gameDir.value,
|
||||
defaultPath: oriEmpty ? undefined : gameDir.value,
|
||||
multiple: false,
|
||||
});
|
||||
if (dir === null) {
|
||||
showSnackbar.warn("路径不能为空!");
|
||||
return;
|
||||
}
|
||||
if (!oriEmpty && appStore.gameDir.value === dir) {
|
||||
if (!oriEmpty && gameDir.value === dir) {
|
||||
showSnackbar.warn("路径未修改!");
|
||||
return;
|
||||
}
|
||||
@@ -162,7 +152,7 @@ async function confirmCGD(): Promise<void> {
|
||||
showSnackbar.warn("未检测到游戏本体");
|
||||
return;
|
||||
}
|
||||
appStore.gameDir.value = dir;
|
||||
gameDir.value = dir;
|
||||
showSnackbar.success(oriEmpty ? "成功设置游戏目录" : "成功修改游戏目录");
|
||||
}
|
||||
|
||||
@@ -180,8 +170,7 @@ async function confirmCLD(): Promise<void> {
|
||||
showSnackbar.cancel("已取消清理");
|
||||
return;
|
||||
}
|
||||
const logDir = appStore.logDir.value;
|
||||
const files = await readDir(logDir);
|
||||
const files = await readDir(logDir.value);
|
||||
const delFiles = files.filter((file) => {
|
||||
// yyyy-mm-dd.log
|
||||
const reg = /(\d{4}-\d{2}-\d{2}\.log)/;
|
||||
@@ -205,23 +194,23 @@ function copyPath(type: "db" | "user" | "log" | "game"): void {
|
||||
let targetPath: string, targetName: string;
|
||||
switch (type) {
|
||||
case "db":
|
||||
targetPath = appStore.dbPath.value;
|
||||
targetPath = dbPath.value;
|
||||
targetName = "数据库";
|
||||
break;
|
||||
case "user":
|
||||
targetPath = appStore.userDir.value;
|
||||
targetPath = userDir.value;
|
||||
targetName = "用户数据";
|
||||
break;
|
||||
case "log":
|
||||
targetPath = appStore.logDir.value;
|
||||
targetPath = logDir.value;
|
||||
targetName = "日志";
|
||||
break;
|
||||
case "game":
|
||||
if (appStore.gameDir.value === "未设置") {
|
||||
if (gameDir.value === "未设置") {
|
||||
showSnackbar.warn("未设置游戏目录!");
|
||||
return;
|
||||
}
|
||||
targetPath = appStore.gameDir.value;
|
||||
targetPath = gameDir.value;
|
||||
targetName = "游戏安装目录";
|
||||
}
|
||||
navigator.clipboard.writeText(targetPath);
|
||||
@@ -235,17 +224,17 @@ async function openPath(type: "db" | "user" | "log" | "game"): Promise<void> {
|
||||
targetPath = await path.appConfigDir();
|
||||
break;
|
||||
case "user":
|
||||
targetPath = appStore.userDir.value;
|
||||
targetPath = userDir.value;
|
||||
break;
|
||||
case "log":
|
||||
targetPath = appStore.logDir.value;
|
||||
targetPath = logDir.value;
|
||||
break;
|
||||
case "game":
|
||||
if (appStore.gameDir.value === "未设置") {
|
||||
if (gameDir.value === "未设置") {
|
||||
showSnackbar.warn("未设置游戏目录!");
|
||||
return;
|
||||
}
|
||||
targetPath = appStore.gameDir.value;
|
||||
targetPath = gameDir.value;
|
||||
break;
|
||||
}
|
||||
await TGShell.openPath(targetPath);
|
||||
|
||||
@@ -16,24 +16,22 @@
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
import { path } from "@tauri-apps/api";
|
||||
import { exists } from "@tauri-apps/plugin-fs";
|
||||
import { Command } from "@tauri-apps/plugin-shell";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed } from "vue";
|
||||
|
||||
import { useAppStore } from "../../store/modules/app.js";
|
||||
import { useUserStore } from "../../store/modules/user.js";
|
||||
import TGLogger from "../../utils/TGLogger.js";
|
||||
import PassportApi from "../../web/request/passportReq.js";
|
||||
import showSnackbar from "../func/snackbar.js";
|
||||
import { useAppStore } from "@/store/modules/app.js";
|
||||
import { useUserStore } from "@/store/modules/user.js";
|
||||
import TGLogger from "@/utils/TGLogger.js";
|
||||
import PassportApi from "@/web/request/passportReq.js";
|
||||
|
||||
const userStore = storeToRefs(useUserStore());
|
||||
const appStore = storeToRefs(useAppStore());
|
||||
const account = computed<TGApp.Sqlite.Account.Game>(() => userStore.account.value);
|
||||
const { gameDir } = storeToRefs(useAppStore());
|
||||
const { account, uid, cookie } = storeToRefs(useUserStore());
|
||||
|
||||
async function tryPlayGame(): Promise<void> {
|
||||
if (!userStore.uid.value || !userStore.cookie.value) {
|
||||
if (!uid.value || !cookie.value) {
|
||||
showSnackbar.warn("请先登录!");
|
||||
return;
|
||||
}
|
||||
@@ -41,16 +39,16 @@ async function tryPlayGame(): Promise<void> {
|
||||
showSnackbar.warn("仅支持官服用户启动!");
|
||||
return;
|
||||
}
|
||||
if (appStore.gameDir.value === "未设置") {
|
||||
if (gameDir.value === "未设置") {
|
||||
showSnackbar.warn("未设置游戏安装目录!");
|
||||
return;
|
||||
}
|
||||
const gamePath = `${appStore.gameDir.value}${path.sep()}YuanShen.exe`;
|
||||
const gamePath = `${gameDir.value}${path.sep()}YuanShen.exe`;
|
||||
if (!(await exists(gamePath))) {
|
||||
showSnackbar.warn("未检测到原神本体应用!");
|
||||
return;
|
||||
}
|
||||
const resp = await PassportApi.authTicket(account.value, userStore.cookie.value);
|
||||
const resp = await PassportApi.authTicket(account.value, cookie.value);
|
||||
if (typeof resp !== "string") {
|
||||
showSnackbar.error(`[${resp.retcode}] ${resp.message}`);
|
||||
await TGLogger.Error(
|
||||
@@ -61,7 +59,7 @@ async function tryPlayGame(): Promise<void> {
|
||||
}
|
||||
showSnackbar.success(`成功获取ticket:${resp},正在启动应用...`);
|
||||
const cmd = Command.create("exec-sh", [`&"${gamePath}" login_auth_ticket=${resp}`], {
|
||||
cwd: appStore.gameDir.value,
|
||||
cwd: gameDir.value,
|
||||
encoding: "utf-8",
|
||||
});
|
||||
console.log(cmd);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
</v-list-item>
|
||||
<v-list-item title="成就版本">
|
||||
<template #prepend>
|
||||
<img class="config-icon" src="../../assets/icons/achievements.svg" alt="Achievements" />
|
||||
<img class="config-icon" src="@/assets/icons/achievements.svg" alt="Achievements" />
|
||||
</template>
|
||||
<template #append>
|
||||
<v-list-item-subtitle>{{ latestAchiVersion }}</v-list-item-subtitle>
|
||||
@@ -45,13 +45,13 @@
|
||||
</div>
|
||||
</template>
|
||||
<template #append>
|
||||
<v-list-item-subtitle
|
||||
>{{ dbInfo.find((item) => item.key === "dataUpdated")?.value }}
|
||||
<v-list-item-subtitle>
|
||||
{{ dbInfo.find((item) => item.key === "dataUpdated")?.value }}
|
||||
</v-list-item-subtitle>
|
||||
</template>
|
||||
<v-list-item-subtitle
|
||||
>更新于
|
||||
{{ dbInfo.find((item) => item.key === "dataUpdated")?.updated }}
|
||||
<v-list-item-subtitle>
|
||||
<span>更新于</span>
|
||||
<span>{{ dbInfo.find((item) => item.key === "dataUpdated")?.updated }}</span>
|
||||
</v-list-item-subtitle>
|
||||
</v-list-item>
|
||||
<v-list-item title="数据库版本">
|
||||
@@ -61,41 +61,40 @@
|
||||
</div>
|
||||
</template>
|
||||
<template #append>
|
||||
<v-list-item-subtitle
|
||||
>{{ dbInfo.find((item) => item.key === "appVersion")?.value }}
|
||||
<v-list-item-subtitle>
|
||||
{{ dbInfo.find((item) => item.key === "appVersion")?.value }}
|
||||
</v-list-item-subtitle>
|
||||
</template>
|
||||
<v-list-item-subtitle
|
||||
>更新于
|
||||
{{ dbInfo.find((item) => item.key === "appVersion")?.updated }}
|
||||
<v-list-item-subtitle>
|
||||
<span>更新于</span>
|
||||
<span>{{ dbInfo.find((item) => item.key === "appVersion")?.updated }}</span>
|
||||
</v-list-item-subtitle>
|
||||
</v-list-item>
|
||||
</v-list>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
import TGSqlite from "@Sqlite/index.js";
|
||||
import TSUserAchi from "@Sqlite/modules/userAchi.js";
|
||||
import { app } from "@tauri-apps/api";
|
||||
import { platform, version } from "@tauri-apps/plugin-os";
|
||||
import { onMounted, ref } from "vue";
|
||||
import { onMounted, ref, shallowRef } from "vue";
|
||||
|
||||
import TGSqlite from "../../plugins/Sqlite/index.js";
|
||||
import TSUserAchi from "../../plugins/Sqlite/modules/userAchi.js";
|
||||
import TGLogger from "../../utils/TGLogger.js";
|
||||
import showSnackbar from "../func/snackbar.js";
|
||||
import TGLogger from "@/utils/TGLogger.js";
|
||||
|
||||
const latestAchiVersion = TSUserAchi.getLatestAchiVersion();
|
||||
const osPlatform = platform();
|
||||
const osVersion = version();
|
||||
|
||||
const versionApp = ref<string>("");
|
||||
const versionTauri = ref<string>("");
|
||||
const osPlatform = ref<string>("");
|
||||
const iconPlatform = ref<string>("mdi-microsoft-windows");
|
||||
const osVersion = ref<string>("");
|
||||
const dbInfo = ref<Array<TGApp.Sqlite.AppData.Item>>([]);
|
||||
const dbInfo = shallowRef<Array<TGApp.Sqlite.AppData.Item>>([]);
|
||||
|
||||
onMounted(async () => {
|
||||
versionApp.value = await app.getVersion();
|
||||
versionTauri.value = await app.getTauriVersion();
|
||||
osPlatform.value = platform();
|
||||
switch (osPlatform.value) {
|
||||
switch (osPlatform) {
|
||||
case "linux":
|
||||
iconPlatform.value = "mdi-linux";
|
||||
break;
|
||||
@@ -112,16 +111,20 @@ onMounted(async () => {
|
||||
iconPlatform.value = "mdi-desktop-classic";
|
||||
break;
|
||||
}
|
||||
osVersion.value = version();
|
||||
try {
|
||||
dbInfo.value = await TGSqlite.getAppData();
|
||||
} catch (e) {
|
||||
if (e instanceof Error) {
|
||||
showSnackbar.warn(`加载数据库错误: ${e.message}`);
|
||||
await TGLogger.Error(`加载数据库错误: ${e.message}`);
|
||||
return;
|
||||
}
|
||||
showSnackbar.warn("加载数据库错误,请重置数据库!");
|
||||
await TGLogger.Error(`加载数据库错误: ${e}`);
|
||||
}
|
||||
});
|
||||
|
||||
function toOuter(url: string) {
|
||||
function toOuter(url: string): void {
|
||||
window.open(url);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -19,16 +19,14 @@
|
||||
</template>
|
||||
<v-list>
|
||||
<v-list-item
|
||||
v-for="account in gameAccounts"
|
||||
:key="account.gameUid"
|
||||
@click="useUserStore().switchGameAccount(account.gameUid)"
|
||||
v-for="ac in gameAccounts"
|
||||
:key="ac.gameUid"
|
||||
@click="useUserStore().switchGameAccount(ac.gameUid)"
|
||||
>
|
||||
<v-list-item-title>{{ account.nickname }}</v-list-item-title>
|
||||
<v-list-item-subtitle>
|
||||
{{ account.gameUid }}({{ account.regionName }})
|
||||
</v-list-item-subtitle>
|
||||
<v-list-item-title>{{ ac.nickname }}</v-list-item-title>
|
||||
<v-list-item-subtitle> {{ ac.gameUid }}({{ ac.regionName }}) </v-list-item-subtitle>
|
||||
<template #append>
|
||||
<div v-if="account.gameUid === userStore.account.value.gameUid" title="当前登录账号">
|
||||
<div v-if="ac.gameUid === account.gameUid" title="当前登录账号">
|
||||
<v-icon color="green">mdi-check</v-icon>
|
||||
</div>
|
||||
</template>
|
||||
@@ -46,15 +44,15 @@
|
||||
/>
|
||||
<v-btn
|
||||
variant="outlined"
|
||||
@click="confirmRefreshUser(userStore.uid.value!)"
|
||||
:disabled="userStore.uid.value === undefined"
|
||||
@click="confirmRefreshUser(uid!)"
|
||||
:disabled="uid === undefined"
|
||||
icon="mdi-refresh"
|
||||
title="刷新用户信息"
|
||||
/>
|
||||
<v-btn
|
||||
variant="outlined"
|
||||
@click="confirmCopyCookie"
|
||||
:disabled="!userStore.cookie.value"
|
||||
:disabled="cookie === undefined"
|
||||
icon="mdi-cookie"
|
||||
title="复制Cookie"
|
||||
/>
|
||||
@@ -69,11 +67,11 @@
|
||||
/>
|
||||
</template>
|
||||
<v-list>
|
||||
<v-list-item v-for="account in accounts" :key="account.uid">
|
||||
<v-list-item-title>{{ account.brief.nickname }}</v-list-item-title>
|
||||
<v-list-item-subtitle>{{ account.brief.uid }}</v-list-item-subtitle>
|
||||
<v-list-item v-for="ac in accounts" :key="ac.uid">
|
||||
<v-list-item-title>{{ ac.brief.nickname }}</v-list-item-title>
|
||||
<v-list-item-subtitle>{{ ac.brief.uid }}</v-list-item-subtitle>
|
||||
<template #append>
|
||||
<div v-if="account.uid === userStore.uid.value" title="当前登录账号">
|
||||
<div v-if="ac.uid === uid" title="当前登录账号">
|
||||
<v-icon color="green">mdi-account-check</v-icon>
|
||||
</div>
|
||||
<v-icon
|
||||
@@ -81,14 +79,14 @@
|
||||
size="small"
|
||||
icon="mdi-account-convert"
|
||||
title="切换用户"
|
||||
@click="loadAccount(account.uid)"
|
||||
@click="loadAccount(ac.uid)"
|
||||
/>
|
||||
<v-icon
|
||||
class="tcu-btn"
|
||||
icon="mdi-delete"
|
||||
title="删除用户"
|
||||
size="small"
|
||||
@click="clearUser(account)"
|
||||
@click="clearUser(ac)"
|
||||
/>
|
||||
</template>
|
||||
</v-list-item>
|
||||
@@ -102,36 +100,35 @@
|
||||
</v-card>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import showDialog from "@comp/func/dialog.js";
|
||||
import showGeetest from "@comp/func/geetest.js";
|
||||
import showLoading from "@comp/func/loading.js";
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
import Mys from "@Mys/index.js";
|
||||
import TSUserAccount from "@Sqlite/modules/userAccount.js";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed, ref } from "vue";
|
||||
import { computed, shallowRef } from "vue";
|
||||
|
||||
import Mys from "../../plugins/Mys/index.js";
|
||||
import TSUserAccount from "../../plugins/Sqlite/modules/userAccount.js";
|
||||
import { useAppStore } from "../../store/modules/app.js";
|
||||
import { useUserStore } from "../../store/modules/user.js";
|
||||
import TGLogger from "../../utils/TGLogger.js";
|
||||
import BBSApi from "../../web/request/bbsReq.js";
|
||||
import PassportApi from "../../web/request/passportReq.js";
|
||||
import TakumiApi from "../../web/request/takumiReq.js";
|
||||
import showDialog from "../func/dialog.js";
|
||||
import showGeetest from "../func/geetest.js";
|
||||
import showLoading from "../func/loading.js";
|
||||
import showSnackbar from "../func/snackbar.js";
|
||||
import { useAppStore } from "@/store/modules/app.js";
|
||||
import { useUserStore } from "@/store/modules/user.js";
|
||||
import TGLogger from "@/utils/TGLogger.js";
|
||||
import BBSApi from "@/web/request/bbsReq.js";
|
||||
import PassportApi from "@/web/request/passportReq.js";
|
||||
import TakumiApi from "@/web/request/takumiReq.js";
|
||||
|
||||
const userStore = storeToRefs(useUserStore());
|
||||
const appStore = storeToRefs(useAppStore());
|
||||
const { isLogin } = storeToRefs(useAppStore());
|
||||
const { uid, briefInfo, cookie, account } = storeToRefs(useUserStore());
|
||||
|
||||
const accounts = ref<TGApp.App.Account.User[]>([]);
|
||||
const gameAccounts = ref<TGApp.Sqlite.Account.Game[]>([]);
|
||||
const accounts = shallowRef<Array<TGApp.App.Account.User>>([]);
|
||||
const gameAccounts = shallowRef<Array<TGApp.Sqlite.Account.Game>>([]);
|
||||
const userInfo = computed<TGApp.App.Account.BriefInfo>(() => {
|
||||
if (userStore.uid.value === undefined)
|
||||
return {
|
||||
nickname: "未登录",
|
||||
uid: "-1",
|
||||
desc: "请使用短信验证码登录",
|
||||
avatar: "/source/UI/lumine.webp",
|
||||
};
|
||||
return userStore.briefInfo.value;
|
||||
if (uid.value) return briefInfo.value;
|
||||
return {
|
||||
nickname: "未登录",
|
||||
uid: "-1",
|
||||
desc: "请使用短信验证码登录",
|
||||
avatar: "/source/UI/lumine.webp",
|
||||
};
|
||||
});
|
||||
|
||||
async function tryCaptchaLogin(): Promise<void> {
|
||||
@@ -196,7 +193,7 @@ async function tryCaptchaLogin(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
showSnackbar.success("获取用户信息成功");
|
||||
const briefInfo: TGApp.App.Account.BriefInfo = {
|
||||
const briefInfoGet: TGApp.App.Account.BriefInfo = {
|
||||
nickname: briefRes.nickname,
|
||||
uid: briefRes.uid,
|
||||
avatar: briefRes.avatar_url,
|
||||
@@ -204,17 +201,17 @@ async function tryCaptchaLogin(): Promise<void> {
|
||||
};
|
||||
showLoading.update("正在登录...", "正在保存用户数据");
|
||||
await TSUserAccount.account.saveAccount({
|
||||
uid: briefInfo.uid,
|
||||
uid: briefInfoGet.uid,
|
||||
cookie: ck,
|
||||
brief: briefInfo,
|
||||
brief: briefInfoGet,
|
||||
updated: "",
|
||||
});
|
||||
userStore.uid.value = briefInfo.uid;
|
||||
userStore.briefInfo.value = briefInfo;
|
||||
userStore.cookie.value = ck;
|
||||
appStore.isLogin.value = true;
|
||||
uid.value = briefInfoGet.uid;
|
||||
briefInfo.value = briefInfoGet;
|
||||
cookie.value = ck;
|
||||
isLogin.value = true;
|
||||
showLoading.update("正在登录...", "正在获取游戏账号");
|
||||
const gameRes = await TakumiApi.bind.gameRoles(userStore.cookie.value);
|
||||
const gameRes = await TakumiApi.bind.gameRoles(cookie.value);
|
||||
if (!Array.isArray(gameRes)) {
|
||||
showLoading.end();
|
||||
showSnackbar.error(`[${gameRes.retcode}]${gameRes.message}`);
|
||||
@@ -222,14 +219,14 @@ async function tryCaptchaLogin(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
showSnackbar.success("获取游戏账号成功");
|
||||
await TSUserAccount.game.saveAccounts(briefInfo.uid, gameRes);
|
||||
const curAccount = await TSUserAccount.game.getCurAccount(briefInfo.uid);
|
||||
await TSUserAccount.game.saveAccounts(briefInfoGet.uid, gameRes);
|
||||
const curAccount = await TSUserAccount.game.getCurAccount(briefInfoGet.uid);
|
||||
if (!curAccount) {
|
||||
showSnackbar.warn("未检测到游戏账号,请重新刷新");
|
||||
showLoading.end();
|
||||
return;
|
||||
}
|
||||
userStore.account.value = curAccount;
|
||||
account.value = curAccount;
|
||||
showLoading.end();
|
||||
showSnackbar.success("成功登录!");
|
||||
}
|
||||
@@ -318,46 +315,46 @@ async function refreshUser(uid: string) {
|
||||
showLoading.end();
|
||||
}
|
||||
|
||||
async function loadAccount(uid: string): Promise<void> {
|
||||
if (userStore.uid.value && uid === userStore.uid.value) {
|
||||
async function loadAccount(ac: string): Promise<void> {
|
||||
if (uid.value && ac === uid.value) {
|
||||
showSnackbar.warn("该账户已经登录,无需切换");
|
||||
return;
|
||||
}
|
||||
const account = await TSUserAccount.account.getAccount(uid);
|
||||
if (!account) {
|
||||
const accountGet = await TSUserAccount.account.getAccount(ac);
|
||||
if (!accountGet) {
|
||||
showSnackbar.warn(`未找到${uid}的账号信息,请重新登录`);
|
||||
return;
|
||||
}
|
||||
userStore.uid.value = uid;
|
||||
userStore.briefInfo.value = account.brief;
|
||||
userStore.cookie.value = account.cookie;
|
||||
const gameAccount = await TSUserAccount.game.getCurAccount(uid);
|
||||
uid.value = ac;
|
||||
briefInfo.value = accountGet.brief;
|
||||
cookie.value = accountGet.cookie;
|
||||
const gameAccount = await TSUserAccount.game.getCurAccount(ac);
|
||||
if (!gameAccount) {
|
||||
showSnackbar.warn(`未找到${uid}的游戏账号信息,请尝试刷新`);
|
||||
return;
|
||||
}
|
||||
userStore.account.value = gameAccount;
|
||||
account.value = gameAccount;
|
||||
showSnackbar.success(`成功切换到用户${uid}`);
|
||||
}
|
||||
|
||||
async function confirmRefreshUser(uid: string): Promise<void> {
|
||||
async function confirmRefreshUser(ac: string): Promise<void> {
|
||||
const freshCheck = await showDialog.check("确认刷新用户信息吗?", "将会重新获取用户信息");
|
||||
if (!freshCheck) {
|
||||
showSnackbar.cancel("已取消刷新用户信息");
|
||||
return;
|
||||
}
|
||||
await refreshUser(uid);
|
||||
if (userStore.uid.value === uid) {
|
||||
await refreshUser(ac);
|
||||
if (uid.value === ac) {
|
||||
showSnackbar.success("成功刷新用户信息");
|
||||
return;
|
||||
}
|
||||
const switchCheck = await showDialog.check("是否切换用户?", `将切换到用户${uid}`);
|
||||
const switchCheck = await showDialog.check("是否切换用户?", `将切换到用户${ac}`);
|
||||
if (!switchCheck) return;
|
||||
await loadAccount(uid);
|
||||
await loadAccount(ac);
|
||||
}
|
||||
|
||||
async function confirmCopyCookie(): Promise<void> {
|
||||
if (!userStore.cookie.value) {
|
||||
if (!cookie.value) {
|
||||
showSnackbar.warn("请先登录");
|
||||
return;
|
||||
}
|
||||
@@ -366,7 +363,7 @@ async function confirmCopyCookie(): Promise<void> {
|
||||
showSnackbar.cancel("已取消复制 Cookie");
|
||||
return;
|
||||
}
|
||||
const ckText = TSUserAccount.account.copy(userStore.cookie.value);
|
||||
const ckText = TSUserAccount.account.copy(cookie.value);
|
||||
await navigator.clipboard.writeText(ckText);
|
||||
showSnackbar.success("已复制 Cookie!");
|
||||
}
|
||||
@@ -411,11 +408,11 @@ async function showMenu(): Promise<void> {
|
||||
}
|
||||
|
||||
async function showAccounts(): Promise<void> {
|
||||
if (!userStore.uid.value) {
|
||||
if (!uid.value) {
|
||||
showSnackbar.warn("未登录!");
|
||||
return;
|
||||
}
|
||||
gameAccounts.value = await TSUserAccount.game.getAccount(userStore.uid.value);
|
||||
gameAccounts.value = await TSUserAccount.game.getAccount(uid.value);
|
||||
if (gameAccounts.value.length === 0) {
|
||||
showSnackbar.warn("未找到账户的游戏数据,请尝试刷新!");
|
||||
return;
|
||||
@@ -515,7 +512,7 @@ async function addByCookie(): Promise<void> {
|
||||
}
|
||||
|
||||
async function clearUser(user: TGApp.App.Account.User): Promise<void> {
|
||||
if (user.uid === userStore.uid.value) {
|
||||
if (user.uid === uid.value) {
|
||||
showSnackbar.warn("当前登录用户不许删除!");
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user