修复激进模式错误

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