feat: 优化代理准备并完善远端部署

- 增加严格代理、两分钟预取、白名单去重与分组状态展示\n- 增加远端注册令牌和安全地址校验\n- 增加 Docker Compose、Caddy 示例与控制中心部署文档
This commit is contained in:
yml
2026-11-21 20:59:35 +08:00
parent d176c421a8
commit 9c83be798d
43 changed files with 2755 additions and 119 deletions
@@ -6,6 +6,7 @@ import { useProducts } from '@/composables/useProducts'
import type { Product } from '@/composables/useProducts'
import { useActivity } from '@/composables/useActivity'
import { useToast } from '@/composables/useToast'
import { useProxyStatus } from '@/composables/useProxyStatus'
import { formatExchangeTime, formatShortExchangeTime } from '@/utils/formatTime'
import {
ExportLatestXiaodianReport,
@@ -35,6 +36,7 @@ const {
const { products, selectedProductId, selectedProductName, selectProduct, clearSelection } = useProducts()
const { currentActivity } = useActivity()
const { showToast } = useToast()
const { getAccountProxy } = useProxyStatus()
const isXiaodian = computed(() => currentActivity.value?.id === 'xiaodian')
const productFilterMap = ref<Record<string, string>>({})
const openProductAccount = ref<string | null>(null)
@@ -411,6 +413,7 @@ const closeExchangeRecords = () => {
<th v-if="isXiaodian">扭蛋碎片</th>
<th v-if="isXiaodian">角色信息</th>
<th class="exchange-record-col">兑换记录</th>
<th class="proxy-col">代理</th>
<th class="status-col">状态</th>
<th>最后结果</th>
<th class="account-action-col">操作</th>
@@ -418,7 +421,7 @@ const closeExchangeRecords = () => {
</thead>
<tbody>
<tr v-if="accounts.length === 0">
<td :colspan="isXiaodian ? 12 : 10" class="empty-state">暂无账号,请加载账号</td>
<td :colspan="isXiaodian ? 13 : 11" class="empty-state">暂无账号,请加载账号</td>
</tr>
<template v-else>
<tr
@@ -550,6 +553,17 @@ const closeExchangeRecords = () => {
>{{ recordSummary(account.name) }}</div>
<button class="btn btn-compact btn-records" @click.stop="openExchangeRecords(account.name)">记录</button>
</td>
<td class="proxy-cell">
<span
v-if="getAccountProxy(account.name)"
class="proxy-badge"
:class="getAccountProxy(account.name)?.transport"
:title="getAccountProxy(account.name)?.proxy || ''"
>
{{ getAccountProxy(account.name)?.groupLabel }}
</span>
<span v-else class="account-sub">-</span>
</td>
<td class="status-td">
<span
class="status-badge"
@@ -828,6 +842,40 @@ tbody tr:hover {
width: 96px;
}
.proxy-col,
.proxy-cell {
width: 76px;
white-space: nowrap;
}
.proxy-badge {
display: inline-flex;
align-items: center;
padding: 3px 7px;
border: 1px solid var(--line);
border-radius: 999px;
background: var(--surface-2);
color: var(--muted);
font-size: 11px;
font-weight: 600;
}
.proxy-badge.proxy {
color: var(--success);
border-color: var(--success);
background: var(--success-soft);
}
.proxy-badge.direct {
color: var(--danger);
border-color: var(--danger);
background: var(--danger-soft);
}
.proxy-badge.unassigned {
color: var(--muted);
}
.account-action-col,
.account-action-cell {
width: 92px;
@@ -0,0 +1,128 @@
<script setup lang="ts">
import { computed } from 'vue'
import { useProxyStatus } from '@/composables/useProxyStatus'
const { proxyStatus } = useProxyStatus()
const stateLabel = computed(() => {
const status = proxyStatus.value
if (!status.enabled) return '本地直连'
if (status.state === 'ready') return status.required ? '严格代理已就绪' : '代理已就绪'
if (status.state === 'degraded') return '代理降级运行'
if (status.state === 'direct_fallback') return '代理故障回退直连'
if (status.state === 'failed') return status.required ? '严格代理准备失败' : '代理准备失败'
if (status.state === 'preparing') return '代理准备中'
if (status.state === 'stale') return '代理配置已变更'
return status.required ? '严格代理未准备' : '代理未准备'
})
const stateClass = computed(() => ({
warning: ['direct_fallback', 'failed', 'degraded', 'stale'].includes(proxyStatus.value.state),
active: proxyStatus.value.state === 'ready',
idle: !proxyStatus.value.enabled
}))
const groups = computed(() => (proxyStatus.value.groups || []).filter(group => group.role === 'active'))
</script>
<template>
<section class="proxy-strip">
<div class="proxy-title">
<span class="state-dot" :class="stateClass"></span>
<strong>{{ stateLabel }}</strong>
<span v-if="proxyStatus.enabled" class="sub">
活动 {{ proxyStatus.activeCount }} · 备用 {{ proxyStatus.standbyCount }}/{{ proxyStatus.standbyTarget }} · 直连 {{ proxyStatus.directCount }}
</span>
</div>
<div v-if="groups.length" class="group-list">
<span
v-for="group in groups"
:key="group.groupIndex"
class="group-chip"
:class="group.state"
:title="`${group.proxy || '直连'}${group.region ? ' · ' + group.region : ''}${group.rttMs ? ' · ' + group.rttMs + 'ms' : ''}${group.lastError ? ' · ' + group.lastError : ''}`"
>
G{{ group.groupIndex }}
<span>{{ group.state === 'direct' ? '直连' : group.state === 'failed' ? '失败' : `${group.accountCount}号` }}</span>
</span>
</div>
<span v-if="proxyStatus.lastError" class="proxy-error" :title="proxyStatus.lastError">{{ proxyStatus.lastError }}</span>
</section>
</template>
<style scoped>
.proxy-strip {
display: flex;
align-items: center;
gap: 12px;
min-height: 38px;
padding: 7px 20px;
border-bottom: 1px solid var(--line);
background: var(--surface);
overflow: hidden;
}
.proxy-title, .group-list {
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
}
.proxy-title {
flex-shrink: 0;
font-size: 12px;
}
.sub, .proxy-error {
color: var(--muted);
font-size: 11px;
}
.proxy-error {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.state-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--muted);
}
.state-dot.active { background: var(--success); }
.state-dot.warning { background: var(--warning); }
.state-dot.idle { background: var(--muted); }
.group-list {
overflow: auto hidden;
scrollbar-width: none;
}
.group-chip {
display: inline-flex;
align-items: center;
gap: 4px;
padding: 4px 8px;
border: 1px solid var(--line);
border-radius: 999px;
background: var(--surface-2);
color: var(--muted);
font-size: 11px;
white-space: nowrap;
}
.group-chip.active {
color: var(--success);
border-color: var(--success);
background: var(--success-soft);
}
.group-chip.direct, .group-chip.failed {
color: var(--danger);
border-color: var(--danger);
background: var(--danger-soft);
}
</style>
@@ -5,12 +5,14 @@ import { useScheduler } from '@/composables/useScheduler'
import { useSettings } from '@/composables/useSettings'
import StatusGrid from '@/components/console/StatusGrid.vue'
import ControlStrip from '@/components/console/ControlStrip.vue'
import ProxyGroupPanel from '@/components/console/ProxyGroupPanel.vue'
import AccountTable from '@/components/account/AccountTable.vue'
import LogPanel from '@/components/log/LogPanel.vue'
import SettingsModal from '@/components/modal/SettingsModal.vue'
import CKManager from '@/components/ck/CKManager.vue'
import ExchangeRecords from '@/components/exchange/ExchangeRecords.vue'
import { GetRemoteStatus } from '@wails/go/app/App'
import { useProxyStatus } from '@/composables/useProxyStatus'
defineProps<{
serverTime: string
@@ -19,6 +21,7 @@ defineProps<{
const { theme, toggleTheme } = useTheme()
const { runState, countdownSeconds, formatRemain } = useScheduler()
const { settings, loadSettings } = useSettings()
const { loadProxyStatus } = useProxyStatus()
const settingsModalRef = ref<InstanceType<typeof SettingsModal> | null>(null)
const currentPage = ref<'console' | 'ck' | 'exchange'>('console')
@@ -28,6 +31,7 @@ const remoteStatus = ref<{
message?: string
}>({ enabled: false, connected: false })
let remoteStatusTimer: number | null = null
let proxyStatusTimer: number | null = null
const proxyAutoFetchReady = computed(() => (
settings.value.proxyEnabled
@@ -44,7 +48,7 @@ const proxyNeedsApi = computed(() => (
const proxySummary = computed(() => {
if (!settings.value.proxyEnabled) return '代理未启用'
const size = settings.value.accountsPerProxy || 5
const spare = settings.value.proxySparePercent || 25
const spare = settings.value.proxySparePercent || 50
if (!settings.value.autoFetchProxyOnSchedule) return `代理 · ${size}号/组 · 备用${spare}%`
if (!settings.value.proxyApi.trim()) return `代理 · ${size}号/组 · 缺少 API`
return `代理 · ${size}号/组 · 备用${spare}% · 预取`
@@ -53,7 +57,7 @@ const proxySummary = computed(() => {
const proxyTitle = computed(() => {
if (!settings.value.proxyEnabled) return '代理尚未启用,点击配置'
if (proxyNeedsApi.value) return '已开启定时预取,但缺少代理提取 API;点击配置'
if (proxyAutoFetchReady.value) return '定时抢购触发前 30 秒自动提取并校验代理;点击查看设置'
if (proxyAutoFetchReady.value) return '定时抢购触发前 2 分钟自动提取并校验代理;点击查看设置'
return '代理已启用,点击打开代理设置'
})
@@ -86,11 +90,14 @@ const refreshRemoteStatus = async () => {
onMounted(async () => {
await loadSettings()
await refreshRemoteStatus()
await loadProxyStatus()
remoteStatusTimer = window.setInterval(refreshRemoteStatus, 3000)
proxyStatusTimer = window.setInterval(loadProxyStatus, 2000)
})
onUnmounted(() => {
if (remoteStatusTimer) clearInterval(remoteStatusTimer)
if (proxyStatusTimer) clearInterval(proxyStatusTimer)
})
</script>
@@ -141,6 +148,7 @@ onUnmounted(() => {
<template v-if="currentPage === 'console'">
<StatusGrid :server-time="serverTime" />
<ControlStrip />
<ProxyGroupPanel />
<section class="console-workspace">
<AccountTable />
</section>
+36 -10
View File
@@ -30,19 +30,21 @@ const formData = ref({
seckillMode: 1,
xiaodianPageSize: 200,
proxyEnabled: false,
proxyRequired: true,
proxyUrl: '',
proxyApi: '',
sharedProxyConfigFile: '',
proxyExpiresAt: 0,
autoFetchProxyOnSchedule: false,
accountsPerProxy: 5,
proxySparePercent: 25,
proxySparePercent: 50,
proxyAutoWhitelist: false,
proxyWhitelistReplace: true,
proxyWhitelistPassword: '',
proxyWhitelistSignKey: '',
remoteEnabled: false,
remoteUrl: '',
remoteEnrollmentToken: '',
remoteToken: '',
remoteMachineName: ''
})
@@ -61,10 +63,10 @@ const proxyOverviewTitle = computed(() => (
const proxyOverviewDetail = computed(() => {
if (!formData.value.proxyEnabled) return '启用后可配置账号分组、提取 API 和自动预取'
const size = formData.value.accountsPerProxy || 5
const spare = formData.value.proxySparePercent || 25
const spare = formData.value.proxySparePercent || 50
if (!formData.value.autoFetchProxyOnSchedule) return `当前每 ${size} 个账号一个代理,备用 ${spare}%`
if (!formData.value.proxyApi.trim()) return '已开启自动预取,但尚未填写代理提取 API'
return `每 ${size} 个账号一组,备用 ${spare}%;定时抢购触发前 30 秒自动预取`
return `每 ${size} 个账号一组,备用 ${spare}%;定时抢购触发前 2 分钟自动预取`
})
const proxyAutoFetchReady = computed(() => (
@@ -324,6 +326,19 @@ defineExpose({ open, close })
</div>
</div>
<div class="form-group">
<div class="toggle-row">
<div>
<span class="toggle-label">严格代理模式</span>
<div class="form-hint">代理未就绪时中止抢购,运行中也不自动回退直连</div>
</div>
<label class="toggle">
<input v-model="formData.proxyRequired" type="checkbox">
<span class="toggle-slider"></span>
</label>
</div>
</div>
<div class="shared-config-box">
<div class="shared-config-title">共享代理配置</div>
<div class="shared-config-path">
@@ -341,7 +356,7 @@ defineExpose({ open, close })
<button type="button" class="btn btn-ghost btn-sm" @click="handleSaveSharedProxyConfig">保存到共享文件</button>
</div>
<div class="form-hint">
共享文件包含代理提取 API、分组、备用比例、白名单和远端控制设置,不包含账号、CK、当前代理 IP 或过期时间。文件中可能包含密码、签名密钥和远端令牌,请妥善保管。
共享文件包含代理提取 API、分组、备用比例、白名单和远端控制设置,不包含账号、CK、当前代理 IP 或过期时间。文件中可能包含密码、签名密钥和注册令牌,请妥善保管。
</div>
</div>
@@ -367,12 +382,12 @@ defineExpose({ open, close })
v-model.number="formData.proxySparePercent"
class="form-input"
type="number"
min="1"
min="50"
max="100"
step="1"
>
<div class="form-hint">
默认 25%,至少备用 1 个;6 个活动组会额外提取 2 个备用代理。
最低 50%,默认 50%;4 个活动组会额外提取 2 个备用代理。
</div>
</div>
</div>
@@ -435,10 +450,10 @@ defineExpose({ open, close })
<div class="form-group">
<label class="checkbox-row">
<input v-model="formData.autoFetchProxyOnSchedule" type="checkbox">
<span class="checkbox-text">定时抢购触发前 30 秒自动预取并校验代理</span>
<span class="checkbox-text">定时抢购触发前 2 分钟自动预取并校验代理</span>
</label>
<div class="form-hint">
仅对定时抢购生效。按“每组账号数”提取对应数量并校验;立即抢购会在开始前同步准备代理。建议使用 10 分钟以上时长,覆盖抢购与最长 180 秒支付。
按“每组账号数”提取对应数量并校验;严格代理模式下定时抢购始终提前 2 分钟准备。立即抢购会在开始前同步准备代理。建议使用 10 分钟以上时长,覆盖抢购与最长 180 秒支付。
</div>
</div>
@@ -589,11 +604,22 @@ defineExpose({ open, close })
<input
v-model="formData.remoteUrl"
class="form-input"
type="text"
type="url"
placeholder="https://control.example.com 或 http://127.0.0.1:18080"
>
<div class="form-hint">只填写控制中心根地址,不要带 /#admin= 后面的管理令牌。</div>
</div>
<div class="form-row">
<div class="form-group">
<label class="form-label">注册令牌</label>
<input
v-model="formData.remoteEnrollmentToken"
class="form-input"
type="password"
autocomplete="off"
placeholder="填写控制中心的 DOUYU_CONTROL_ENROLL_TOKEN"
>
</div>
<div class="form-group">
<label class="form-label">机器显示名称</label>
<input
@@ -605,7 +631,7 @@ defineExpose({ open, close })
</div>
</div>
<div class="form-hint">
首次连接会在控制中心注册窗口内自动领取独立实例令牌并保存在本机,无需手工配置。
首次连接使用注册令牌领取独立实例令牌并保存在本机,后续不需要再次填写。注册令牌只用于注册,不会作为实例连接令牌使用。
Cookie、CSRF、代理密码、签名密钥和 Trace 内容不会上传。远端只接收结构化日志、运行摘要和控制命令。
</div>
</template>
@@ -0,0 +1,74 @@
import { computed, ref } from 'vue'
import { GetProxyStatus } from '@wails/go/app/App'
export interface ProxyGroupStatus {
groupIndex: number
role: string
state: string
accountCount: number
accounts?: string[]
proxy?: string
region?: string
rttMs?: number
switchCount: number
lastError?: string
}
export interface AccountProxyView {
accountName: string
groupIndex?: number
groupLabel: string
transport: string
proxy?: string
}
export interface ProxyStatus {
enabled: boolean
required: boolean
state: string
activeCount: number
standbyCount: number
standbyTarget: number
directCount: number
lastError?: string
updatedAt: string
groups: ProxyGroupStatus[]
accounts: AccountProxyView[]
}
const proxyStatus = ref<ProxyStatus>({
enabled: false,
required: false,
state: 'not-loaded',
activeCount: 0,
standbyCount: 0,
standbyTarget: 0,
directCount: 0,
updatedAt: '',
groups: [],
accounts: []
})
const accountProxyMap = computed(() => {
const out: Record<string, AccountProxyView> = {}
for (const account of proxyStatus.value.accounts || []) {
out[account.accountName] = account
}
return out
})
export function useProxyStatus() {
const loadProxyStatus = async () => {
try {
proxyStatus.value = await GetProxyStatus()
} catch {}
}
const getAccountProxy = (accountName: string) => accountProxyMap.value[accountName]
return {
proxyStatus,
loadProxyStatus,
getAccountProxy
}
}
+8 -2
View File
@@ -19,6 +19,7 @@ export interface Settings {
seckillMode: number // 0=标准, 1=激进
xiaodianPageSize: number
proxyEnabled: boolean
proxyRequired: boolean
proxyUrl: string
proxyApi: string
sharedProxyConfigFile: string
@@ -32,6 +33,7 @@ export interface Settings {
proxyWhitelistSignKey: string
remoteEnabled: boolean
remoteUrl: string
remoteEnrollmentToken: string
remoteToken: string
remoteMachineName: string
}
@@ -55,19 +57,21 @@ const settings = ref<Settings>({
seckillMode: 1,
xiaodianPageSize: 200,
proxyEnabled: false,
proxyRequired: true,
proxyUrl: '',
proxyApi: '',
sharedProxyConfigFile: '',
proxyExpiresAt: 0,
autoFetchProxyOnSchedule: false,
accountsPerProxy: 5,
proxySparePercent: 25,
proxySparePercent: 50,
proxyAutoWhitelist: false,
proxyWhitelistReplace: true,
proxyWhitelistPassword: '',
proxyWhitelistSignKey: '',
remoteEnabled: false,
remoteUrl: '',
remoteEnrollmentToken: '',
remoteToken: '',
remoteMachineName: ''
})
@@ -92,19 +96,21 @@ export function useSettings() {
seckillMode: cfg.seckillMode ?? 1,
xiaodianPageSize: cfg.xiaodianPageSize || 200,
proxyEnabled: !!cfg.proxyEnabled,
proxyRequired: !!cfg.proxyRequired,
proxyUrl: cfg.proxyUrl || '',
proxyApi: cfg.proxyApi || '',
sharedProxyConfigFile: cfg.sharedProxyConfigFile || '',
proxyExpiresAt: cfg.proxyExpiresAt || 0,
autoFetchProxyOnSchedule: !!cfg.autoFetchProxyOnSchedule,
accountsPerProxy: cfg.accountsPerProxy || 5,
proxySparePercent: cfg.proxySparePercent || 25,
proxySparePercent: cfg.proxySparePercent || 50,
proxyAutoWhitelist: !!cfg.proxyAutoWhitelist,
proxyWhitelistReplace: !!cfg.proxyWhitelistReplace,
proxyWhitelistPassword: cfg.proxyWhitelistPassword || '',
proxyWhitelistSignKey: cfg.proxyWhitelistSignKey || '',
remoteEnabled: !!cfg.remoteEnabled,
remoteUrl: cfg.remoteUrl || '',
remoteEnrollmentToken: cfg.remoteEnrollmentToken || '',
remoteToken: cfg.remoteToken || '',
remoteMachineName: cfg.remoteMachineName || ''
}