mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-26 05:39:45 +08:00
✨ 千星奇域页面
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
/**
|
||||
* @file plugins/Sqlite/index.ts
|
||||
* @description Sqlite 数据库操作类
|
||||
* @since Beta v0.8.0
|
||||
* Sqlite 数据库操作类
|
||||
* @since Beta v0.8.4
|
||||
*/
|
||||
|
||||
import { app } from "@tauri-apps/api";
|
||||
@@ -17,10 +16,11 @@ class Sqlite {
|
||||
"Achievements",
|
||||
"AppData",
|
||||
"GachaRecords",
|
||||
"GachaBRecords",
|
||||
"GameAccount",
|
||||
"SpiralAbyss",
|
||||
"RoleCombat",
|
||||
"HardChallenge",
|
||||
"RoleCombat",
|
||||
"SpiralAbyss",
|
||||
"UFCollection",
|
||||
"UFMap",
|
||||
"UFPost",
|
||||
@@ -39,7 +39,7 @@ class Sqlite {
|
||||
private constructor() {}
|
||||
|
||||
/**
|
||||
* @description 获取数据库实例
|
||||
* 获取数据库实例
|
||||
* @since Beta v0.3.3
|
||||
* @returns {Promise<Database>}
|
||||
*/
|
||||
@@ -49,7 +49,7 @@ class Sqlite {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 检测是否需要创建数据库
|
||||
* 检测是否需要创建数据库
|
||||
* @since Beta v0.6.1
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
@@ -70,7 +70,7 @@ class Sqlite {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 初始化数据库
|
||||
* 初始化数据库
|
||||
* @since Beta v0.4.5
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
@@ -81,7 +81,7 @@ class Sqlite {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取数据库信息
|
||||
* 获取数据库信息
|
||||
* @since Beta v0.3.3
|
||||
* @returns {Promise<TGApp.Sqlite.AppData.Item[]>}
|
||||
*/
|
||||
@@ -92,7 +92,7 @@ class Sqlite {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 对比数据判断是否需要更新
|
||||
* 对比数据判断是否需要更新
|
||||
* @since Beta v0.3.3
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
@@ -105,7 +105,7 @@ class Sqlite {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 保存 appData
|
||||
* 保存 appData
|
||||
* @since Beta v0.3.3
|
||||
* @param {string} key
|
||||
* @param {string} value
|
||||
@@ -118,7 +118,7 @@ class Sqlite {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 已有数据表跟触发器不变的情况下,更新数据库数据
|
||||
* 已有数据表跟触发器不变的情况下,更新数据库数据
|
||||
* @since Beta v0.3.3
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
@@ -131,7 +131,7 @@ class Sqlite {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 更新 SpiralAbyss 表
|
||||
* 更新 SpiralAbyss 表
|
||||
* @since Beta v0.6.1
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
@@ -147,7 +147,7 @@ class Sqlite {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 重置数据库
|
||||
* 重置数据库
|
||||
* @since Beta v0.4.0
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
|
||||
161
src/plugins/Sqlite/modules/userGachaB.ts
Normal file
161
src/plugins/Sqlite/modules/userGachaB.ts
Normal file
@@ -0,0 +1,161 @@
|
||||
/**
|
||||
* 千星奇域祈愿模块
|
||||
* @since Beta v0.8.4
|
||||
*/
|
||||
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
import TGSqlite from "@Sql/index.js";
|
||||
import { exists, mkdir } from "@tauri-apps/plugin-fs";
|
||||
import TGLogger from "@utils/TGLogger.js";
|
||||
|
||||
/**
|
||||
* 获取导入 Sql
|
||||
* @since Beta v0.8.4
|
||||
* @param {TGApp.Game.Gacha.GachaBItem} gacha - 抽卡记录数据
|
||||
* @returns {string}
|
||||
*/
|
||||
function getInsertSql(gacha: TGApp.Game.Gacha.GachaBItem): string {
|
||||
return `
|
||||
INSERT INTO GachaBRecords(id, uid, region, scheduleId, gachaType,
|
||||
opGachaType, time, itemId, name, type,
|
||||
rank, isUp, updated)
|
||||
VALUES ('${gacha.id}', '${gacha.uid}', '${gacha.region}', '${gacha.schedule_id}',
|
||||
'${gacha.op_gacha_type === "1000" ? "1000" : "2000"}', '${gacha.op_gacha_type}', '${gacha.time}',
|
||||
'${gacha.item_id}', '${gacha.item_name}', '${gacha.item_type}',
|
||||
'${gacha.rank_type}', '${gacha.is_up}', datetime('now', 'localtime'))
|
||||
ON CONFLICT (id)
|
||||
DO UPDATE
|
||||
SET uid = '${gacha.uid}',
|
||||
region = '${gacha.region}',
|
||||
scheduleId = '${gacha.schedule_id}',
|
||||
gachaType = '${gacha.op_gacha_type === "1000" ? "1000" : "2000"}',
|
||||
opGachaType = '${gacha.op_gacha_type}',
|
||||
time = '${gacha.time}',
|
||||
itemId = '${gacha.item_id}',
|
||||
name = '${gacha.item_name}',
|
||||
type = '${gacha.item_type}',
|
||||
rank = '${gacha.rank_type}',
|
||||
isUp = '${gacha.is_up}',
|
||||
updated = datetime('now', 'localtime');
|
||||
`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入列表数据
|
||||
* @since Beta v0.8.4
|
||||
* @param {Array<TGApp.Game.Gacha.GachaBItem>} list - 抽卡记录列表
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function insertGachaList(list: Array<TGApp.Game.Gacha.GachaBItem>): Promise<void> {
|
||||
const db = await TGSqlite.getDB();
|
||||
for (const gacha of list) {
|
||||
const sql = getInsertSql(gacha);
|
||||
await db.execute(sql);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据库UID列表
|
||||
* @since Beta v0.8.4
|
||||
* @returns {Promise<Array<string>>}
|
||||
*/
|
||||
async function getUidList(): Promise<Array<string>> {
|
||||
const db = await TGSqlite.getDB();
|
||||
type resType = Array<{ uid: string }>;
|
||||
const res = await db.select<resType>("SELECT DISTINCT uid FROM GachaBRecords;");
|
||||
return res.map((i) => i.uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取增量更新的记录 ID
|
||||
* @since Beta v0.8.4
|
||||
* @param {string} uid - UID
|
||||
* @param {string} type - 类型
|
||||
* @returns {Promise<string|undefined>}
|
||||
*/
|
||||
async function getGachaCheck(uid: string, type: string): Promise<string | undefined> {
|
||||
const db = await TGSqlite.getDB();
|
||||
type resType = Array<{ id: string }>;
|
||||
const res = await db.select<resType>(
|
||||
"SELECT id FROM GachaBRecords WHERE uid = ? AND opGachaType = ? ORDER BY id DESC LIMIT 1;",
|
||||
[uid, type],
|
||||
);
|
||||
if (res.length === 0) return undefined;
|
||||
return res[0].id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户祈愿记录
|
||||
* @since Beta v0.8.4
|
||||
* @param {string} uid - UID
|
||||
* @param {string} [type] - 类型
|
||||
* @return {Promise<Array<TGApp.Sqlite.GachaRecords.TableGachaB>>}
|
||||
*/
|
||||
async function getGachaRecords(
|
||||
uid: string,
|
||||
type?: string,
|
||||
): Promise<Array<TGApp.Sqlite.GachaRecords.TableGachaB>> {
|
||||
const db = await TGSqlite.getDB();
|
||||
if (type) {
|
||||
return await db.select("SELECT * FROM GachaBRecords WHERE uid = ? AND opGachaType = ?;", [
|
||||
uid,
|
||||
type,
|
||||
]);
|
||||
}
|
||||
return await db.select("SELECT * FROM GachaBRecords WHERE uid = ?;", [uid]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 备份祈愿数据
|
||||
* @since Beta v0.8.4
|
||||
* @param {string} dir - 备份目录
|
||||
* @remarks 等UIGF标准最终确定后与TSUserGacha合并
|
||||
*/
|
||||
async function backUpUigf(dir: string): Promise<void> {
|
||||
if (!(await exists(dir))) {
|
||||
await TGLogger.Warn("不存在指定的祈愿备份目录,即将创建");
|
||||
await mkdir(dir, { recursive: true });
|
||||
}
|
||||
showSnackbar.error(`千星奇域祈愿数据备份功能尚未实现,请耐心等待后续版本更新。`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复祈愿数据
|
||||
* @since Beta v0.8.4
|
||||
* @param {string} dir - 恢复目录
|
||||
* @remarks 等UIGF标准最终确定后与TSUserGacha合并
|
||||
*/
|
||||
async function restoreUigf(dir: string): Promise<boolean> {
|
||||
if (!(await exists(dir))) {
|
||||
await TGLogger.Warn("不存在指定的祈愿备份目录");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户祈愿数据
|
||||
* @since Beta v0.8.4
|
||||
* @param {string} uid - UID
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function deleteRecords(uid: string): Promise<void> {
|
||||
const db = await TGSqlite.getDB();
|
||||
await db.execute("DELETE FROM GachaBRecords WHERE uid = ?;", [uid]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 千星奇域祈愿模块
|
||||
* @since Beta v0.8.4
|
||||
*/
|
||||
const TSUserGachaB = {
|
||||
getUidList,
|
||||
getGachaCheck,
|
||||
getGachaRecords,
|
||||
insertGachaList,
|
||||
backUpUigf,
|
||||
restoreUigf,
|
||||
deleteRecords,
|
||||
};
|
||||
|
||||
export default TSUserGachaB;
|
||||
@@ -1,6 +1,5 @@
|
||||
-- @file plugins/Sqlite/sql/createTable.sql
|
||||
-- @brief sqlite数据库创建表语句
|
||||
-- @since Beta v0.8.0
|
||||
-- @since Beta v0.8.4
|
||||
|
||||
-- @brief 创建成就数据表
|
||||
create table if not exists Achievements
|
||||
@@ -148,6 +147,24 @@ create table if not exists GachaRecords
|
||||
updated text
|
||||
);
|
||||
|
||||
-- @brief 创建千星奇域祈愿数据表
|
||||
create table if not exists GachaBRecords
|
||||
(
|
||||
id text primary key not null,
|
||||
uid text,
|
||||
region text,
|
||||
scheduleId text,
|
||||
gachaType text,
|
||||
opGachaType text,
|
||||
time text,
|
||||
itemId text,
|
||||
name text,
|
||||
type text,
|
||||
rank text,
|
||||
isUp text,
|
||||
updated text
|
||||
);
|
||||
|
||||
-- @brief 创建用户帖子收藏
|
||||
create table if not exists UFPost
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user