增加和平小店关键词固定抢购
This commit is contained in:
@@ -1,13 +1,22 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import { computed, onUnmounted, ref, watch } from 'vue'
|
||||
import { useScheduler } from '@/composables/useScheduler'
|
||||
import { useAccounts } from '@/composables/useAccounts'
|
||||
import { useActivity } from '@/composables/useActivity'
|
||||
import { useProducts } from '@/composables/useProducts'
|
||||
import { useToast } from '@/composables/useToast'
|
||||
|
||||
const { scheduleActive, startNow, startSchedule, cancelSchedule, restoreSchedule } = useScheduler()
|
||||
const { scheduleActive, startNow, startFixed, startSchedule, cancelSchedule, restoreSchedule } = useScheduler()
|
||||
const { reloadAccounts, queryAllScore, queryAllXiaodianAssets } = useAccounts()
|
||||
const { currentActivity } = useActivity()
|
||||
const isXiaodian = computed(() => currentActivity.value?.id === 'xiaodian')
|
||||
const { products, selectedProductId, loadProducts, selectProduct } = useProducts()
|
||||
const { showToast } = useToast()
|
||||
const fixedKeyword = ref(localStorage.getItem('xiaodianFixedKeyword') || '')
|
||||
const fixedAttempts = ref(Number(localStorage.getItem('xiaodianFixedAttempts') || 3))
|
||||
const fixedDelayMs = ref(Number(localStorage.getItem('xiaodianFixedDelayMs') || 500))
|
||||
const keywordWatching = ref(false)
|
||||
let keywordTimer: number | null = null
|
||||
|
||||
// 从本地缓存恢复定时设置
|
||||
const { savedTime } = restoreSchedule()
|
||||
@@ -24,6 +33,61 @@ const queryAssets = () => {
|
||||
}
|
||||
queryAllScore()
|
||||
}
|
||||
|
||||
const saveFixedConfig = () => {
|
||||
localStorage.setItem('xiaodianFixedKeyword', fixedKeyword.value.trim())
|
||||
localStorage.setItem('xiaodianFixedAttempts', String(fixedAttempts.value))
|
||||
localStorage.setItem('xiaodianFixedDelayMs', String(fixedDelayMs.value))
|
||||
}
|
||||
|
||||
const startFixedBuy = () => {
|
||||
saveFixedConfig()
|
||||
if (!selectedProductId.value) return
|
||||
startFixed(fixedAttempts.value, fixedDelayMs.value)
|
||||
}
|
||||
|
||||
const toggleKeywordWatch = () => {
|
||||
keywordWatching.value = !keywordWatching.value
|
||||
if (keywordWatching.value) {
|
||||
saveFixedConfig()
|
||||
if (!fixedKeyword.value.trim()) {
|
||||
keywordWatching.value = false
|
||||
showToast('请输入关键词', '设置商品关键词后再开始监控', 'warn')
|
||||
return
|
||||
}
|
||||
void loadProducts(true)
|
||||
keywordTimer = window.setInterval(async () => {
|
||||
if (!keywordWatching.value || scheduleActive.value) return
|
||||
await loadProducts(false)
|
||||
const keyword = fixedKeyword.value.trim().toLowerCase()
|
||||
const hit = products.value.find(p => p.commodityName.toLowerCase().includes(keyword))
|
||||
if (hit) {
|
||||
keywordWatching.value = false
|
||||
if (keywordTimer) clearInterval(keywordTimer)
|
||||
selectProduct(hit.commodityId, hit.commodityName)
|
||||
await startFixed(fixedAttempts.value, fixedDelayMs.value)
|
||||
}
|
||||
}, 3000)
|
||||
} else if (keywordTimer) {
|
||||
clearInterval(keywordTimer)
|
||||
keywordTimer = null
|
||||
}
|
||||
}
|
||||
|
||||
watch(isXiaodian, (enabled) => {
|
||||
if (!enabled && keywordWatching.value) {
|
||||
keywordWatching.value = false
|
||||
if (keywordTimer) {
|
||||
clearInterval(keywordTimer)
|
||||
keywordTimer = null
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
if (keywordTimer) clearInterval(keywordTimer)
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -46,9 +110,30 @@ const queryAssets = () => {
|
||||
</button>
|
||||
<button class="btn" @click="reloadAccounts">加载账号</button>
|
||||
<button class="btn" @click="queryAssets">{{ isXiaodian ? '查询点券/碎片' : '查询积分' }}</button>
|
||||
<template v-if="isXiaodian">
|
||||
<button class="btn btn-fixed" @click="startFixedBuy">固定抢购</button>
|
||||
<button class="btn btn-watch" :class="{ watching: keywordWatching }" @click="toggleKeywordWatch">
|
||||
{{ keywordWatching ? '停止监控' : '关键词监控' }}
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<div class="schedule-bar">
|
||||
<template v-if="isXiaodian">
|
||||
<div class="schedule-item fixed-keyword">
|
||||
<label>上架关键词</label>
|
||||
<input v-model="fixedKeyword" type="text" placeholder="例如:礼包" @change="saveFixedConfig">
|
||||
</div>
|
||||
<div class="schedule-item">
|
||||
<label>次数</label>
|
||||
<input v-model.number="fixedAttempts" type="number" min="1" max="100" step="1" @change="saveFixedConfig">
|
||||
</div>
|
||||
<div class="schedule-item">
|
||||
<label>间隔</label>
|
||||
<input v-model.number="fixedDelayMs" type="number" min="0" max="60000" step="50" @change="saveFixedConfig">
|
||||
<span class="input-unit">ms</span>
|
||||
</div>
|
||||
</template>
|
||||
<div class="schedule-item">
|
||||
<label>目标</label>
|
||||
<input
|
||||
@@ -127,6 +212,11 @@ const queryAssets = () => {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.fixed-keyword input { width: 132px; }
|
||||
.btn-fixed { border-color: var(--warning); color: var(--warning); }
|
||||
.btn-watch { border-color: var(--accent-border); color: var(--accent); }
|
||||
.btn-watch.watching { background: var(--accent-soft); }
|
||||
|
||||
@media (max-width: 1180px) {
|
||||
.control-strip {
|
||||
flex-direction: column;
|
||||
|
||||
Reference in New Issue
Block a user