From fc43ed15d0b0b50d1b09e745b3c830ffa3d18635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9B=AE=E6=A3=83?= Date: Sun, 22 Sep 2024 19:14:09 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=89=8B=E5=8A=A8=E8=BE=93?= =?UTF-8?q?=E5=85=A5CK&=E7=94=A8=E6=88=B7=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #126 --- src/components/app/t-sidebar.vue | 1 + src/components/config/tc-userBadge.vue | 146 +++++++++++++++++++++- src/plugins/Sqlite/modules/userAccount.ts | 13 ++ 3 files changed, 154 insertions(+), 6 deletions(-) diff --git a/src/components/app/t-sidebar.vue b/src/components/app/t-sidebar.vue index a1effc00..ca332909 100644 --- a/src/components/app/t-sidebar.vue +++ b/src/components/app/t-sidebar.vue @@ -347,6 +347,7 @@ onUnmounted(() => themeListener()); .side-icon.paimon { width: 32px; height: 32px; + border-radius: 50%; margin-right: 24px; transform: translateX(-4px); } diff --git a/src/components/config/tc-userBadge.vue b/src/components/config/tc-userBadge.vue index 8a4209b7..76fac6da 100644 --- a/src/components/config/tc-userBadge.vue +++ b/src/components/config/tc-userBadge.vue @@ -64,19 +64,33 @@ /> - + {{ account.brief.nickname }} {{ account.brief.uid }} + + 手动添加 + 手动输入Cookie + @@ -416,10 +430,130 @@ async function showAccounts(): Promise { return; } } + +async function addByCookie(): Promise { + const ckInput = await showConfirm({ + mode: "input", + title: "请输入cookie", + text: "Cookie:", + }); + if (!ckInput) { + showSnackbar({ text: "已取消Cookie输入", color: "cancel" }); + return; + } + if (ckInput === "") { + showSnackbar({ text: "请输入Cookie!", color: "warn" }); + return; + } + const ckArr = ckInput.split(";"); + let ckRes = { stoken: "", stuid: "", mid: "" }; + for (const ck of ckArr) { + if (ck.startsWith("mid=")) ckRes.mid = ck.substring(4); + else if (ck.startsWith("stoken=")) ckRes.stoken = ck.substring(7); + else if (ck.startsWith("stuid=")) ckRes.stuid = ck.substring(6); + } + if (ckRes.mid === "" || ckRes.stoken === "" || ckRes.stuid === "") { + showSnackbar({ text: "解析Cookie失败", color: "error" }); + await TGLogger.Error(`解析Cookie失败:${ckInput}`); + return; + } + loading.value = true; + emits("loadOuter", { show: true, title: "尝试刷新Cookie" }); + const ck: TGApp.App.Account.Cookie = { + account_id: ckRes.stuid, + ltuid: ckRes.stuid, + stuid: ckRes.stuid, + mid: ckRes.mid, + cookie_token: "", + stoken: ckRes.stoken, + ltoken: "", + }; + emits("loadOuter", { show: true, title: "正在获取 LToken" }); + const ltokenRes = await TGRequest.User.bySToken.getLToken(ck.mid, ck.stoken); + if (typeof ltokenRes !== "string") { + showSnackbar({ text: `[${ltokenRes.retcode}]${ltokenRes.message}`, color: "error" }); + await TGLogger.Error(`获取LToken失败:${ltokenRes.retcode}-${ltokenRes.message}`); + loading.value = false; + emits("loadOuter", { show: false }); + return; + } + ck.ltoken = ltokenRes; + emits("loadOuter", { show: true, title: "正在获取 cookieToken " }); + const cookieTokenRes = await TGRequest.User.bySToken.getCookieToken(ck.mid, ck.stoken); + if (typeof cookieTokenRes !== "string") { + showSnackbar({ text: `[${cookieTokenRes.retcode}]${cookieTokenRes.message}`, color: "error" }); + await TGLogger.Error( + `获取CookieToken失败:${cookieTokenRes.retcode}-${cookieTokenRes.message}`, + ); + loading.value = false; + emits("loadOuter", { show: false }); + return; + } + ck.cookie_token = cookieTokenRes; + emits("loadOuter", { show: true, title: "正在获取用户信息" }); + const briefRes = await TGRequest.User.byCookie.getUserInfo(ck.cookie_token, ck.account_id); + if ("retcode" in briefRes) { + showSnackbar({ text: `[${briefRes.retcode}]${briefRes.message}` }); + await TGLogger.Error(`获取用户数据失败:${briefRes.retcode}-${briefRes.message}`); + loading.value = false; + emits("loadOuter", { show: false }); + return; + } + const briefInfo: TGApp.App.Account.BriefInfo = { + nickname: briefRes.nickname, + uid: briefRes.uid, + avatar: briefRes.avatar_url, + desc: briefRes.introduce, + }; + emits("loadOuter", { show: true, title: "正在保存用户数据" }); + await TSUserAccount.account.saveAccount({ + uid: briefInfo.uid, + cookie: ck, + brief: briefInfo, + updated: "", + }); + emits("loadOuter", { show: true, title: "正在获取游戏账号" }); + const gameRes = await TGRequest.User.bySToken.getAccounts(ck.stoken, ck.stuid); + if (!Array.isArray(gameRes)) { + loading.value = false; + emits("loadOuter", { show: false }); + showSnackbar({ text: `[${gameRes.retcode}]${gameRes.message}` }); + return; + } + await TSUserAccount.game.saveAccounts(briefInfo.uid, gameRes); + const curAccount = await TSUserAccount.game.getCurAccount(briefInfo.uid); + if (!curAccount) { + showSnackbar({ text: "未检测到游戏账号,请重新刷新", color: "warn" }); + loading.value = false; + emits("loadOuter", { show: false }); + return; + } + loading.value = false; + emits("loadOuter", { show: false }); + showSnackbar({ text: "成功加载用户数据!" }); +} + +async function clearUser(user: TGApp.App.Account.User): Promise { + if (user.uid === userStore.uid.value) { + showSnackbar({ text: "当前登录用户不许删除!", color: "warn" }); + return; + } + const confirm = await showConfirm({ title: "确认删除", text: "将删除账号及其游戏账号数据" }); + if (!confirm) { + showSnackbar({ text: "取消删除用户数据", color: "cancel" }); + return; + } + await TSUserAccount.account.deleteAccount(user.uid); + showSnackbar({ text: "成功删除用户!", color: "success" }); +} diff --git a/src/plugins/Sqlite/modules/userAccount.ts b/src/plugins/Sqlite/modules/userAccount.ts index 5e3776ef..b04665e4 100644 --- a/src/plugins/Sqlite/modules/userAccount.ts +++ b/src/plugins/Sqlite/modules/userAccount.ts @@ -216,6 +216,18 @@ async function saveGameAccount( } } +/** + * @description 删除游戏账户数据 + * @since Beta v0.6.0 + * @param {string} uid - 米社UID + * @returns {Promise} + */ +async function deleteAccount(uid: string): Promise { + const db = await TGSqlite.getDB(); + await db.execute("DELETE FROM GameAccount WHERE uid = ?;", [uid]); + await db.execute("DELETE FROM UserAccount WHERE uid = ?;", [uid]); +} + const TSUserAccount = { account: { getAllUid: getAllAccountId, @@ -223,6 +235,7 @@ const TSUserAccount = { getAccount: getUserAccount, saveAccount, copy: copyCookie, + deleteAccount, }, game: { getAccount: getGameAccount,