feat(config): 支持共享代理配置文件,发布 0.5.2

This commit is contained in:
yml
2026-11-20 13:20:12 +08:00
parent 635d80e63e
commit f4b3cfa486
13 changed files with 595 additions and 6 deletions
+126 -3
View File
@@ -2,7 +2,14 @@
import { computed, nextTick, ref } from 'vue'
import { useSettings, type RetryStage } from '@/composables/useSettings'
import { useToast } from '@/composables/useToast'
import { TestProxy, FetchProxy, RunProxyDrill } from '@wails/go/app/App'
import {
TestProxy,
FetchProxy,
RunProxyDrill,
LoadSharedProxyConfig,
SaveSharedProxyConfig,
SelectSharedProxyConfigFile
} from '@wails/go/app/App'
import { types } from '@wails/go/models'
const { settings, loadSettings, saveSettings } = useSettings()
@@ -24,6 +31,7 @@ const formData = ref({
proxyEnabled: false,
proxyUrl: '',
proxyApi: '',
sharedProxyConfigFile: '',
proxyExpiresAt: 0,
autoFetchProxyOnSchedule: false,
accountsPerProxy: 5,
@@ -157,12 +165,70 @@ const handleProxyDrill = async () => {
}
}
const open = async (section = '') => {
await loadSettings()
const copySettingsToForm = () => {
formData.value = {
...settings.value,
retryStages: settings.value.retryStages.map(s => ({ ...s }))
}
}
const handleSelectSharedProxyConfig = async (save: boolean) => {
try {
const res = await SelectSharedProxyConfigFile(save)
if (!res.success) {
if (res.error) showToast('选择文件失败', res.error, 'error')
return ''
}
if (!res.path) return ''
formData.value.sharedProxyConfigFile = res.path
return res.path
} catch (e: any) {
showToast('选择文件失败', e.message || String(e), 'error')
return ''
}
}
const handleLoadSharedProxyConfig = async () => {
const path = formData.value.sharedProxyConfigFile.trim()
|| await handleSelectSharedProxyConfig(false)
if (!path) return
try {
const res = await LoadSharedProxyConfig(path)
if (!res.success) {
showToast('加载失败', res.error || '共享代理配置未应用', 'error')
return
}
await loadSettings()
copySettingsToForm()
drillResult.value = null
showToast('共享配置已加载', '代理配置已应用并保存到当前实例', 'success')
} catch (e: any) {
showToast('加载失败', e.message || String(e), 'error')
}
}
const handleSaveSharedProxyConfig = async () => {
const path = formData.value.sharedProxyConfigFile.trim()
|| await handleSelectSharedProxyConfig(true)
if (!path) return
formData.value.sharedProxyConfigFile = path
try {
const saved = await saveSettings(formData.value)
if (!saved) return
const res = await SaveSharedProxyConfig(path)
if (!res.success) {
showToast('保存失败', res.error || '共享代理配置未保存', 'error')
return
}
showToast('共享配置已保存', '代理配置已写入指定 JSON 文件', 'success')
} catch (e: any) {
showToast('保存失败', e.message || String(e), 'error')
}
}
const open = async (section = '') => {
await loadSettings()
copySettingsToForm()
testProxyResult.value = null
drillResult.value = null
visible.value = true
@@ -250,6 +316,27 @@ defineExpose({ open, close })
</div>
</div>
<div class="shared-config-box">
<div class="shared-config-title">共享代理配置</div>
<div class="shared-config-path">
<input
v-model="formData.sharedProxyConfigFile"
class="form-input"
type="text"
placeholder="选择一个共享 JSON 文件,例如 D:\\douyu-proxy-config.json"
>
<button type="button" class="btn-action" @click="handleSelectSharedProxyConfig(false)">选择</button>
<button type="button" class="btn-action primary" @click="handleLoadSharedProxyConfig">加载</button>
</div>
<div class="shared-config-actions">
<span>启动时自动读取,本机新实例会继承该路径;当前代理 IP 和过期时间仍保存在本机。</span>
<button type="button" class="btn btn-ghost btn-sm" @click="handleSaveSharedProxyConfig">保存到共享文件</button>
</div>
<div class="form-hint">
共享文件仅包含代理提取 API、分组、备用比例和白名单设置,不包含账号、CK、当前代理 IP 或过期时间。文件中可能包含密码和密钥,请妥善保管。
</div>
</div>
<div v-if="formData.proxyEnabled" class="proxy-config-area">
<div class="form-row">
<div class="form-group">
@@ -1303,6 +1390,42 @@ defineExpose({ open, close })
word-break: break-word;
}
.shared-config-box {
margin-bottom: 16px;
padding: 12px;
border: 1px solid var(--line);
border-radius: var(--radius-sm);
background: var(--surface-2);
}
.shared-config-title {
margin-bottom: 8px;
color: var(--text-strong);
font-size: 13px;
font-weight: 600;
}
.shared-config-path {
display: flex;
align-items: center;
gap: 8px;
}
.shared-config-path .form-input {
flex: 1;
min-width: 0;
}
.shared-config-actions {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-top: 8px;
color: var(--muted);
font-size: 11px;
}
.proxy-config-area {
margin-top: 14px;
padding: 14px;
+3
View File
@@ -22,6 +22,7 @@ export interface Settings {
proxyEnabled: boolean
proxyUrl: string
proxyApi: string
sharedProxyConfigFile: string
proxyExpiresAt: number
autoFetchProxyOnSchedule: boolean
accountsPerProxy: number
@@ -53,6 +54,7 @@ const settings = ref<Settings>({
proxyEnabled: false,
proxyUrl: '',
proxyApi: '',
sharedProxyConfigFile: '',
proxyExpiresAt: 0,
autoFetchProxyOnSchedule: false,
accountsPerProxy: 5,
@@ -85,6 +87,7 @@ export function useSettings() {
proxyEnabled: !!cfg.proxyEnabled,
proxyUrl: cfg.proxyUrl || '',
proxyApi: cfg.proxyApi || '',
sharedProxyConfigFile: cfg.sharedProxyConfigFile || '',
proxyExpiresAt: cfg.proxyExpiresAt || 0,
autoFetchProxyOnSchedule: !!cfg.autoFetchProxyOnSchedule,
accountsPerProxy: cfg.accountsPerProxy || 5,