🌱 获取卡池抽卡记录

#188
This commit is contained in:
BTMuli
2025-12-27 21:02:35 +08:00
parent a929572ef5
commit 37a47205b1
9 changed files with 86 additions and 33 deletions

View File

@@ -79,7 +79,7 @@ const chartHeight = computed<string>(() => {
* @returns {EChartsOption}
*/
async function getCalendarOptions(): Promise<EChartsOption> {
const records = await TSUserGacha.getGachaRecordsGroupByDate(props.uid, props.gachaType);
const records = await TSUserGacha.record.time(props.uid, props.gachaType);
// 获取最大长度
const maxLen = Math.max(...Object.values(records).map((v) => v.length));
// 获取年份

View File

@@ -72,7 +72,7 @@ const chartEl = useTemplateRef<InstanceType<typeof VChart>>("chartRef");
* @returns {EChartsOption}
*/
async function getOverviewOptions(): Promise<EChartsOption> {
const records = await TSUserGacha.getGachaRecords(props.uid);
const records = await TSUserGacha.record.all(props.uid);
const data: EChartsOption = {
title: [
{ text: ">> 祈愿系统大数据分析 <<", left: "center", top: "5%" },

View File

@@ -72,7 +72,7 @@ const chartEl = useTemplateRef<InstanceType<typeof VChart>>("chartRef");
* @returns {EChartsOption}
*/
async function getStackBarOptions(): Promise<EChartsOption> {
const records = await TSUserGacha.getGachaRecordsGroupByDate(props.uid, props.gachaType);
const records = await TSUserGacha.record.time(props.uid, props.gachaType);
const dataCount = Object.keys(records).length;
const xAxis = {
type: <const>"category",

View File

@@ -1,6 +1,7 @@
<!-- 抽卡历史 -->
<template>
<div class="gro-container">
<v-tabs class="gro-tabs" v-model="historyTab" align-tabs="start" direction="vertical">
<v-tabs v-model="historyTab" align-tabs="start" class="gro-tabs" direction="vertical">
<v-tab v-for="(item, index) in tabList" :key="index" :value="item.tab">
{{ item.tab }}
</v-tab>
@@ -12,7 +13,7 @@
:value="item.tab"
class="gro-pools"
>
<UgHisCard v-for="pool in item.value" :key="pool.order" :pool="pool" />
<UgHisCard v-for="pool in item.value" :key="pool.order" :pool="pool" :uid="props.uid" />
</v-window-item>
</v-window>
</div>
@@ -25,6 +26,9 @@ import UgHisCard from "./ug-his-card.vue";
import { AppGachaData } from "@/data/index.js";
type GroHistoryMap = { tab: string; value: Array<TGApp.App.Gacha.PoolItem> };
type GroHistoryProps = { uid?: string };
const props = defineProps<GroHistoryProps>();
const historyTab = ref<string>("");
const tabList = shallowRef<Array<GroHistoryMap>>([]);
@@ -62,6 +66,7 @@ onMounted(() => {
.gro-container :deep(.v-tabs.v-slide-group--vertical) {
max-height: 100%;
}
/* stylelint-enable selector-class-pattern */
.gro-window {
@@ -81,6 +86,7 @@ onMounted(() => {
.gro-window :deep(.v-window__container) {
width: 100%;
}
/* stylelint-enable selector-class-pattern */
.gro-pools {

View File

@@ -1,3 +1,4 @@
<!-- 单个卡池抽卡记录 -->
<template>
<div class="user-gacha-history-card-comp">
<img
@@ -38,21 +39,40 @@
import TItemBox, { type TItemBoxData } from "@comp/app/t-itemBox.vue";
import showSnackbar from "@comp/func/snackbar.js";
import gameEnum from "@enum/game.js";
import TSUserGacha from "@Sqlm/userGacha.js";
import { createPost } from "@utils/TGWindow.js";
import { getWikiBrief, timestampToDate } from "@utils/toolFunc.js";
import { shallowRef, watch } from "vue";
import { useRouter } from "vue-router";
type UgHisCardProps = { pool: TGApp.App.Gacha.PoolItem };
type UgHisCardProps = {
/** 卡池信息 */
pool: TGApp.App.Gacha.PoolItem;
/** UID */
uid?: string;
};
const router = useRouter();
const props = defineProps<UgHisCardProps>();
const gachaTypeList: ReadonlyArray<TGApp.App.Gacha.PoolGachaType> = [
TGApp.Game.Gacha.GachaType.AvatarUp,
TGApp.Game.Gacha.GachaType.AvatarUp2,
TGApp.Game.Gacha.GachaType.WeaponUp,
TGApp.Game.Gacha.GachaType.MixUp,
gameEnum.gachaType.AvatarUp,
gameEnum.gachaType.AvatarUp2,
gameEnum.gachaType.WeaponUp,
gameEnum.gachaType.MixUp,
];
const gachaRecords = shallowRef<Array<TGApp.Sqlite.Gacha.Gacha>>([]);
watch(
() => props.uid,
async () => loadRecords(),
{ immediate: true },
);
async function loadRecords(): Promise<void> {
if (!props.uid) gachaRecords.value = [];
else gachaRecords.value = await TSUserGacha.record.pool(props.pool, props.uid);
}
function isPoolGachaType(x: string): x is TGApp.App.Gacha.PoolGachaType {
return (<ReadonlyArray<string>>gachaTypeList).includes(x);

View File

@@ -156,7 +156,7 @@ async function handleExportData(): Promise<void> {
const uidList = await TSUserGacha.getUidList();
const tmpData: Array<UgoUidItem> = [];
for (const uid of uidList) {
const dataRaw = await TSUserGacha.getGachaRecords(uid);
const dataRaw = await TSUserGacha.record.all(uid);
tmpData.push(parseDataRaw(dataRaw));
}
data.value = tmpData;

View File

@@ -112,7 +112,7 @@
<gro-table v-model="gachaListCur" />
</v-window-item>
<v-window-item class="gacha-window-item" value="history">
<gro-history />
<gro-history :uid="uidCur" />
</v-window-item>
<v-window-item class="gacha-window-item" value="iframe">
<gro-iframe mode="normal" />
@@ -176,7 +176,7 @@ onMounted(async () => {
await reloadUid();
if (uidCur.value) {
await showLoading.update(`UID${uidCur.value}`);
gachaListCur.value = await TSUserGacha.getGachaRecords(uidCur.value);
gachaListCur.value = await TSUserGacha.record.all(uidCur.value);
await TGLogger.Info(
`[UserGacha][onMounted] 获取到 ${uidCur.value}${gachaListCur.value.length} 条祈愿数据`,
);
@@ -190,7 +190,7 @@ watch(
() => uidCur.value,
async (newUid) => {
if (!newUid) return;
gachaListCur.value = await TSUserGacha.getGachaRecords(newUid);
gachaListCur.value = await TSUserGacha.record.all(newUid);
showSnackbar.success(`成功获取 ${gachaListCur.value.length} 条祈愿数据`);
await TGLogger.Info(
`[UserGacha][${newUid}][watch] 成功获取 ${gachaListCur.value.length} 条祈愿数据`,

View File

@@ -1,6 +1,6 @@
/**
* 用户祈愿模块
* @since Beta v0.9.0
* @since Beta v0.9.1
*/
import showLoading from "@comp/func/loading.js";
@@ -25,19 +25,19 @@ 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');
`;
}
@@ -129,7 +129,7 @@ async function getGachaRecords(uid: string): Promise<Array<TGApp.Sqlite.Gacha.Ga
* @param type - 类型
* @returns 日期分组的祈愿记录
*/
async function getGachaRecordsGroupByDate(
async function getGachaRecordsByDate(
uid: string,
type?: string,
): Promise<Record<string, Array<TGApp.Sqlite.Gacha.Gacha>>> {
@@ -156,6 +156,30 @@ async function getGachaRecordsGroupByDate(
return map;
}
/**
* 获取指定卡池的祈愿记录
* @since Beta v0.9.1
* @param pool - 卡池信息
* @param uid - 用户UID
*/
async function getGachaRecordsByPool(
pool: TGApp.App.Gacha.PoolItem,
uid: string,
): Promise<Array<TGApp.Sqlite.Gacha.Gacha>> {
console.log(pool, uid);
const db = await TGSqlite.getDB();
type resType = Array<TGApp.Sqlite.Gacha.Gacha>;
return await db.select<resType>(
"SELECT * FROM GachaRecords WHERE uid = ? AND gachaType = ? AND time >= ? AND time <= ?;",
[
uid.toString(),
pool.type.toString(),
pool.from.slice(0, 19).replace("T", " "),
pool.to.slice(0, 19).replace("T", " "),
],
);
}
/**
* 删除指定UID的祈愿记录
* @since Beta v0.4.7
@@ -369,8 +393,6 @@ async function updateItemIdById(raw: TGApp.Sqlite.Gacha.Gacha, itemId: string):
const TSUserGacha = {
getUidList,
getGachaCheck,
getGachaRecords,
getGachaRecordsGroupByDate,
deleteGachaRecords,
cleanGachaRecords,
mergeUIGF,
@@ -380,6 +402,11 @@ const TSUserGacha = {
update: {
itemId: updateItemIdById,
},
record: {
all: getGachaRecords,
time: getGachaRecordsByDate,
pool: getGachaRecordsByPool,
},
};
export default TSUserGacha;

View File

@@ -211,7 +211,7 @@ export async function exportUigfData(
/**
* 导出UIGF4数据
* @since Beta v0.9.0
* @since Beta v0.9.1
* @param uids - UID列表
* @param savePath - 保存路径
* @returns
@@ -221,7 +221,7 @@ export async function exportUigf4Data(uids: Array<string> = [], savePath?: strin
const filePath = savePath ?? `${await path.appLocalDataDir()}userData\\UIGF4.json`;
const data: Array<TGApp.Plugins.UIGF.GachaHk4e> = [];
for (const uid of uids) {
const gachaList = await TSUserGacha.getGachaRecords(uid);
const gachaList = await TSUserGacha.record.all(uid);
await showLoading.update(`正在导出${uid}${gachaList.length}条祈愿记录`);
const timezone = getUigfTimeZone(uid);
data.push({ uid: uid, timezone: timezone, list: convertDataToUigf(gachaList, timezone) });