Files
dygou_go/frontend/src/components/layout/RightConsole.vue
T
yml 9c83be798d feat: 优化代理准备并完善远端部署
- 增加严格代理、两分钟预取、白名单去重与分组状态展示\n- 增加远端注册令牌和安全地址校验\n- 增加 Docker Compose、Caddy 示例与控制中心部署文档
2026-11-21 20:59:35 +08:00

315 lines
9.6 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { computed, onMounted, onUnmounted, ref } from 'vue'
import { useTheme } from '@/composables/useTheme'
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
}>()
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')
const remoteStatus = ref<{
enabled: boolean
connected: boolean
message?: string
}>({ enabled: false, connected: false })
let remoteStatusTimer: number | null = null
let proxyStatusTimer: number | null = null
const proxyAutoFetchReady = computed(() => (
settings.value.proxyEnabled
&& settings.value.autoFetchProxyOnSchedule
&& !!settings.value.proxyApi.trim()
))
const proxyNeedsApi = computed(() => (
settings.value.proxyEnabled
&& settings.value.autoFetchProxyOnSchedule
&& !settings.value.proxyApi.trim()
))
const proxySummary = computed(() => {
if (!settings.value.proxyEnabled) return '代理未启用'
const size = settings.value.accountsPerProxy || 5
const spare = settings.value.proxySparePercent || 50
if (!settings.value.autoFetchProxyOnSchedule) return `代理 · ${size}号/组 · 备用${spare}%`
if (!settings.value.proxyApi.trim()) return `代理 · ${size}号/组 · 缺少 API`
return `代理 · ${size}号/组 · 备用${spare}% · 预取`
})
const proxyTitle = computed(() => {
if (!settings.value.proxyEnabled) return '代理尚未启用,点击配置'
if (proxyNeedsApi.value) return '已开启定时预取,但缺少代理提取 API;点击配置'
if (proxyAutoFetchReady.value) return '定时抢购触发前 2 分钟自动提取并校验代理;点击查看设置'
return '代理已启用,点击打开代理设置'
})
const remoteSummary = computed(() => {
if (!settings.value.remoteEnabled) return '远端 · 未启用'
if (remoteStatus.value.connected) return '远端 · 已连接'
if (remoteStatus.value.enabled) return '远端 · 连接中'
return '远端 · 未启用'
})
const remoteTitle = computed(() => {
if (!settings.value.remoteEnabled) return '远端控制未启用,点击配置'
const target = settings.value.remoteUrl.trim() || '尚未填写控制中心地址'
const detail = remoteStatus.value.message ? `;${remoteStatus.value.message}` : ''
return `${target}${detail};点击打开远端设置`
})
const openSettings = (section = '') => {
settingsModalRef.value?.open(section)
}
const refreshRemoteStatus = async () => {
try {
remoteStatus.value = await GetRemoteStatus()
} catch {
remoteStatus.value = { enabled: false, connected: false }
}
}
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>
<template>
<main class="right">
<header class="console-head">
<div class="headline">
<div class="nav-tabs">
<button class="nav-tab" :class="{ active: currentPage === 'console' }" @click="currentPage = 'console'">抢购控制台</button>
<button class="nav-tab" :class="{ active: currentPage === 'ck' }" @click="currentPage = 'ck'">CK 管理</button>
<button class="nav-tab" :class="{ active: currentPage === 'exchange' }" @click="currentPage = 'exchange'">兑换记录</button>
</div>
<span v-if="currentPage === 'console'" class="run-state" :class="{ active: runState !== '等待操作' }" :title="runState">{{ runState }}</span>
<span v-if="countdownSeconds > 0 && currentPage === 'console'" class="countdown-badge">{{ formatRemain(countdownSeconds) }}</span>
</div>
<div class="top-actions">
<button
class="remote-quick"
:class="{
active: settings.remoteEnabled && remoteStatus.connected,
warning: settings.remoteEnabled && !remoteStatus.connected
}"
:title="remoteTitle"
@click="openSettings('remote')"
>
{{ remoteSummary }}
</button>
<button
class="proxy-quick"
:class="{
active: settings.proxyEnabled,
scheduled: proxyAutoFetchReady,
warning: proxyNeedsApi
}"
:title="proxyTitle"
@click="openSettings('proxy')"
>
{{ proxySummary }}
</button>
<button class="btn btn-ghost settings-button" title="设置" aria-label="设置" @click="openSettings()">
<span aria-hidden="true">⚙</span>
<span>设置</span>
</button>
<button class="btn btn-ghost icon-btn theme-toggle" :title="theme === 'light' ? '切换到暗色' : '切换到亮色'" :aria-label="theme === 'light' ? '切换到暗色' : '切换到亮色'" @click="toggleTheme">{{ theme === 'light' ? '☀' : '☾' }}</button>
</div>
</header>
<template v-if="currentPage === 'console'">
<StatusGrid :server-time="serverTime" />
<ControlStrip />
<ProxyGroupPanel />
<section class="console-workspace">
<AccountTable />
</section>
<LogPanel />
</template>
<template v-else-if="currentPage === 'ck'">
<section class="page-body"><CKManager /></section>
</template>
<template v-else>
<ExchangeRecords />
</template>
</main>
<SettingsModal ref="settingsModalRef" />
</template>
<style scoped>
.right {
display: flex;
flex-direction: column;
min-width: 0;
min-height: 0;
overflow: hidden;
}
.console-head {
padding: 14px 20px;
border-bottom: 1px solid var(--line);
background: var(--surface);
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
}
.headline, .top-actions, .nav-tabs { display: flex; align-items: center; }
.headline { gap: 14px; min-width: 0; }
.top-actions { gap: 6px; }
.nav-tabs { gap: 4px; }
.proxy-quick {
height: 30px;
padding: 0 10px;
border: 1px solid var(--line);
border-radius: 999px;
background: var(--surface-2);
color: var(--muted);
cursor: pointer;
font-size: 11px;
white-space: nowrap;
}
.remote-quick {
height: 30px;
padding: 0 10px;
border: 1px solid var(--line);
border-radius: 999px;
background: var(--surface-2);
color: var(--muted);
cursor: pointer;
font-size: 11px;
white-space: nowrap;
}
.remote-quick:hover {
border-color: var(--accent-border);
color: var(--text-strong);
}
.remote-quick.active {
color: var(--success);
border-color: var(--success);
background: var(--success-soft);
}
.remote-quick.warning {
color: var(--warning);
border-color: var(--warning);
background: var(--warning-soft);
}
.proxy-quick:hover {
border-color: var(--accent-border);
color: var(--text-strong);
}
.proxy-quick.active {
color: var(--success);
border-color: var(--success);
background: var(--success-soft);
}
.proxy-quick.scheduled {
color: var(--accent);
border-color: var(--accent-border);
background: var(--accent-soft);
}
.proxy-quick.warning {
color: var(--warning);
border-color: var(--warning);
background: var(--warning-soft);
}
.settings-button {
display: inline-flex;
align-items: center;
gap: 6px;
height: 30px;
padding: 0 10px;
font-size: 12px;
}
.nav-tab {
height: 28px;
padding: 0 12px;
border: 0;
border-radius: var(--radius-sm);
background: transparent;
color: var(--muted);
cursor: pointer;
font-size: 13px;
font-weight: 500;
}
.nav-tab:hover { color: var(--text-strong); background: var(--surface-2); }
.nav-tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.run-state, .countdown-badge {
display: inline-flex;
align-items: center;
padding: 4px 10px;
border: 1px solid var(--line);
border-radius: 999px;
font-size: 12px;
font-weight: 500;
white-space: nowrap;
}
.run-state { max-width: 220px; overflow: hidden; text-overflow: ellipsis; color: var(--muted); background: var(--surface-2); }
.run-state.active { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-border); }
.countdown-badge { color: var(--danger); background: var(--danger-soft); border-color: var(--danger); font-variant-numeric: tabular-nums; }
.console-workspace {
flex: 1;
min-height: 0;
overflow: hidden;
padding: 14px 20px;
}
.page-body { flex: 1; min-height: 0; overflow-y: auto; }
@media (max-width: 1180px) {
.right { overflow: visible; min-height: auto; }
.console-workspace { min-height: 520px; padding: 14px; }
}
@media (max-width: 900px) {
.console-head { flex-wrap: wrap; }
.top-actions { width: 100%; justify-content: flex-end; }
.proxy-quick, .remote-quick { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
}
</style>