diff --git a/frontend/src/components/account/AccountTable.vue b/frontend/src/components/account/AccountTable.vue index 7536faf..23b96c3 100644 --- a/frontend/src/components/account/AccountTable.vue +++ b/frontend/src/components/account/AccountTable.vue @@ -8,8 +8,10 @@ import { useActivity } from '@/composables/useActivity' import { useToast } from '@/composables/useToast' import { ExportLatestXiaodianReport, + QueryExchangeRecords, QueryXiaodianAccountExchangeRecords, - QueryXiaodianExchangeRecords + QueryXiaodianExchangeRecords, + VerifyExchange } from '@wails/go/app/App' const { @@ -56,6 +58,11 @@ watch(selectedProductId, () => { exchangeLookup.value = null }) +watch(currentActivity, () => { + exchangeLookup.value = null + lookupProductId.value = '' +}) + const handleDocumentClick = (event: MouseEvent) => { const target = event.target if (!(target instanceof Element) || !target.closest('.account-product-picker')) { @@ -168,6 +175,21 @@ const selectedLookupProduct = computed(() => products.value.find(product => product.commodityId === selectedProductId.value) ) +// lookupProductId 只用于"手册类活动的兑换记录筛选",刻意不写回全局商品选择—— +// 免得只是想看看记录,却把抢购目标商品改掉了。 +const lookupProductId = ref('') + +const lookupCommodity = computed(() => { + if (isXiaodian.value) { + return { + id: selectedLookupProduct.value?.commodityId || '', + name: selectedLookupProduct.value?.commodityName || '' + } + } + const product = products.value.find(item => item.commodityId === lookupProductId.value) + return { id: lookupProductId.value, name: product?.commodityName || '' } +}) + const handleLookupProductChange = (event: Event) => { const productID = (event.target as HTMLSelectElement).value const product = products.value.find(item => item.commodityId === productID) @@ -179,15 +201,19 @@ const handleLookupProductChange = (event: Event) => { } const querySelectedExchangeRecords = async () => { - if (!selectedLookupProduct.value) { + // 和平小店必须选商品(记录按商品归属);手册类活动的记录自带商品名,商品可不选 + if (isXiaodian.value && !selectedLookupProduct.value) { showToast('提示', '请先选择要查询的商品', 'warn') return } - const { commodityId, commodityName } = selectedLookupProduct.value + const commodityId = lookupCommodity.value.id + const commodityName = lookupCommodity.value.name exchangeLookup.value = { productId: commodityId, productName: commodityName, loading: true, results: {} } try { - const result = await QueryXiaodianExchangeRecords(commodityId, commodityName) + const result = isXiaodian.value + ? await QueryXiaodianExchangeRecords(commodityId, commodityName) + : await QueryExchangeRecords(commodityId, commodityName) if (!exchangeLookup.value || exchangeLookup.value.productId !== commodityId) return exchangeLookup.value.loading = false exchangeLookup.value.results = result.results || {} @@ -195,15 +221,44 @@ const querySelectedExchangeRecords = async () => { showToast('查询失败', result.error || '兑换记录接口未返回成功', 'error') return } - const matched = Object.values(result.results || {}).filter((item: any) => item.success && item.matched).length - const failed = Object.values(result.results || {}).filter((item: any) => !item.success).length - showToast('查询完成', `${commodityName}:${matched} 个账号有兑换记录${failed ? `,${failed} 个查询失败` : ''}`, failed ? 'warn' : 'success') + const items = Object.values(result.results || {}) as any[] + const failed = items.filter((item) => !item.success).length + const total = items.reduce((sum, item) => sum + (item.records?.length || 0), 0) + if (commodityId) { + const matched = items.filter((item) => item.success && item.matched).length + showToast('查询完成', `${commodityName}:${matched} 个账号有兑换记录${failed ? `,${failed} 个查询失败` : ''}`, failed ? 'warn' : 'success') + } else { + showToast('查询完成', `共 ${total} 条兑换记录${failed ? `,${failed} 个账号查询失败` : ''}`, failed ? 'warn' : 'success') + } } catch (e: any) { if (exchangeLookup.value?.productId === commodityId) exchangeLookup.value.loading = false showToast('查询失败', e?.message || '兑换记录查询失败', 'error') } } +// recordSummary 取账号最新的兑换记录,用于表格里的紧凑展示。 +const recordSummary = (accountName: string) => { + const records = getLookupResult(accountName)?.records || [] + if (!records.length) return '' + const latest = records[0] + const name = latest.commodityName || latest.commodityId || '-' + const time = formatShortTime(latest.time || latest.buyTime || '') + return time ? `${name} · ${time}` : name +} + +const formatShortTime = (value: string) => { + if (!value) return '' + const text = String(value) + const match = text.match(/(\d{2})[-/](\d{2})\s+(\d{2}:\d{2})/) + if (match) return `${match[1]}-${match[2]} ${match[3]}` + const numeric = Number(text) + if (Number.isFinite(numeric) && numeric > 0) { + const date = new Date(numeric < 10_000_000_000 ? numeric * 1000 : numeric) + return `${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')} ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}` + } + return text.replace('T', ' ').slice(0, 16) +} + const getLookupResult = (accountName: string) => exchangeLookup.value?.results[accountName] const getMatchedRecord = (accountName: string) => { @@ -264,9 +319,18 @@ const orderStatus = (status: string) => { } const openExchangeRecords = async (accountName: string) => { + // 已经批量查过就直接用现成结果,避免同一个账号再打一次接口 + const cached = getLookupResult(accountName) + if (cached?.success && Array.isArray(cached.records)) { + recordsModal.value = { accountName, loading: false, error: '', records: cached.records } + return + } + recordsModal.value = { accountName, loading: true, error: '', records: [] } try { - const result = await QueryXiaodianAccountExchangeRecords(accountName) + const result = isXiaodian.value + ? await QueryXiaodianAccountExchangeRecords(accountName) + : await VerifyExchange(accountName) if (!recordsModal.value || recordsModal.value.accountName !== accountName) return recordsModal.value.loading = false recordsModal.value.error = result.error || '' @@ -292,8 +356,23 @@ const closeExchangeRecords = () => { 账号作战表 {{ accounts.length }} 个账号,已选 {{ selectedIndices.size }} 个 -
| 商品 | 数量 | 兑换时间 | 积分 | 昵称 |
|---|---|---|---|---|
|
+ {{ record.commodityName || record.commodityId }}
+ {{ record.showName }}
+ |
+ ×{{ record.exchangeNum || 1 }} | +{{ formatTime(record.time) }} | +{{ record.score || '-' }} | +{{ record.nickName || '-' }} | +
| 商品 | 兑换时间 | 支付时间 | 价格 | 状态 | 角色 |
|---|