feat: improve xiaodian seckill flow

This commit is contained in:
yml2213
2026-08-08 23:04:40 +08:00
parent 16972b41cd
commit dde2b43d82
19 changed files with 871 additions and 64 deletions
+34 -7
View File
@@ -25,6 +25,7 @@ const accounts = ref<Account[]>([])
const selectedIndices = ref<Set<number>>(new Set())
const statusMap = ref<Record<string, AccountStatus | boolean>>({})
const scoreMap = ref<Record<string, string>>({})
const accountProductMap = ref<Record<string, string>>({})
export interface XiaodianAssets {
success: boolean
coupons: number
@@ -93,6 +94,12 @@ export function useAccounts() {
statusMap.value = JSON.parse(savedStatus)
} catch {}
}
const savedProducts = localStorage.getItem('accountProducts')
if (savedProducts) {
try {
accountProductMap.value = JSON.parse(savedProducts)
} catch {}
}
}
const queryAllScore = async () => {
@@ -170,26 +177,43 @@ export function useAccounts() {
markSelectedStatus({ pending: true, message })
}
const buildAccountProducts = (productId: string): Record<string, string> | null => {
const setAccountProduct = (accountName: string, productId: string) => {
if (productId) {
accountProductMap.value[accountName] = productId
} else {
delete accountProductMap.value[accountName]
}
localStorage.setItem('accountProducts', JSON.stringify(accountProductMap.value))
}
const getAccountProduct = (accountName: string): string => {
return accountProductMap.value[accountName] || ''
}
const buildAccountProducts = (productId: string, respectOverrides = true): Record<string, string> | null => {
if (selectedIndices.value.size === 0) {
showToast('提示', '请勾选要抢购的账号', 'warn')
return null
}
if (!productId) {
showToast('提示', '请先选择商品', 'warn')
return null
}
const ap: Record<string, string> = {}
selectedIndices.value.forEach(i => {
const account = accounts.value[i]
if (account) {
ap[account.name] = productId
const selectedProduct = respectOverrides ? getAccountProduct(account.name) : ''
const assignedProduct = selectedProduct || productId
if (assignedProduct) {
ap[account.name] = assignedProduct
}
}
})
if (Object.keys(ap).length === 0) {
showToast('提示', '没有有效账号可提交', 'warn')
showToast('提示', '请先选择商品,或为每个账号分配商品', 'warn')
return null
}
if (Object.keys(ap).length !== selectedIndices.value.size) {
showToast('提示', '还有已选账号没有商品', 'warn')
return null
}
return ap
@@ -201,6 +225,7 @@ export function useAccounts() {
statusMap,
scoreMap,
xiaodianAssetsMap,
accountProductMap,
loadAccounts,
reloadAccounts,
toggleAccount,
@@ -217,6 +242,8 @@ export function useAccounts() {
setStatus,
markSelectedStatus,
markSelectedPending,
setAccountProduct,
getAccountProduct,
selectedAccountNames,
buildAccountProducts
}