feat(remote): 增加远端控制台与日志汇总导出
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||
import { useTheme } from '@/composables/useTheme'
|
||||
import { useScheduler } from '@/composables/useScheduler'
|
||||
import { useSettings } from '@/composables/useSettings'
|
||||
@@ -10,6 +10,7 @@ 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'
|
||||
|
||||
defineProps<{
|
||||
serverTime: string
|
||||
@@ -21,6 +22,12 @@ const { settings, loadSettings } = useSettings()
|
||||
|
||||
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
|
||||
|
||||
const proxyAutoFetchReady = computed(() => (
|
||||
settings.value.proxyEnabled
|
||||
@@ -50,11 +57,41 @@ const proxyTitle = computed(() => {
|
||||
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)
|
||||
}
|
||||
|
||||
onMounted(loadSettings)
|
||||
const refreshRemoteStatus = async () => {
|
||||
try {
|
||||
remoteStatus.value = await GetRemoteStatus()
|
||||
} catch {
|
||||
remoteStatus.value = { enabled: false, connected: false }
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadSettings()
|
||||
await refreshRemoteStatus()
|
||||
remoteStatusTimer = window.setInterval(refreshRemoteStatus, 3000)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
if (remoteStatusTimer) clearInterval(remoteStatusTimer)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -70,6 +107,17 @@ onMounted(loadSettings)
|
||||
<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="{
|
||||
@@ -147,6 +195,35 @@ onMounted(loadSettings)
|
||||
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);
|
||||
@@ -224,6 +301,6 @@ onMounted(loadSettings)
|
||||
@media (max-width: 900px) {
|
||||
.console-head { flex-wrap: wrap; }
|
||||
.top-actions { width: 100%; justify-content: flex-end; }
|
||||
.proxy-quick { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
||||
.proxy-quick, .remote-quick { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -17,6 +17,7 @@ const { showToast } = useToast()
|
||||
|
||||
const visible = ref(false)
|
||||
const proxySectionRef = ref<HTMLElement | null>(null)
|
||||
const remoteSectionRef = ref<HTMLElement | null>(null)
|
||||
const formData = ref({
|
||||
timeApiUrl: '',
|
||||
activity: '',
|
||||
@@ -39,7 +40,11 @@ const formData = ref({
|
||||
proxyAutoWhitelist: false,
|
||||
proxyWhitelistReplace: true,
|
||||
proxyWhitelistPassword: '',
|
||||
proxyWhitelistSignKey: ''
|
||||
proxyWhitelistSignKey: '',
|
||||
remoteEnabled: false,
|
||||
remoteUrl: '',
|
||||
remoteToken: '',
|
||||
remoteMachineName: ''
|
||||
})
|
||||
|
||||
const testingProxy = ref(false)
|
||||
@@ -235,6 +240,9 @@ const open = async (section = '') => {
|
||||
if (section === 'proxy') {
|
||||
await nextTick()
|
||||
proxySectionRef.value?.scrollIntoView({ block: 'start', behavior: 'smooth' })
|
||||
} else if (section === 'remote') {
|
||||
await nextTick()
|
||||
remoteSectionRef.value?.scrollIntoView({ block: 'start', behavior: 'smooth' })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,7 +341,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>
|
||||
|
||||
@@ -560,6 +568,49 @@ defineExpose({ open, close })
|
||||
<div class="form-hint">用于获取斗鱼服务端时间,一般不需要修改</div>
|
||||
</div>
|
||||
|
||||
<!-- 远端控制 -->
|
||||
<div ref="remoteSectionRef" class="form-section">
|
||||
<div class="form-section-title">远端控制(可选)</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.remoteEnabled" type="checkbox">
|
||||
<span class="toggle-slider"></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<template v-if="formData.remoteEnabled">
|
||||
<div class="form-group">
|
||||
<label class="form-label">控制中心地址</label>
|
||||
<input
|
||||
v-model="formData.remoteUrl"
|
||||
class="form-input"
|
||||
type="text"
|
||||
placeholder="https://control.example.com 或 http://127.0.0.1:18080"
|
||||
>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label class="form-label">机器显示名称</label>
|
||||
<input
|
||||
v-model="formData.remoteMachineName"
|
||||
class="form-input"
|
||||
type="text"
|
||||
placeholder="留空使用主机名,例如 PC-01"
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-hint">
|
||||
首次连接会在控制中心注册窗口内自动领取独立实例令牌并保存在本机,无需手工配置。
|
||||
Cookie、CSRF、代理密码、签名密钥和 Trace 内容不会上传。远端只接收结构化日志、运行摘要和控制命令。
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<!-- 和平小店参数 -->
|
||||
<div class="form-section">
|
||||
<div class="form-section-title">和平小店商品列表</div>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { ref } from 'vue'
|
||||
import { useToast } from './useToast'
|
||||
import { GetSettings, SaveSettings } from '@wails/go/app/App'
|
||||
import { types } from '@wails/go/models'
|
||||
|
||||
export interface RetryStage {
|
||||
maxElapsed: number
|
||||
@@ -31,6 +30,10 @@ export interface Settings {
|
||||
proxyWhitelistReplace: boolean
|
||||
proxyWhitelistPassword: string
|
||||
proxyWhitelistSignKey: string
|
||||
remoteEnabled: boolean
|
||||
remoteUrl: string
|
||||
remoteToken: string
|
||||
remoteMachineName: string
|
||||
}
|
||||
|
||||
const defaultRetryStages: RetryStage[] = [
|
||||
@@ -62,7 +65,11 @@ const settings = ref<Settings>({
|
||||
proxyAutoWhitelist: false,
|
||||
proxyWhitelistReplace: true,
|
||||
proxyWhitelistPassword: '',
|
||||
proxyWhitelistSignKey: ''
|
||||
proxyWhitelistSignKey: '',
|
||||
remoteEnabled: false,
|
||||
remoteUrl: '',
|
||||
remoteToken: '',
|
||||
remoteMachineName: ''
|
||||
})
|
||||
|
||||
export function useSettings() {
|
||||
@@ -70,7 +77,7 @@ export function useSettings() {
|
||||
|
||||
const loadSettings = async () => {
|
||||
try {
|
||||
const cfg = await GetSettings()
|
||||
const cfg: any = await GetSettings()
|
||||
settings.value = {
|
||||
timeApiUrl: cfg.timeApiUrl || '',
|
||||
activity: cfg.activity || '',
|
||||
@@ -95,7 +102,11 @@ export function useSettings() {
|
||||
proxyAutoWhitelist: !!cfg.proxyAutoWhitelist,
|
||||
proxyWhitelistReplace: !!cfg.proxyWhitelistReplace,
|
||||
proxyWhitelistPassword: cfg.proxyWhitelistPassword || '',
|
||||
proxyWhitelistSignKey: cfg.proxyWhitelistSignKey || ''
|
||||
proxyWhitelistSignKey: cfg.proxyWhitelistSignKey || '',
|
||||
remoteEnabled: !!cfg.remoteEnabled,
|
||||
remoteUrl: cfg.remoteUrl || '',
|
||||
remoteToken: cfg.remoteToken || '',
|
||||
remoteMachineName: cfg.remoteMachineName || ''
|
||||
}
|
||||
} catch (e: any) {
|
||||
showToast('读取设置失败', e.message, 'error')
|
||||
@@ -104,7 +115,9 @@ export function useSettings() {
|
||||
|
||||
const saveSettings = async (newSettings: Settings) => {
|
||||
try {
|
||||
const d = await SaveSettings(types.Config.createFrom(newSettings))
|
||||
// Generated Wails bindings may lag behind newly added backend fields during
|
||||
// development; the raw object preserves forward-compatible settings.
|
||||
const d = await SaveSettings(newSettings as any)
|
||||
if (d.success) {
|
||||
settings.value = { ...newSettings }
|
||||
showToast('设置已保存', '配置已生效', 'success')
|
||||
|
||||
Reference in New Issue
Block a user