feat(代理): 多套餐余量预警与用户级 jikip 套餐配置

平台自费池由单个 planId/userId 改为 planId:userId 列表逐套餐探测,
套餐余量或账户余额低于阈值时推管理员预警;用户可在密钥设置里为自己
配置多个套餐,巡检跟随密钥检查按用户查余量并推站内通知,欠费状态在
客户端右上角常驻提示(V160 新建用户级套餐表)。

同时把测试里写死的真实代理 key 换成占位串,避免凭证随仓库扩散。
This commit is contained in:
2026-10-21 13:32:56 +08:00
parent 19a291ec39
commit f6aa04d0f2
31 changed files with 1544 additions and 52 deletions
@@ -93,6 +93,52 @@
</div>
</div>
<div v-if="proxySupported" 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="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 套餐查询;留空则显示平台默认套餐。套餐 ID / 用户 ID 在 jikip 后台「我的套餐」和「账户信息」查看。
</div>
</div>
<div class="secret-actions">
<button
type="button"
@@ -139,7 +185,8 @@ import {
type UserApiSecretCheckResult,
} from '@/shared/utils/api-secret-store'
import { getPywebviewApi, type ProxyMode, type DesktopConfigUpdate } from '@/shared/bridges/pywebview'
import { deleteMyApiSecret, putMyApiSecret } from '@/shared/api/types/modules/user-secret'
import { deleteMyApiSecret, putMyApiSecret, fetchProxyPlan, saveProxyPlan, clearProxyPlan } from '@/shared/api/types/modules/user-secret'
import { PROXY_PLAN_CHANGED_EVENT } from '@/shared/utils/proxy-balance-alert'
const props = withDefaults(
defineProps<{
@@ -185,6 +232,12 @@ const proxyChecking = ref(false)
const proxyCheckResult = ref<UserApiSecretCheckResult | null>(null)
const proxyCheckError = ref('')
const proxyPlanId = ref('')
const proxyPlanUserId = ref('')
const proxyPlanConfigured = ref(false)
const proxyPlanLoading = ref(false)
const proxyPlanSaving = ref(false)
const proxyStatusText = computed(() => {
if (proxyChecking.value) return '正在检测...'
if (proxyCheckResult.value) {
@@ -460,6 +513,65 @@ async function syncProxyToServer(url: string) {
}
}
async function loadProxyPlan() {
proxyPlanLoading.value = true
try {
const result = await fetchProxyPlan().catch((error) => {
console.warn('[api-secret] 代理套餐配置读取失败:', error)
return null
})
if (!result) return
proxyPlanId.value = result.planId || ''
proxyPlanUserId.value = result.jikipUserId || ''
proxyPlanConfigured.value = Boolean(result.configured)
} finally {
proxyPlanLoading.value = false
}
}
async function saveProxyPlanInfo() {
const planId = proxyPlanId.value.trim()
const jikipUserId = proxyPlanUserId.value.trim()
if (!planId || !jikipUserId) {
ElMessage.warning('请同时填写套餐 ID 和用户 ID')
return
}
proxyPlanSaving.value = true
try {
const result = await saveProxyPlan(planId, jikipUserId).catch((error) => {
ElMessage.error(error instanceof Error ? error.message : '套餐信息保存失败')
return null
})
if (!result) return
proxyPlanConfigured.value = Boolean(result.configured)
ElMessage.success('套餐信息已保存,余量将按你的套餐查询')
window.dispatchEvent(new Event(PROXY_PLAN_CHANGED_EVENT))
await loadBalance()
} finally {
proxyPlanSaving.value = false
}
}
async function clearProxyPlanInfo() {
if (proxyPlanSaving.value) return
proxyPlanSaving.value = true
try {
const cleared = await clearProxyPlan().then(() => true).catch((error) => {
ElMessage.error(error instanceof Error ? error.message : '套餐信息清除失败')
return false
})
if (!cleared) return
proxyPlanId.value = ''
proxyPlanUserId.value = ''
proxyPlanConfigured.value = false
ElMessage.success('已清除套餐信息,余量恢复为平台默认套餐')
window.dispatchEvent(new Event(PROXY_PLAN_CHANGED_EVENT))
await loadBalance()
} finally {
proxyPlanSaving.value = false
}
}
async function loadBalance() {
balanceLoading.value = true
try {
@@ -552,7 +664,10 @@ onMounted(() => {
void (async () => {
await reload()
if (props.showProxy) {
void loadProxyConfig()
await loadProxyConfig()
if (proxySupported.value) {
void loadProxyPlan()
}
void loadBalance()
}
})()
@@ -692,6 +807,19 @@ defineExpose({ saveAll, reload })
display: block;
}
.proxy-plan-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.proxy-plan-hint {
margin-top: 8px;
color: #7f8a96;
font-size: 12px;
line-height: 1.5;
}
.retention-block {
margin-top: 12px;
}