Files
crawler-plugin/frontend-vue/src/shared/components/ApiSecretSettingsPanel.vue
T
huangzd1997 faae355bcf fix(user-secret): 青果只用 Authkey/Authpwd,链接由前端拼并上报服务端
青果没有可填的提取链接(10-30 口径),但商标检测在服务端只认 proxy_url,
保存时又主动清空服务端记录 ⇒ 用户填了账密仍被判「未配置代理」。
- 新增 qingguo-link.ts(零依赖):由账密拼 overseas.proxy.qg.net/get 链接,
  Authkey/Authpwd 走 userinfo(隧道 Basic 认证没有第二个通道)
- 保存时本地与服务端都用这条链接;已存账密的旧配置刷新后仍能读回
- 4 例纯函数用例钉住拼装规则与空 key 语义
2026-10-31 22:16:30 +08:00

686 lines
26 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.
<template>
<div class="secret-settings-body">
<section v-for="module in modules" :key="module.moduleKey" class="secret-card">
<div class="secret-card-head">
<div class="secret-card-heading">
<div class="secret-card-title">
{{ module.moduleLabel }}
<span class="source-tag">{{ llmChannelLabel(moduleChannels[module.moduleKey]) }}</span>
<span class="status-pill" :class="statusPillClassOf(module.moduleKey)">
{{ statusPillTextOf(module.moduleKey) }}
</span>
</div>
<div class="secret-card-desc">{{ descriptionOf(module.moduleKey) }}</div>
</div>
<button
v-if="snapshotOf(module.moduleKey).exists"
type="button"
class="link-danger"
:disabled="busy"
@click="clearModule(module.moduleKey as ApiSecretModuleKey)"
>
清空
</button>
</div>
<div class="source-picker" role="radiogroup" :aria-label="`${module.moduleLabel}渠道`">
<button
v-for="option in LLM_CHANNEL_OPTIONS"
:key="option.key"
type="button"
role="radio"
:aria-checked="moduleChannels[module.moduleKey] === option.key"
class="source-option"
:class="{ 'source-option--active': moduleChannels[module.moduleKey] === option.key }"
:disabled="busy"
@click="selectChannel(module.moduleKey, option.key)"
>
<span class="source-option-label">{{ option.label }}</span>
<span class="source-option-hint">{{ option.hint }}</span>
</button>
</div>
<div class="secret-field">
<label class="field-label" :for="`secret-input-${module.moduleKey}`">接口密钥</label>
<input
:id="`secret-input-${module.moduleKey}`"
v-model="moduleStates[module.moduleKey].input"
class="secret-input"
type="password"
:placeholder="placeholderOf(module.moduleKey)"
autocomplete="off"
spellcheck="false"
:disabled="busy"
/>
</div>
<div v-if="channelSwitchNeedsValue(module.moduleKey)" class="inline-warn">
已切换到「{{ llmChannelLabel(moduleChannels[module.moduleKey]) }}」,请填写该渠道的密钥后再保存(两家渠道的密钥不通用)。
</div>
<div class="secret-actions">
<button
type="button"
class="check-btn"
:disabled="busy || moduleStates[module.moduleKey].checking"
@click="runCheck(module.moduleKey as ApiSecretModuleKey)"
>
{{ moduleStates[module.moduleKey].checking ? '检测中...' : (moduleStates[module.moduleKey].input.trim() ? '检测输入值(未保存)' : '检测配置密钥') }}
</button>
<span class="check-result" :class="resultClassOf(module.moduleKey)">
{{ statusTextOf(module.moduleKey) }}
</span>
</div>
</section>
<section v-if="showProxy" class="secret-card">
<div class="secret-card-head">
<div class="secret-card-heading">
<div class="secret-card-title">
代理设置
<span class="source-tag">{{ proxyProviderLabel(proxyProvider) }}</span>
<span v-if="proxyLocked" class="lock-tag">后台锁定</span>
</div>
<div class="secret-card-desc">
{{ proxyLocked
? '代理由管理员统一配置并锁定,客户端不可修改或清空;如需变更请联系管理员。'
: (proxyProvider === 'qingguo'
? '青果用 Authkey / Authpwd 直连隧道代理,无需填写提取链接。'
: '供客户端任务连接代理服务,支持静态代理地址或代理服务商的提取链接。') }}
</div>
</div>
</div>
<div class="source-picker" role="radiogroup" aria-label="代理供应商">
<button
v-for="option in PROXY_PROVIDER_OPTIONS"
:key="option.key"
type="button"
role="radio"
:aria-checked="proxyProvider === option.key"
class="source-option"
:class="{ 'source-option--active': proxyProvider === option.key }"
:disabled="!proxyReady || busy || proxyLocked"
@click="selectProxyProvider(option.key)"
>
<span class="source-option-label">{{ option.label }}</span>
<span class="source-option-hint">{{ option.hint }}</span>
</button>
</div>
<div v-if="proxyProvider !== 'qingguo'" class="proxy-field">
<label class="field-label" for="proxy-url">代理地址</label>
<input
id="proxy-url"
v-model="proxyUrl"
class="secret-input"
type="text"
:placeholder="proxyPlaceholder"
autocomplete="off"
spellcheck="false"
:disabled="!proxyReady || busy || proxyLocked"
@input="proxyDirty = true"
/>
</div>
<div v-if="proxyReady && proxyProvider === 'qingguo'" class="retention-block">
<div class="field-label">隧道代理账号(青果 Authkey / Authpwd)</div>
<div class="proxy-plan-row">
<input
v-model="proxyAccount"
class="secret-input"
type="text"
placeholder="Authkey,如 40F79A90"
autocomplete="off"
spellcheck="false"
:disabled="busy || proxyLocked"
@input="proxyDirty = true"
/>
<input
v-model="proxyPassword"
class="secret-input"
type="password"
placeholder="Authpwd"
autocomplete="off"
spellcheck="false"
:disabled="busy || proxyLocked"
@input="proxyDirty = true"
/>
</div>
<div class="proxy-plan-hint">
青果没有可填的提取链接:保存时用 Authkey / Authpwd 自动拼出
<code>overseas.proxy.qg.net/get?key=…&amp;format=json</code>(Basic 认证也带在同一条链接里),
本地与后台密钥各存一份。服务端的商标检测用的就是这条链接,不填账密它会按「未配置代理」拦下任务。
</div>
</div>
<div v-if="proxySupported && proxyProvider === 'jikip'" class="retention-block">
<div class="field-label">jikip 套餐信息(余量查询)
</div>
<div class="proxy-plan-row">
<input
v-model="proxyPlanId"
class="secret-input"
type="text"
placeholder="套餐 ID"
autocomplete="off"
spellcheck="false"
:disabled="proxyPlanLoading || proxyPlanSaving"
/>
<input
v-model="proxyPlanUserId"
class="secret-input"
type="text"
placeholder="用户 ID"
autocomplete="off"
spellcheck="false"
:disabled="proxyPlanLoading || proxyPlanSaving"
/>
</div>
<div class="proxy-plan-row proxy-plan-row--single">
<input
v-model="proxyPlanKey"
class="secret-input"
type="password"
:placeholder="proxyPlanKeyPlaceholder"
autocomplete="off"
spellcheck="false"
:disabled="proxyPlanLoading || proxyPlanSaving"
/>
</div>
<div class="secret-actions">
<button
type="button"
class="check-btn"
:disabled="proxyPlanLoading || proxyPlanSaving"
@click="saveProxyPlanInfo"
>
{{ proxyPlanSaving ? '保存中...' : '保存套餐信息' }}
</button>
<button
v-if="proxyPlanConfigured"
type="button"
class="link-danger"
:disabled="proxyPlanSaving"
@click="clearProxyPlanInfo"
>
清除
</button>
</div>
<div class="proxy-plan-hint">
填写后,下方余量按你自己的 jikip 套餐查询;套餐 key 保存后只显示掩码,留空保存则保留已存值。套餐 ID / 用户 ID / key 在 jikip 后台「我的套餐」「账户信息」「套餐列表」查看。
</div>
</div>
<div v-else-if="proxySupported && proxyProvider === 'qingguo'" class="proxy-plan-hint">
青果的账户余量与通道用量请到青果后台查看;本客户端目前只做青果提取链接的连通性检测。
</div>
<div class="secret-actions">
<button
type="button"
class="check-btn"
:disabled="!proxyReady || busy || proxyChecking || proxyProvider === 'qingguo'"
@click="runProxyCheck"
>
{{ proxyChecking
? '检测中...'
: (proxyProvider === 'qingguo'
? '青果账密直连,无需检测'
: (proxyUrl.trim() && proxyDirty ? '检测输入地址(未保存)' : '检测配置代理')) }}
</button>
<span class="check-result" :class="proxyResultClass">
{{ proxyStatusText }}
</span>
</div>
<div class="secret-meta">
<span v-if="proxyLoading">正在读取代理配置...</span>
<span v-else-if="proxyLoadFailed">代理配置读取失败,请关闭弹窗后重试</span>
<span v-else-if="!proxySupported">代理设置仅在桌面客户端中可用</span>
<span v-else-if="proxyProvider === 'qingguo'">供应商:青果 · 提取链接示例 https://overseas.proxy.qg.net/get?key=...&format=json</span>
<span v-else-if="balanceLoading">正在查询代理余量...</span>
<span v-else-if="balance">{{ balanceText }}</span>
<span v-else>余额查询暂不可用</span>
</div>
</section>
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
import { ElMessage } from 'element-plus'
import {
checkApiSecret,
clearApiSecret,
getServerProxySnapshot,
getStoredApiSecretSnapshot,
listApiSecretModules,
loadApiSecrets,
saveApiSecret,
subscribeApiSecrets,
type ApiSecretModuleKey,
type ApiSecretSnapshot,
type ServerProxySnapshot,
type UserApiSecretCheckResult,
} from '@/shared/utils/api-secret-store'
import {
DEFAULT_LLM_CHANNEL,
DEFAULT_PROXY_PROVIDER,
LLM_CHANNEL_OPTIONS,
PROXY_PROVIDER_OPTIONS,
llmChannelLabel,
normalizeLlmChannel,
normalizeProxyProvider,
proxyProviderLabel,
type LlmChannelKey,
type ProxyProviderKey,
} from '@/shared/utils/api-secret-channel'
import { getPywebviewApi, type ProxyMode, type DesktopConfigUpdate } from '@/shared/bridges/pywebview'
import {
deleteMyApiSecret,
putMyApiSecret,
} from '@/shared/api/types/modules/user-secret'
import {
composeQingguoLink,
proxyUserId,
readUserProxy,
userProxyPatch,
} from '@/shared/utils/api-secret-proxy-config'
import { useProxyBalance, useProxyPlan } from '@/shared/composables/useProxyPlan'
import { createModuleView, type ModuleState } from '@/shared/utils/api-secret-module-view'
const props = withDefaults(
defineProps<{
/** 是否展示代理设置区(默认展示)。 */
showProxy?: boolean
}>(),
{
showProxy: true,
},
)
const modules = ref(listApiSecretModules())
const moduleStates = reactive<Record<string, ModuleState>>({})
/** 每个模块当前选择的渠道:默认龙抬头,加载后以服务端已存值为准。 */
const moduleChannels = reactive<Record<string, LlmChannelKey>>({})
/** 用户手动切过渠道、但还没为这个渠道填写密钥:保存前必须拦住(两家密钥不通用)。 */
const channelDirty = reactive<Record<string, boolean>>({})
// 首次渲染即需可读:按模块清单预初始化状态(后续 refreshSnapshots 兜底补齐)
for (const module of modules.value) {
moduleStates[module.moduleKey] = { input: '', checking: false, result: null, error: '', lastCheckSource: '' }
moduleChannels[module.moduleKey] = DEFAULT_LLM_CHANNEL
channelDirty[module.moduleKey] = false
}
const snapshots = ref<Record<string, ApiSecretSnapshot>>({})
const busy = ref(false)
/** 服务端代理状态:后台代填并锁定时客户端只读。 */
const serverProxy = ref<ServerProxySnapshot | null>(getServerProxySnapshot())
const proxyLocked = computed(() => Boolean(serverProxy.value?.locked && serverProxy.value?.exists))
const proxyUrl = ref('')
const proxyMode = ref<ProxyMode>(1)
const proxyProvider = ref<ProxyProviderKey>(DEFAULT_PROXY_PROVIDER)
/** 青果隧道端点的代理账密(Authkey/Authpwd):只存本机 app.json,不上报服务端。 */
const proxyAccount = ref('')
const proxyPassword = ref('')
const proxyLoading = ref(false)
const proxyLoadFailed = ref(false)
const proxyReady = ref(false)
const proxySupported = ref(false)
const proxyDirty = ref(false)
const proxyChecking = ref(false)
const proxyCheckResult = ref<UserApiSecretCheckResult | null>(null)
const proxyCheckError = ref('')
const { balance, balanceLoading, balanceText, loadBalance } = useProxyBalance({ proxyProvider })
const {
proxyPlanId,
proxyPlanUserId,
proxyPlanKey,
proxyPlanKeyConfigured,
proxyPlanKeyMasked,
proxyPlanConfigured,
proxyPlanLoading,
proxyPlanSaving,
proxyPlanKeyPlaceholder,
loadProxyPlan,
saveProxyPlanInfo,
clearProxyPlanInfo,
} = useProxyPlan({ proxyProvider, resetWhitelistStatus: () => {}, loadBalance })
const proxyPlaceholder = 'https://api.jikip.com/ip-get?num=1&minute=3&key=... 或 http://user:pass@host:port'
const proxyStatusText = computed(() => {
if (proxyChecking.value) return '正在检测...'
if (proxyCheckResult.value) {
const latency = proxyCheckResult.value.checkLatencyMs != null ? `(${proxyCheckResult.value.checkLatencyMs}ms)` : ''
if (proxyCheckResult.value.checkStatus === 'passed') return `代理连通正常${latency}`
return `${proxyCheckResult.value.checkMessage || '代理检测失败'}`
}
if (proxyCheckError.value) return proxyCheckError.value
return ''
})
const proxyResultClass = computed(() => {
const status = proxyCheckResult.value?.checkStatus
return {
'check-result--ok': status === 'passed',
'check-result--fail': status === 'failed',
'check-result--warn': status === 'error',
}
})
/** 切换代理供应商:只改本地选择,保存时与地址一起写入(检测也会按新供应商解析响应)。 */
function selectProxyProvider(provider: ProxyProviderKey) {
if (proxyProvider.value === provider) return
proxyProvider.value = provider
// 青果只支持账号密码直连,模式随供应商锁死;切回极客再让用户自选
if (provider === 'qingguo') proxyMode.value = 2
proxyDirty.value = true
proxyCheckResult.value = null
proxyCheckError.value = ''
}
/** 检测代理连通性:地址有改动时检测输入值(不落库),否则检测/落库已存值并刷新状态展示。 */
async function runProxyCheck() {
if (proxyChecking.value) return
const inputValue = proxyUrl.value.trim()
const dirty = proxyDirty.value && inputValue
proxyChecking.value = true
proxyCheckError.value = ''
proxyCheckResult.value = null
try {
// 供应商一起提交:检测要按对应供应商解析提取响应(青果/极客返回体不同)
proxyCheckResult.value = await checkApiSecret('proxy', dirty ? inputValue : undefined, proxyProvider.value)
const result = proxyCheckResult.value
if (result.checkStatus === 'failed') {
ElMessage.warning(
result.checkCode === 'insufficient_balance' ? '代理服务商余额不足,请充值或联系管理员' : (result.checkMessage || '代理不可用'),
)
} else if (result.checkStatus === 'error') {
ElMessage.warning(result.checkMessage || '暂时无法判定代理可用性')
} else {
ElMessage.success(dirty ? '输入地址连通正常(未保存)' : '代理连通正常')
}
} catch (error) {
proxyCheckError.value = error instanceof Error ? error.message : '代理检测失败'
ElMessage.error(proxyCheckError.value)
} finally {
proxyChecking.value = false
}
}
function ensureModuleState(moduleKey: string) {
if (!moduleStates[moduleKey]) {
moduleStates[moduleKey] = { input: '', checking: false, result: null, error: '', lastCheckSource: '' }
}
if (!moduleChannels[moduleKey]) {
moduleChannels[moduleKey] = DEFAULT_LLM_CHANNEL
}
return moduleStates[moduleKey]
}
/** 用户切换渠道:只改选择,保存时随密钥一起提交;已有密钥但没重新填写时给出提示。 */
function selectChannel(moduleKey: string, channel: LlmChannelKey) {
if (moduleChannels[moduleKey] === channel) return
moduleChannels[moduleKey] = channel
channelDirty[moduleKey] = true
}
/** 切到新渠道但没填新密钥(且已有旧渠道密钥):保存前必须拦住。 */
function channelSwitchNeedsValue(moduleKey: string) {
return Boolean(channelDirty[moduleKey]) && !ensureModuleState(moduleKey).input.trim() && snapshotOf(moduleKey).exists
}
function refreshSnapshots() {
modules.value = listApiSecretModules()
const next: Record<string, ApiSecretSnapshot> = {}
for (const module of modules.value) {
next[module.moduleKey] = getStoredApiSecretSnapshot(module.moduleKey as ApiSecretModuleKey)
ensureModuleState(module.moduleKey)
// 只在用户没主动切换过时跟服务端对齐,避免把手动选择回退掉
if (!channelDirty[module.moduleKey]) {
moduleChannels[module.moduleKey] = normalizeLlmChannel(next[module.moduleKey].channel)
}
}
snapshots.value = next
serverProxy.value = getServerProxySnapshot()
}
function snapshotOf(moduleKey: string): ApiSecretSnapshot {
return snapshots.value[moduleKey] || getStoredApiSecretSnapshot(moduleKey as ApiSecretModuleKey)
}
const { descriptionOf, placeholderOf, statusPillTextOf, statusPillClassOf, statusTextOf, resultClassOf } = createModuleView({
moduleChannels,
ensureModuleState,
snapshotOf,
})
async function runCheck(moduleKey: ApiSecretModuleKey) {
const state = ensureModuleState(moduleKey)
if (state.checking) return
state.checking = true
state.error = ''
state.result = null
const inputValue = state.input.trim()
state.lastCheckSource = inputValue ? 'input' : 'saved'
try {
// 不传 override 时服务端检测的是当前登录用户在密钥配置里保存的密钥(按 uid 绑定)
// 渠道一起提交:检测必须走所选渠道,否则「连通」是别的渠道的结论
const result = await checkApiSecret(moduleKey, inputValue || undefined, moduleChannels[moduleKey])
state.result = result
if (result.checkStatus === 'failed') {
ElMessage.warning(result.checkMessage || '密钥无效')
} else if (result.checkStatus === 'error') {
ElMessage.warning(result.checkMessage || '暂时无法判定密钥有效性')
} else {
ElMessage.success(inputValue ? '输入值检测通过(未保存)' : '配置密钥检测通过')
}
} catch (error) {
state.error = error instanceof Error ? error.message : '检测失败'
ElMessage.error(state.error)
} finally {
state.checking = false
refreshSnapshots()
}
}
async function clearModule(moduleKey: ApiSecretModuleKey) {
if (busy.value) return
busy.value = true
try {
await clearApiSecret(moduleKey)
const state = ensureModuleState(moduleKey)
state.input = ''
state.result = null
state.error = ''
channelDirty[moduleKey] = false
refreshSnapshots()
ElMessage.success('已清空密钥')
} catch (error) {
ElMessage.error(error instanceof Error ? error.message : '清空失败')
} finally {
busy.value = false
}
}
async function loadProxyConfig() {
proxyLoading.value = true
proxyLoadFailed.value = false
proxyReady.value = false
proxyDirty.value = false
const api = getPywebviewApi()
proxySupported.value = Boolean(api?.read_config && api?.save_config)
if (!api?.read_config || !api.save_config) {
proxyUrl.value = ''
proxyMode.value = 1
proxyLoading.value = false
return
}
try {
const config = await api.read_config()
const own = readUserProxy(config as Record<string, unknown>)
proxyUrl.value = own.url
proxyMode.value = (own.mode === 2 ? 2 : 1) as ProxyMode
proxyAccount.value = own.account
proxyPassword.value = own.password
// 本地配置是权威(客户端任务链读的就是它);本地没写过时才用服务端里记的供应商
proxyProvider.value = own.url
? own.provider
: normalizeProxyProvider(serverProxy.value?.channel ?? own.provider)
// 青果只走账密认证,历史配置若停在白名单也强制拉回账号密码
if (proxyProvider.value === 'qingguo') proxyMode.value = 2
proxyReady.value = true
} catch (error) {
proxyLoadFailed.value = true
ElMessage.error(error instanceof Error ? error.message : '代理配置读取失败')
} finally {
proxyLoading.value = false
}
}
/** 代理配置上报服务端(后台密钥管理观测/检测):有地址则保存、清空则删除;失败不阻断本地保存。 */
async function syncProxyToServer(url: string): Promise<boolean> {
if (proxyUserId() === '0') return false
try {
if (url) {
// 供应商随地址一起上报:服务端检测要按供应商解析提取响应
await putMyApiSecret('proxy', url, proxyProvider.value)
} else {
await deleteMyApiSecret('proxy')
}
return true
} catch (error) {
console.warn('[api-secret] 代理配置上报失败(不影响本地任务):', error)
ElMessage.warning('代理已保存到本地,但上报后台失败')
return false
}
}
/**
* 保存:逐模块保存非空输入(空输入保留服务端原值),代理仅在改动时保存。
* 检测一律由用户手动点击触发;保存时服务端会沿用「刚检测过的同一个输入值」的结果,
* 其余情况(改过值 / 从未检测)保持未检测,需用户点「检测」确认可用性。
*/
async function saveAll(options: { requireAll?: boolean } = {}): Promise<boolean> {
if (busy.value || proxyLoading.value) return false
// 切了渠道却只留着旧渠道的密钥:两家密钥不通用,必须让用户补填,否则保存后必然不可用
const needRefill = modules.value.filter((module) => channelSwitchNeedsValue(module.moduleKey))
if (needRefill.length) {
ElMessage.warning(
`已切换渠道,请填写该渠道的密钥:${needRefill.map((module) => module.moduleLabel).join('、')}`,
)
return false
}
const pendingModules = modules.value.filter((module) => ensureModuleState(module.moduleKey).input.trim())
if (options.requireAll) {
const missing = modules.value.filter(
(module) => !ensureModuleState(module.moduleKey).input.trim() && !snapshotOf(module.moduleKey).exists,
)
if (missing.length) {
ElMessage.warning(`请填写:${missing.map((module) => module.moduleLabel).join('、')}`)
return false
}
}
busy.value = true
let secretsSaved = false
try {
for (const module of pendingModules) {
const moduleKey = module.moduleKey as ApiSecretModuleKey
const state = ensureModuleState(module.moduleKey)
await saveApiSecret(moduleKey, state.input.trim(), moduleChannels[module.moduleKey])
state.input = ''
// 输入值已保存:本地那次「检测输入值」的结果不再代表当前配置,清掉后展示统一走服务端快照
// (保存前检测过的同一个值,服务端会沿用那次结果,快照里直接是「检测通过」)
state.result = null
state.lastCheckSource = ''
state.error = ''
channelDirty[module.moduleKey] = false
}
secretsSaved = true
refreshSnapshots()
if (props.showProxy && proxyReady.value && proxyDirty.value && !proxyLocked.value) {
const api = getPywebviewApi()
if (!api?.save_config) throw new Error('当前客户端未提供代理配置保存能力')
// 青果走账密直连隧道,不保存提取链接;切回极客时输入框里的旧值仍在
const tunnelMode = proxyProvider.value === 'qingguo'
// 青果没有提取链接可填:由 Authkey/Authpwd 拼出来(2026-10-31 用户拍板)。
// 本地与服务端用同一条链接——服务端商标检测(16890)只收得到 proxy_url,
// 拼空串等于用户填了账密却仍被判「未配置代理」。
const nextProxyUrl = tunnelMode
? composeQingguoLink(proxyAccount.value, proxyPassword.value)
: proxyUrl.value.trim()
const nextProxyMode = tunnelMode ? 2 : proxyMode.value
await api.save_config(
userProxyPatch(nextProxyUrl, nextProxyMode, proxyProvider.value, proxyAccount.value, proxyPassword.value) as DesktopConfigUpdate,
)
if (!tunnelMode) proxyUrl.value = nextProxyUrl
proxyDirty.value = false
// 同上:地址已保存,本地「未保存」的检测文案不再适用
proxyCheckResult.value = null
proxyCheckError.value = ''
await syncProxyToServer(nextProxyUrl)
void loadProxyPlan()
void loadBalance()
}
// 保存后不再自动检测:检测一律由用户手动点击「检测」触发
refreshSnapshots()
return true
} catch (error) {
const message = error instanceof Error ? error.message : '设置保存失败'
ElMessage.error(secretsSaved ? `密钥已保存,但后续步骤失败:${message}` : message)
return false
} finally {
busy.value = false
}
}
/** 重新从服务端拉取(设置页/弹窗打开时调用)。 */
async function reload() {
await loadApiSecrets({ force: true })
refreshSnapshots()
}
watch(proxyProvider, (provider) => {
// 切到极客时补拉套餐信息(含套餐 key 是否已配置)
if (provider === 'jikip' && proxySupported.value) {
void loadProxyPlan()
}
})
let unsubscribe: (() => void) | null = null
onMounted(() => {
refreshSnapshots()
unsubscribe = subscribeApiSecrets(refreshSnapshots)
// 先拉服务端密钥包(后台锁定的代理会先对齐到本地配置),再读本地代理,避免展示对齐前的旧值
void (async () => {
await reload()
if (props.showProxy) {
await loadProxyConfig()
if (proxySupported.value) {
void loadProxyPlan()
}
void loadBalance()
}
})()
})
onUnmounted(() => {
if (unsubscribe) unsubscribe()
})
defineExpose({ saveAll, reload })
</script>
<style scoped src="./api-secret-settings-panel.css"></style>