mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-18 10:18:14 +08:00
🌱 深渊数据支持多用户,暂时不做用户切换
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
<v-window v-model="userTab" class="ua-window">
|
||||
<v-window-item v-for="item in localAbyss" :key="item.id" :value="item.id" class="ua-window-item">
|
||||
<div class="uaw-title">
|
||||
<span>挑战回顾</span>
|
||||
<span>挑战回顾【{{ user.gameUid }}】</span>
|
||||
<span>更新于 {{ item.updated }}</span>
|
||||
</div>
|
||||
<div class="uaw-sub-title">
|
||||
@@ -72,7 +72,8 @@ const loadingTitle = ref("");
|
||||
|
||||
// data
|
||||
const userTab = ref(0);
|
||||
const abyssCookie = ref(computed(() => userStore.getCookieGroup4()));
|
||||
const abyssCookie = ref(computed(
|
||||
() => userStore.getCookieGroup4() as Record<string, string>));
|
||||
const user = computed(() => userStore.getCurAccount());
|
||||
|
||||
const localAbyss = ref([] as TGApp.Sqlite.Abyss.SingleTable[]);
|
||||
@@ -86,7 +87,7 @@ onMounted(async () => {
|
||||
});
|
||||
|
||||
async function initAbyssData () {
|
||||
localAbyss.value = await TGSqlite.getAbyss();
|
||||
localAbyss.value = await TGSqlite.getAbyss(user.value.gameUid);
|
||||
localAbyss.value.forEach((item) => {
|
||||
localAbyssID.value.push(item.id);
|
||||
});
|
||||
@@ -102,14 +103,14 @@ async function getAbyssData (): Promise<void> {
|
||||
const resP = await TGRequest.User.byCookie.getAbyss(abyssCookie.value, "2", user.value);
|
||||
if (!resP.hasOwnProperty("retcode")) {
|
||||
loadingTitle.value = "正在保存上期深渊数据";
|
||||
await TGSqlite.saveAbyss(resP as TGApp.Game.Abyss.FullData);
|
||||
await TGSqlite.saveAbyss(user.value.gameUid, resP as TGApp.Game.Abyss.FullData);
|
||||
}
|
||||
}
|
||||
loadingTitle.value = "正在获取本期深渊数据";
|
||||
const res = await TGRequest.User.byCookie.getAbyss(abyssCookie.value, "1", user.value);
|
||||
if (!res.hasOwnProperty("retcode")) {
|
||||
loadingTitle.value = "正在保存本期深渊数据";
|
||||
await TGSqlite.saveAbyss(res as TGApp.Game.Abyss.FullData);
|
||||
await TGSqlite.saveAbyss(user.value.gameUid, res as TGApp.Game.Abyss.FullData);
|
||||
}
|
||||
loadingTitle.value = "正在加载深渊数据";
|
||||
await initAbyssData();
|
||||
@@ -122,7 +123,7 @@ function toAbyss (id: number): void {
|
||||
</script>
|
||||
<style lang="css" scoped>
|
||||
.ua-box {
|
||||
background: rgb(0 0 0 / 10%);
|
||||
box-shadow: 0 0 10px 0 rgb(0 0 0 / 10%);
|
||||
display: flex;
|
||||
justify-content: left;
|
||||
align-items: center;
|
||||
|
||||
@@ -192,12 +192,12 @@ class Sqlite {
|
||||
* @param {number} seriesId 系列 ID
|
||||
* @returns {Promise<TGApp.Sqlite.NameCard.Item>}
|
||||
*/
|
||||
public async getNameCard (seriesId: number): Promise<TGApp.Sqlite.NameCard.Item> {
|
||||
public async getNameCard (seriesId: number): Promise<TGApp.Sqlite.NameCard.SingleTable> {
|
||||
const db = await Database.load(this.dbPath);
|
||||
const sql = `SELECT *
|
||||
FROM NameCard
|
||||
WHERE name = (SELECT nameCard FROM AchievementSeries WHERE id = ${seriesId});`;
|
||||
const res: TGApp.Sqlite.NameCard.Item[] = await db.select(sql);
|
||||
const res: TGApp.Sqlite.NameCard.SingleTable[] = await db.select(sql);
|
||||
await db.close();
|
||||
return res[0];
|
||||
}
|
||||
@@ -319,12 +319,13 @@ class Sqlite {
|
||||
/**
|
||||
* @description 保存深渊数据
|
||||
* @since Alpha v0.2.0
|
||||
* @param {string} uid 游戏 UID
|
||||
* @param {TGApp.Game.Abyss.FullData} data 深渊数据
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public async saveAbyss (data: TGApp.Game.Abyss.FullData): Promise<void> {
|
||||
public async saveAbyss (uid: string, data: TGApp.Game.Abyss.FullData): Promise<void> {
|
||||
const db = await Database.load(this.dbPath);
|
||||
const sql = insertAbyssData(data);
|
||||
const sql = insertAbyssData(uid, data);
|
||||
await db.execute(sql);
|
||||
await db.close();
|
||||
}
|
||||
@@ -332,11 +333,12 @@ class Sqlite {
|
||||
/**
|
||||
* @description 获取深渊数据
|
||||
* @since Alpha v0.2.0
|
||||
* @param {string} uid 游戏 UID
|
||||
* @returns {Promise<TGApp.Game.Abyss.FullData>}
|
||||
*/
|
||||
public async getAbyss (): Promise<TGApp.Sqlite.Abyss.SingleTable[]> {
|
||||
public async getAbyss (uid: string): Promise<TGApp.Sqlite.Abyss.SingleTable[]> {
|
||||
const db = await Database.load(this.dbPath);
|
||||
const sql = "SELECT * FROM SpiralAbyss order by id desc";
|
||||
const sql = `SELECT * FROM SpiralAbyss WHERE uid = '${uid}' order by id desc`;
|
||||
const res: TGApp.Sqlite.Abyss.SingleTable[] = await db.select(sql);
|
||||
await db.close();
|
||||
return res;
|
||||
|
||||
@@ -83,7 +83,8 @@ create table if not exists NameCard
|
||||
-- @brief 创建深渊数据表
|
||||
create table if not exists SpiralAbyss
|
||||
(
|
||||
id integer primary key,
|
||||
uid text,
|
||||
id integer,
|
||||
startTime text,
|
||||
endTime text,
|
||||
totalBattleTimes integer,
|
||||
@@ -98,7 +99,8 @@ create table if not exists SpiralAbyss
|
||||
normalSkillRank text,
|
||||
energySkillRank text,
|
||||
floors text,
|
||||
updated text
|
||||
updated text,
|
||||
primary key (uid, id)
|
||||
);
|
||||
|
||||
-- @brief 创建战绩数据表
|
||||
|
||||
@@ -133,10 +133,11 @@ export function insertCharacterData (data: TGApp.App.Character.WikiBriefInfo): s
|
||||
/**
|
||||
* @description 插入深渊数据
|
||||
* @since Alpha v0.2.0
|
||||
* @param {string} uid 用户 uid
|
||||
* @param {TGApp.User.Abyss} data 深渊数据
|
||||
* @returns {string} sql
|
||||
*/
|
||||
export function insertAbyssData (data: TGApp.Game.Abyss.FullData): string {
|
||||
export function insertAbyssData (uid: string, data: TGApp.Game.Abyss.FullData): string {
|
||||
const startTime = timeToSecond(data.start_time);
|
||||
const endTime = timeToSecond(data.end_time);
|
||||
const isUnlock = data.is_unlock ? 1 : 0;
|
||||
@@ -148,14 +149,14 @@ export function insertAbyssData (data: TGApp.Game.Abyss.FullData): string {
|
||||
const energySkillRank = transCharacterData(data.energy_skill_rank);
|
||||
const floors = transFloorData(data.floors);
|
||||
return `
|
||||
INSERT INTO SpiralAbyss (id, startTime, endTime, totalBattleTimes, totalWinTimes, maxFloor, totalStar, isUnlock,
|
||||
revealRank, defeatRank, damageRank, takeDamageRank, normalSkillRank, energySkillRank,
|
||||
floors, updated)
|
||||
VALUES (${data.schedule_id}, '${startTime}', '${endTime}', ${data.total_battle_times}, ${data.total_win_times},
|
||||
'${data.max_floor}', ${data.total_star},
|
||||
${isUnlock}, '${revealRank}', '${defeatRank}', '${damageRank}', '${takeDamageRank}', '${normalSkillRank}',
|
||||
'${energySkillRank}', '${floors}', datetime('now', 'localtime'))
|
||||
ON CONFLICT(id) DO UPDATE
|
||||
INSERT INTO SpiralAbyss (uid, id, startTime, endTime, totalBattleTimes, totalWinTimes,
|
||||
maxFloor, totalStar, isUnlock, revealRank, defeatRank, damageRank,
|
||||
takeDamageRank, normalSkillRank, energySkillRank, floors, updated)
|
||||
VALUES ('${uid}', ${data.schedule_id}, '${startTime}', '${endTime}', ${data.total_battle_times},
|
||||
${data.total_win_times}, '${data.max_floor}', ${data.total_star},
|
||||
${isUnlock}, '${revealRank}', '${defeatRank}', '${damageRank}', '${takeDamageRank}',
|
||||
'${normalSkillRank}', '${energySkillRank}', '${floors}', datetime('now', 'localtime'))
|
||||
ON CONFLICT(uid, id) DO UPDATE
|
||||
SET startTime = '${startTime}',
|
||||
endTime = '${endTime}',
|
||||
totalBattleTimes = ${data.total_battle_times},
|
||||
|
||||
Reference in New Issue
Block a user