🚸 支持删除无用账户,重构游戏账号表格

This commit is contained in:
目棃
2025-03-11 10:54:34 +08:00
parent c0d9830670
commit 9d212a5b87
4 changed files with 77 additions and 13 deletions

View File

@@ -252,7 +252,7 @@ defineExpose({ displayInputBox, displayCheckBox });
font-size: 20px;
text-align: center;
text-overflow: ellipsis;
white-space: normal;
white-space: pre-wrap;
word-break: break-all;
}

View File

@@ -20,7 +20,17 @@
</v-icon>
<v-icon v-else color="var(--tgc-od-white)">mdi-checkbox-blank-outline</v-icon>
<div class="tuss-account">
<img :src="item.info.icon" alt="icon" />
<div class="tuss-icon">
<img :src="item.info.icon" alt="icon" />
<div
class="delete"
v-if="item.account.gameBiz !== 'hk4e_cn'"
@click.stop="deleteAccount(item)"
title="删除账户"
>
<v-icon size="12" color="var(--tgc-od-red)">mdi-delete</v-icon>
</div>
</div>
<span>{{ item.account.gameUid }} {{ item.account.regionName }}</span>
</div>
<div class="tuss-stat">
@@ -43,6 +53,7 @@
</template>
<script setup lang="ts">
import TMiImg from "@comp/app/t-mi-img.vue";
import showDialog from "@comp/func/dialog.js";
import showGeetest from "@comp/func/geetest.js";
import showSnackbar from "@comp/func/snackbar.js";
import TSUserAccount from "@Sqlite/modules/userAccount.js";
@@ -114,6 +125,24 @@ async function loadData(): Promise<void> {
}
}
async function deleteAccount(item: SignAccount): Promise<void> {
if (item.account.gameBiz === "hk4e_cn") {
showSnackbar.warn("原神账户不可删除");
return;
}
const idx = signAccounts.value.findIndex((i) => i === item);
if (idx === -1) return;
const infoStr = `${item.info.title}-${item.account.regionName}-${item.account.gameUid}`;
const check = await showDialog.check(`确定删除?`, `${infoStr}\n删除后仅能通过刷新游戏账号恢复`);
if (!check) {
showSnackbar.cancel(`已取消删除${infoStr}`);
return;
}
await TSUserAccount.game.deleteAccount(item.account);
signAccounts.value.splice(idx, 1);
showSnackbar.success(`已删除${infoStr}`);
}
async function tryRefresh(): Promise<void> {
if (loadScript.value) {
showSnackbar.warn("任务正在执行中,请稍后再试");
@@ -231,9 +260,6 @@ async function trySign(ac: SignAccount[], ck: TGApp.App.Account.Cookie): Promise
);
continue;
}
await TGLogger.Script(
`[签到任务]${item.info.title}-${item.account.regionName}-${item.account.gameUid}签到`,
);
let check = false;
let challenge: string | undefined = undefined;
while (!check) {
@@ -354,11 +380,33 @@ async function trySign(ac: SignAccount[], ck: TGApp.App.Account.Cookie): Promise
align-items: center;
justify-content: center;
column-gap: 4px;
}
.tuss-icon {
position: relative;
width: 48px;
height: 48px;
border-radius: 4px;
overflow: hidden;
img {
border-radius: 4px;
width: 48px;
height: 48px;
width: 100%;
height: 100%;
}
.delete {
position: absolute;
bottom: 0;
left: 0;
width: 16px;
height: 16px;
display: flex;
align-items: center;
justify-content: center;
backdrop-filter: blur(5px);
border-top-right-radius: 8px;
cursor: pointer;
}
}

View File

@@ -13,7 +13,7 @@ import { timestampToDate } from "@/utils/toolFunc.js";
/**
* @description 获取插入游戏账号数据的sql
* @since Beta v0.6.0
* @since Beta v0.7.2
* @param {string} uid - 米社UID
* @param {TGApp.BBS.Game.Account} data - 游戏账号数据
* @return {string}
@@ -26,9 +26,8 @@ function getInsertGameAccountSql(uid: string, data: TGApp.BBS.Game.Account): str
INSERT INTO GameAccount(uid, gameBiz, gameUid, isChosen, isOfficial, level, nickname, region, regionName, updated)
VALUES ('${uid}', '${data.game_biz}', '${data.game_uid}', ${isChosen}, ${isOfficial}, ${data.level},
'${data.nickname}', '${data.region}', '${data.region_name}', '${timeNow}')
ON CONFLICT(uid, gameUid) DO UPDATE
SET gameBiz = '${data.game_biz}',
isChosen = ${isChosen},
ON CONFLICT(uid, gameUid, gameBiz) DO UPDATE
SET isChosen = ${isChosen},
isOfficial = ${isOfficial},
level = ${data.level},
nickname = '${data.nickname}',
@@ -277,6 +276,21 @@ async function saveGameAccount(
await Promise.all(accounts.map((account) => db.execute(getInsertGameAccountSql(uid, account))));
}
/**
* @description 删除指定游戏账户
* @since Beta v0.7.2
* @param {TGApp.Sqlite.Account.Game} account - 游戏账户
* @return {Promise<void>}
*/
async function deleteGameAccount(account: TGApp.Sqlite.Account.Game): Promise<void> {
const db = await TGSqlite.getDB();
await db.execute("DELETE FROM GameAccount WHERE uid = ? AND gameUid = ? AND gameBiz = ?;", [
account.uid,
account.gameUid,
account.gameBiz,
]);
}
/**
* @description 删除游戏账户数据
* @since Beta v0.6.0
@@ -305,6 +319,7 @@ const TSUserAccount = {
switchAccount: switchGameAccount,
getCurAccount: getCurGameAccount,
saveAccounts: saveGameAccount,
deleteAccount: deleteGameAccount,
},
};

View File

@@ -1,6 +1,6 @@
-- @file plugins/Sqlite/sql/createTable.sql
-- @brief sqlite数据库创建表语句
-- @since Beta v0.6.3
-- @since Beta v0.7.2
-- @brief 创建成就数据表
create table if not exists Achievements
@@ -31,6 +31,7 @@ create table if not exists UserAccount
updated text
);
drop table if exists GameAccount;
-- @brief 创建游戏账号数据表
create table if not exists GameAccount
(
@@ -44,7 +45,7 @@ create table if not exists GameAccount
region text,
regionName text,
updated text,
primary key (uid, gameUid)
primary key (uid, gameBiz, gameUid)
);
-- @brief 创建深渊数据表