diff --git a/src/components/userGacha/gro-data-line.vue b/src/components/userGacha/gro-data-line.vue index f117cf68..0ce44f8e 100644 --- a/src/components/userGacha/gro-data-line.vue +++ b/src/components/userGacha/gro-data-line.vue @@ -17,10 +17,10 @@ diff --git a/src/components/userGacha/ug-his-card.vue b/src/components/userGacha/ug-his-card.vue new file mode 100644 index 00000000..15f12fe5 --- /dev/null +++ b/src/components/userGacha/ug-his-card.vue @@ -0,0 +1,206 @@ + + + + + + {{ props.pool.name }} + {{ props.pool.order === 1 ? "上半" : "下半" }} + {{ getType(props.pool.type) }} + + {{ getTimeStr(props.pool) }} + Up 五星 + + + + Up 四星 + + + + + + + + diff --git a/src/plugins/Sqlite/modules/userGacha.ts b/src/plugins/Sqlite/modules/userGacha.ts index a93bbdda..3b364418 100644 --- a/src/plugins/Sqlite/modules/userGacha.ts +++ b/src/plugins/Sqlite/modules/userGacha.ts @@ -1,7 +1,7 @@ /** * @file plugins/Sqlite/modules/userGacha.ts * @description 用户祈愿模块 - * @since Beta v0.6.0 + * @since Beta v0.6.8 */ import showSnackbar from "@comp/func/snackbar.js"; @@ -9,29 +9,10 @@ import TGSqlite from "@Sqlite/index.js"; import { path } from "@tauri-apps/api"; import { exists, mkdir, readDir } from "@tauri-apps/plugin-fs"; -import { AppCharacterData, AppWeaponData } from "@/data/index.js"; import TGLogger from "@/utils/TGLogger.js"; +import { getWikiBrief } from "@/utils/toolFunc.js"; import { exportUigfData, readUigfData, verifyUigfData } from "@/utils/UIGF.js"; -type gachaItemTypeRes = - | ["角色", TGApp.App.Character.WikiBriefInfo] - | ["武器", TGApp.App.Weapon.WikiBriefInfo] - | ["未知", "未知"]; - -/** - * @description 根据 item_id 获取角色/武器类型 - * @since Beta v0.4.7 - * @param {string} item_id - item_id - * @return {gachaItemTypeRes} - */ -function getGachaItemType(item_id: string): gachaItemTypeRes { - const findAvatar = AppCharacterData.find((i) => i.id.toString() === item_id); - if (findAvatar !== undefined) return ["角色", findAvatar]; - const findWeapon = AppWeaponData.find((i) => i.id.toString() === item_id); - if (findWeapon !== undefined) return ["武器", findWeapon]; - return ["未知", "未知"]; -} - /** * @description 获取导入 Sql * @since Beta v.6.0 @@ -44,60 +25,42 @@ function getInsertSql(uid: string, gacha: TGApp.Plugins.UIGF.GachaItem): string INSERT INTO GachaRecords (uid, gachaType, itemId, count, time, name, type, rank, id, uigfType, updated) VALUES ('${uid}', '${gacha.gacha_type}', '${gacha.item_id ?? null}', '${gacha.count ?? null}', '${gacha.time}', '${gacha.name}', '${gacha.item_type ?? null}', '${gacha.rank_type ?? null}', '${gacha.id}', - '${gacha.uigf_gacha_type}', datetime('now', 'localtime')) ON CONFLICT (id) - DO - UPDATE - SET uid = '${uid}', - gachaType = '${gacha.gacha_type}', - uigfType = '${gacha.uigf_gacha_type}', - time = '${gacha.time}', - itemId = '${gacha.item_id ?? null}', - count = '${gacha.count ?? null}', - name = '${gacha.name}', - type = '${gacha.item_type ?? null}', - rank = '${gacha.rank_type ?? null}', - updated = datetime('now', 'localtime'); + '${gacha.uigf_gacha_type}', datetime('now', 'localtime')) + ON CONFLICT (id) + DO UPDATE + SET uid = '${uid}', + gachaType = '${gacha.gacha_type}', + uigfType = '${gacha.uigf_gacha_type}', + time = '${gacha.time}', + itemId = '${gacha.item_id ?? null}', + count = '${gacha.count ?? null}', + name = '${gacha.name}', + type = '${gacha.item_type ?? null}', + rank = '${gacha.rank_type ?? null}', + updated = datetime('now', 'localtime'); `; } /** * @description 转换祈愿数据,防止多语言 - * @since Beta v0.5.1 + * @since Beta v0.6.8 * @param {TGApp.Plugins.UIGF.GachaItem} gacha - UIGF数据 * @return {TGApp.Plugins.UIGF.GachaItem} 转换后的数据 */ function transGacha(gacha: TGApp.Plugins.UIGF.GachaItem): TGApp.Plugins.UIGF.GachaItem { - const type = getGachaItemType(gacha.item_id); - let res = gacha; - res.item_type = type[0]; - if (type[0] === "角色") { - const data: TGApp.App.Character.WikiBriefInfo = type[1]; - res = { - gacha_type: gacha.gacha_type, - item_id: gacha.item_id, - count: gacha.count ?? "1", - time: gacha.time, - name: data.name, - item_type: "角色", - rank_type: data.star.toString(), - id: gacha.id, - uigf_gacha_type: gacha.uigf_gacha_type, - }; - } else if (type[0] === "武器") { - const data: TGApp.App.Weapon.WikiBriefInfo = type[1]; - res = { - gacha_type: gacha.gacha_type, - item_id: gacha.item_id, - count: gacha.count ?? "1", - time: gacha.time, - name: data.name, - item_type: "武器", - rank_type: data.star.toString(), - id: gacha.id, - uigf_gacha_type: gacha.uigf_gacha_type, - }; - } - return res; + const find = getWikiBrief(gacha.item_id); + if (!find) return gacha; + return { + gacha_type: gacha.gacha_type, + item_id: gacha.item_id, + count: gacha.count ?? "1", + time: gacha.time, + name: find.name, + item_type: "element" in find ? "角色" : "武器", + rank_type: find.star.toString(), + id: gacha.id, + uigf_gacha_type: gacha.uigf_gacha_type, + }; } /** @@ -273,7 +236,6 @@ const TSUserGacha = { getUidList, getGachaCheck, getGachaRecords, - getGachaItemType, deleteGachaRecords, cleanGachaRecords, mergeUIGF, diff --git a/src/utils/toolFunc.ts b/src/utils/toolFunc.ts index b4c92c9d..1cee35bc 100644 --- a/src/utils/toolFunc.ts +++ b/src/utils/toolFunc.ts @@ -1,7 +1,7 @@ /** * @file utils/toolFunc.ts * @description 一些工具函数 - * @since Beta v0.6.7 + * @since Beta v0.6.8 */ import { path } from "@tauri-apps/api"; @@ -11,6 +11,7 @@ import type { KEYWORD } from "color-convert/conversions.js"; import { v4 } from "uuid"; import { score } from "wcag-color"; +import { AppCharacterData, AppWeaponData } from "@/data/index.js"; import TGConstant from "@/web/constant/TGConstant.js"; /** @@ -274,6 +275,7 @@ export function decodeRegExp(data: string): string { /** * @description 根据 gid 获取游戏名称 + * @since Beta v0.6.7 * @param {number} gid * @returns {string} */ @@ -284,6 +286,7 @@ export function getGameName(gid: number): string { /** * @description 获取游戏id + * @since Beta v0.6.7 * @param {string} mini * @returns {string} */ @@ -291,3 +294,19 @@ export function getGameId(mini: string): string { const game = TGConstant.BBS.CHANNELS.find((item) => item.mini === mini); return game ? game.gid : "0"; } + +/** + * @description 根据id获取对应角色/武器数据 + * @since Beta v0.6.8 + * @param {number|string} id + * @returns {TGApp.App.Character.WikiBriefInfo|TGApp.App.Weapon.WikiBriefInfo} + */ +export function getWikiBrief( + id: number | string, +): TGApp.App.Character.WikiBriefInfo | TGApp.App.Weapon.WikiBriefInfo | false { + const len = id.toString().length; + if (len === 5) { + return AppWeaponData.find((item) => item.id.toString() === id.toString()) ?? false; + } + return AppCharacterData.find((item) => item.id.toString() === id.toString()) ?? false; +}