修复激进模式错误

This commit is contained in:
yml2213
2026-06-26 15:20:18 +08:00
parent e8f101d0b8
commit e9621df0b9
3 changed files with 35 additions and 30 deletions
@@ -1,6 +1,5 @@
<script setup lang="ts">
import { computed, ref } from 'vue'
import { useVirtualizer } from '@tanstack/vue-virtual'
import { computed } from 'vue'
import { useAccounts } from '@/composables/useAccounts'
import { useProducts } from '@/composables/useProducts'
@@ -15,21 +14,10 @@ const {
const { selectedProductName } = useProducts()
const parentRef = ref<HTMLElement | null>(null)
const allSelected = computed(() =>
accounts.value.length > 0 && selectedIndices.value.size === accounts.value.length
)
const virtualizer = useVirtualizer(
computed(() => ({
count: accounts.value.length,
getScrollElement: () => parentRef.value,
estimateSize: () => 48,
overscan: 5
}))
)
// 状态信息计算
const getStatusInfo = (name: string, selected: boolean) => {
const st = statusMap.value[name]
@@ -79,7 +67,7 @@ const getResultMessage = (name: string) => {
</label>
</div>
<div ref="parentRef" class="table-wrap">
<div class="table-wrap">
<table>
<thead>
<tr>
@@ -98,24 +86,23 @@ const getResultMessage = (name: string) => {
</tr>
<template v-else>
<tr
v-for="item in virtualizer.getVirtualItems()"
:key="String(item.key)"
:style="{ height: `${item.size}px` }"
v-for="(account, index) in accounts"
:key="account.name"
>
<td class="select-cell">
<label class="account-check" @click="toggleAccount(item.index)">
<div class="check-box" :class="{ checked: selectedIndices.has(item.index) }">
<span v-if="selectedIndices.has(item.index)">✓</span>
<label class="account-check" @click="toggleAccount(index)">
<div class="check-box" :class="{ checked: selectedIndices.has(index) }">
<span v-if="selectedIndices.has(index)">✓</span>
</div>
</label>
</td>
<td>
<div class="account-name">{{ accounts[item.index].name }}</div>
<div class="account-sub">{{ selectedIndices.has(item.index) ? '已加入任务' : '未选择' }}</div>
<div class="account-name">{{ account.name }}</div>
<div class="account-sub">{{ selectedIndices.has(index) ? '已加入任务' : '未选择' }}</div>
</td>
<td>
<span
v-if="accounts[item.index].cookie"
v-if="account.cookie"
class="status-badge status-success"
>
已加载
@@ -128,18 +115,18 @@ const getResultMessage = (name: string) => {
</span>
<span v-else>-</span>
</td>
<td>{{ getScore(accounts[item.index].name) }}</td>
<td>{{ getScore(account.name) }}</td>
<td class="status-td">
<span
class="status-badge"
:class="getStatusInfo(accounts[item.index].name, selectedIndices.has(item.index)).cls"
:class="getStatusInfo(account.name, selectedIndices.has(index)).cls"
>
{{ getStatusInfo(accounts[item.index].name, selectedIndices.has(item.index)).text }}
{{ getStatusInfo(account.name, selectedIndices.has(index)).text }}
</span>
</td>
<td>
<span class="account-sub" :title="getResultMessage(accounts[item.index].name)">
{{ getResultMessage(accounts[item.index].name) }}
<span class="account-sub" :title="getResultMessage(account.name)">
{{ getResultMessage(account.name) }}
</span>
</td>
</tr>
@@ -235,7 +222,7 @@ tbody tr:last-child td {
}
tbody tr {
transition: .1s;
transition: background-color .15s ease;
}
tbody tr:hover {
+1 -1
View File
@@ -82,7 +82,7 @@ func defaultConfig() types.Config {
Concurrency: constants.DefaultConcurrency,
Attempts: constants.DefaultAttempts,
RetryStages: defaultRetryStages(),
SeckillMode: types.SeckillModeAggressive,
SeckillMode: types.SeckillModeNormal,
}
}
+18
View File
@@ -286,6 +286,10 @@ func (s *Scheduler) RunNow(accountProducts map[string]string) {
// 激进模式每轮开始时清空缓存,强制重新获取 CSRF
if s.seckillMode == types.SeckillModeAggressive {
s.clearAttemptCache()
// 第1轮时从预热数据初始化缓存
if round == 1 {
s.initCacheFromWarmup(roundAttempts)
}
}
logger.LogEvent("抢购", "info", "第%d轮: 待抢购 %d 个账号,本轮执行=%d,剩余时间=%v,模式=%s",
@@ -560,6 +564,20 @@ func (s *Scheduler) getAttemptCache(accountName string) *types.AttemptCache {
return s.attemptCache[accountName]
}
// initCacheFromWarmup 从预热数据初始化激进模式缓存。
func (s *Scheduler) initCacheFromWarmup(attempts []types.ExchangeAttempt) {
for _, attempt := range attempts {
if warmup, ok := s.warmupFor(attempt); ok {
s.setAttemptCache(attempt.Account.Name, &types.AttemptCache{
CSRF: warmup.CSRF,
RoleName: warmup.RoleName,
LastCheck: time.Now(),
})
logger.LogEvent("抢购", "info", "从预热初始化缓存: 账号=%s", attempt.Account.Name)
}
}
}
func (s *Scheduler) setAttemptCache(accountName string, cache *types.AttemptCache) {
s.attemptCacheMu.Lock()
defer s.attemptCacheMu.Unlock()