From 4c49f6a3b51b425e8787cc87c88004445f9474fd Mon Sep 17 00:00:00 2001 From: mrlee <470349233@qq.com> Date: Sun, 27 Sep 2026 18:14:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(web):=20DDNS=20=E9=A1=B5=E6=94=B9=E7=94=A8?= =?UTF-8?q?=20FRP=20=E5=A4=9A=E6=9C=8D=E5=8A=A1=E7=AB=AF=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ web/src/utils/frp.spec.ts | 20 ++++++++++++++++++++ web/src/utils/frp.ts | 6 ++++++ web/src/views/DdnsView.vue | 5 +++-- 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 web/src/utils/frp.spec.ts create mode 100644 web/src/utils/frp.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 75cee3f..fb40cbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. +## [Unreleased] + +### 修复 + +- **DDNS 页 FRP 提示恢复**:`DdnsView.vue` 原来调用已退役的 `/api/frp`,请求失败后会把 `frpEnabled` 固定为 `false`,导致“FRP 内网穿透已启用”提示不再出现。现改用 `/api/frpmulti/status`,仅在“已配置服务端且存在启用规则”时显示,并补充判定函数单元测试 + ## [v1.2.19] - 2026-09-27 ### 新增 diff --git a/web/src/utils/frp.spec.ts b/web/src/utils/frp.spec.ts new file mode 100644 index 0000000..b0fa238 --- /dev/null +++ b/web/src/utils/frp.spec.ts @@ -0,0 +1,20 @@ +import { describe, expect, it } from 'vitest' +import { shouldShowFrpHint } from './frp' + +describe('shouldShowFrpHint', () => { + it('配置了服务端且存在启用规则时显示提示', () => { + expect(shouldShowFrpHint({ configured: true, enabled_proxies: 1 })).toBe(true) + }) + + it('未配置服务端时不显示提示', () => { + expect(shouldShowFrpHint({ configured: false, enabled_proxies: 1 })).toBe(false) + }) + + it('配置了服务端但没有启用规则时不显示提示', () => { + expect(shouldShowFrpHint({ configured: true, enabled_proxies: 0 })).toBe(false) + }) + + it('状态为空时不显示提示', () => { + expect(shouldShowFrpHint(undefined)).toBe(false) + }) +}) diff --git a/web/src/utils/frp.ts b/web/src/utils/frp.ts new file mode 100644 index 0000000..d9c9c28 --- /dev/null +++ b/web/src/utils/frp.ts @@ -0,0 +1,6 @@ +import type { FrpStatus } from '../api/types' + +// 只有配置了 FRP 服务端且存在启用规则时,DDNS 页才提示域名应指向 VPS。 +export function shouldShowFrpHint(status: Pick | null | undefined): boolean { + return Boolean(status?.configured && status.enabled_proxies > 0) +} diff --git a/web/src/views/DdnsView.vue b/web/src/views/DdnsView.vue index 3efa741..c186ce3 100644 --- a/web/src/views/DdnsView.vue +++ b/web/src/views/DdnsView.vue @@ -518,6 +518,7 @@ import PageHeader from '../components/PageHeader.vue' import StatusBadge from '../components/StatusBadge.vue' import TaskProviderForm, { type ProviderForm } from '../components/TaskProviderForm.vue' import { formatDate, formatRelativeTime } from '../utils/format' +import { shouldShowFrpHint } from '../utils/frp' import { statusLabel } from '../utils/status' const DRAFT_KEY = '__draft__' @@ -929,8 +930,8 @@ async function init() { refreshPublicIP() refreshLiveDNS() try { - const frp = await api.getFRP() - frpEnabled.value = frp.enabled + const status = await api.getFrpStatus() + frpEnabled.value = shouldShowFrpHint(status) } catch { frpEnabled.value = false }