♻️ 仅从数据库中获取名片名称,弃用 NameCard Table

This commit is contained in:
BTMuli
2023-12-29 01:12:41 +08:00
parent 5d9cce1079
commit b1496f1232
2 changed files with 44 additions and 41 deletions

View File

@@ -37,9 +37,7 @@
</div>
<!-- 右侧内容-->
<div class="right-wrap">
<div
v-if="selectedSeries !== 0 && selectedSeries !== 17 && selectedSeries !== -1 && !loading"
>
<div v-if="curCardName !== '' && selectedSeries !== -1 && !loading">
<v-list
v-if="curCard"
class="achi-series"
@@ -113,7 +111,7 @@ import showConfirm from "../../components/func/confirm";
import showSnackbar from "../../components/func/snackbar";
import ToLoading from "../../components/overlay/to-loading.vue";
import ToNamecard from "../../components/overlay/to-namecard.vue";
import { AppAchievementSeriesData } from "../../data";
import { AppAchievementSeriesData, AppNameCardsData } from "../../data";
import TGSqlite from "../../plugins/Sqlite";
import { useAchievementsStore } from "../../store/modules/achievements";
import { getNowStr } from "../../utils/toolFunc";
@@ -130,6 +128,7 @@ const hideFin = ref<boolean>(false);
const showNameCard = ref<boolean>(false);
// data
const title = ref(achievementsStore.title);
const curCardName = ref<string>("");
let curCard = ref<TGApp.App.NameCard.Item>();
// series
const allSeriesData = ref<TGApp.Sqlite.Achievement.SeriesTable[]>([]);
@@ -212,17 +211,9 @@ async function selectSeries(index: number): Promise<void> {
selectedSeries.value = index;
selectedAchievement.value = await getAchiData("series", index.toString());
loadingTitle.value = "正在查找对应的成就名片";
if (selectedSeries.value !== 0 && selectedSeries.value !== 17) {
const cardGet = await TGSqlite.getNameCard(index);
curCard.value = {
name: cardGet.name,
desc: cardGet.desc,
icon: `/source/nameCard/icon/${cardGet.name}.webp`,
bg: `/source/nameCard/bg/${cardGet.name}.webp`,
profile: `/source/nameCard/profile/${cardGet.name}.webp`,
type: cardGet.type,
source: cardGet.source,
};
curCardName.value = await getNameCardName(index);
if (curCardName.value !== "") {
curCard.value = AppNameCardsData.find((item) => item.name === curCardName.value);
}
// 右侧滚动到顶部
const rightWrap = document.querySelector(".right-wrap");
@@ -486,6 +477,16 @@ async function getAchiData(
return await db.select(sql);
}
// 获取成就名片
async function getNameCardName(series: number): Promise<string> {
const db = await TGSqlite.getDB();
const sql = `SELECT nameCard
FROM AchievementSeries
WHERE id = ${series};`;
const res: Array<{ nameCard: string }> = await db.select(sql);
return res[0].nameCard;
}
// 更新成就数据
async function setAchiDB(achievement: TGApp.Sqlite.Achievement.SingleTable): Promise<void> {
const db = await TGSqlite.getDB();

View File

@@ -1,7 +1,7 @@
/**
* @file plugins/Sqlite/index.ts
* @description Sqlite 数据库操作类
* @since Beta v0.3.8
* @since Beta v0.3.9
*/
import { app } from "@tauri-apps/api";
@@ -198,21 +198,6 @@ class Sqlite {
await this.initDB();
}
/**
* @description 获取成就系列对应的名片
* @since Beta v0.3.3
* @param {number} seriesId 系列 ID
* @returns {Promise<TGApp.Sqlite.NameCard.Item>}
*/
public async getNameCard(seriesId: number): Promise<TGApp.Sqlite.NameCard.SingleTable> {
const db = await this.getDB();
const sql = `SELECT *
FROM NameCard
WHERE name = (SELECT nameCard FROM AchievementSeries WHERE id = ${seriesId});`;
const res: TGApp.Sqlite.NameCard.SingleTable[] = await db.select(sql);
return res[0];
}
/**
* @description 获取最新成就版本
* @since Beta v0.3.3
@@ -287,7 +272,10 @@ class Sqlite {
const db = await this.getDB();
let sql;
if (uid) {
sql = `SELECT * FROM SpiralAbyss WHERE uid = '${uid}' order by id desc`;
sql = `SELECT *
FROM SpiralAbyss
WHERE uid = '${uid}'
order by id desc`;
} else {
sql = "SELECT * FROM SpiralAbyss order by uid, id desc";
}
@@ -329,7 +317,9 @@ class Sqlite {
*/
public async getUserRecord(uid: string): Promise<TGApp.Sqlite.Record.SingleTable | false> {
const db = await this.getDB();
const sql = `SELECT * FROM UserRecord WHERE uid = '${uid}'`;
const sql = `SELECT *
FROM UserRecord
WHERE uid = '${uid}'`;
const res: TGApp.Sqlite.Record.SingleTable[] = await db.select(sql);
if (res.length === 0) return false;
return res[0];
@@ -343,7 +333,9 @@ class Sqlite {
*/
public async getAppCharacter(id: number): Promise<TGApp.Sqlite.Character.AppData> {
const db = await this.getDB();
const sql = `SELECT * FROM AppCharacters WHERE id = ${id}`;
const sql = `SELECT *
FROM AppCharacters
WHERE id = ${id}`;
const res: TGApp.Sqlite.Character.AppData[] = await db.select(sql);
return res[0];
}
@@ -378,9 +370,11 @@ class Sqlite {
data: TGApp.Sqlite.Character.RoleTalent[],
): Promise<void> {
const db = await this.getDB();
const sql = `UPDATE UserCharacters
SET talent = '${JSON.stringify(data)}', updated = datetime('now', 'localtime')
WHERE uid = '${uid}' AND cid = ${cid}`;
const sql = `UPDATE UserCharacters
SET talent = '${JSON.stringify(data)}',
updated = datetime('now', 'localtime')
WHERE uid = '${uid}'
AND cid = ${cid}`;
await db.execute(sql);
}
@@ -392,7 +386,9 @@ class Sqlite {
*/
public async getUserCharacter(uid: string): Promise<TGApp.Sqlite.Character.UserRole[] | false> {
const db = await this.getDB();
const sql = `SELECT * FROM UserCharacters WHERE uid = '${uid}'`;
const sql = `SELECT *
FROM UserCharacters
WHERE uid = '${uid}'`;
const res: TGApp.Sqlite.Character.UserRole[] = await db.select(sql);
if (res.length === 0) return false;
return res;
@@ -418,7 +414,9 @@ class Sqlite {
*/
public async getGachaRecords(uid: string): Promise<TGApp.Sqlite.GachaRecords.SingleTable[]> {
const db = await this.getDB();
const sql = `SELECT * FROM GachaRecords WHERE uid = '${uid}'`;
const sql = `SELECT *
FROM GachaRecords
WHERE uid = '${uid}'`;
return await db.select(sql);
}
@@ -430,7 +428,9 @@ class Sqlite {
*/
public async deleteGachaRecords(uid: string): Promise<void> {
const db = await this.getDB();
const sql = `DELETE FROM GachaRecords WHERE uid = '${uid}'`;
const sql = `DELETE
FROM GachaRecords
WHERE uid = '${uid}'`;
await db.execute(sql);
}
@@ -458,7 +458,9 @@ class Sqlite {
const db = await this.getDB();
const dateNow = new Date();
const date = `${dateNow.getMonth() + 1},${dateNow.getDate()}`;
const sql = `SELECT name FROM AppCharacters WHERE birthday = '${date}';`;
const sql = `SELECT name
FROM AppCharacters
WHERE birthday = '${date}';`;
const res: Array<{ name: string }> = await db.select(sql);
if (res.length === 0) return false;
return res.map((item) => item.name).join("、");