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
+2
View File
@@ -2,6 +2,7 @@
<el-config-provider :locale="zhCn">
<router-view />
<ExpiryNotice />
<ProxyBalanceAlert />
<ForceUpdateGate />
</el-config-provider>
</template>
@@ -16,6 +17,7 @@ import zhCn from 'element-plus/es/locale/lang/zh-cn'
import { onBeforeUnmount } from 'vue'
import ExpiryNotice from '@/shared/components/ExpiryNotice.vue'
import ForceUpdateGate from '@/shared/components/ForceUpdateGate.vue'
import ProxyBalanceAlert from '@/shared/components/ProxyBalanceAlert.vue'
import { disposeGlobalErrorGuard } from '@/shared/utils/app-error'
import { uninstallUserTokenSync } from '@/shared/auth/user-token-sync'
import { disposeDownloadProgressListener } from '@/shared/utils/download-progress'
+1
View File
@@ -205,6 +205,7 @@ export const API_ENDPOINTS = {
check: '/api/user-secrets/{moduleKey}/check',
migrate: '/api/user-secrets/migrate',
proxyBalance: '/api/user-secrets/proxy-balance',
proxyPlan: '/api/user-secrets/proxy-plan',
},
notification: {
summary: '/api/notifications/summary',
@@ -48,6 +48,18 @@ export interface UserApiSecretBalance {
surplus: string | null
balance: string | null
message: string | null
/** 余量来源:user=用户自己的套餐;platform=平台套餐 */
scope?: 'user' | 'platform' | string
/** 是否低于预警阈值(仅用户自己的套餐判定) */
low?: boolean
/** 低余量原因 */
lowReason?: string | null
}
export interface UserProxyPlan {
planId: string | null
jikipUserId: string | null
configured: boolean
}
export interface UserApiSecretMigrateItem {
@@ -103,3 +115,25 @@ export function fetchProxyBalance() {
get<JavaApiResponse<UserApiSecretBalance>>(buildJavaUrl(API_ENDPOINTS.userSecret.proxyBalance)),
)
}
/** 读取当前用户填写的 jikip 套餐 ID / 用户 ID(只用于余量查询)。 */
export function fetchProxyPlan() {
return unwrapJavaResponse(
get<JavaApiResponse<UserProxyPlan>>(buildJavaUrl(API_ENDPOINTS.userSecret.proxyPlan)),
)
}
export function saveProxyPlan(planId: string, jikipUserId: string) {
return unwrapJavaResponse(
put<JavaApiResponse<UserProxyPlan>, { planId: string; jikipUserId: string }>(
buildJavaUrl(API_ENDPOINTS.userSecret.proxyPlan),
{ planId, jikipUserId },
),
)
}
export function clearProxyPlan() {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(buildJavaUrl(API_ENDPOINTS.userSecret.proxyPlan)),
)
}
@@ -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;
}
@@ -0,0 +1,149 @@
<script setup lang="ts">
/**
* 代理套餐低余量常驻警告(2026-10-21 需求):
* 「如果欠费了就一直在客户端右上角有个弹窗警告」。
*
* - 只报警用户自己在「设置 → 代理设置」填的 jikip 套餐,平台套餐的告警在管理员侧;
* - 无关闭按钮:充值到账/余量恢复后由下一轮轮询自动收起,避免用户点掉后再也看不见;
* - 先查套餐配置再查余量:没配套餐的用户根本不打供应商接口,轮询成本接近零。
*/
import { onBeforeUnmount, onMounted, ref } from 'vue'
import { fetchProxyPlan } from '@/shared/api/types/modules/user-secret'
import { AUTH_TOKEN_KEY } from '@/shared/auth/session-keys'
import { fetchProxyBalanceSafely } from '@/shared/utils/api-secret-store'
import {
PROXY_BALANCE_POLL_MS,
PROXY_PLAN_CHANGED_EVENT,
proxyBalanceWarningReason,
} from '@/shared/utils/proxy-balance-alert'
const warning = ref('')
let timer: number | null = null
let inflight = false
let disposed = false
function hasLoginToken(): boolean {
if (typeof window === 'undefined') return false
return Boolean(window.localStorage.getItem(AUTH_TOKEN_KEY))
}
async function refresh(): Promise<void> {
if (disposed || inflight) return
if (!hasLoginToken()) {
warning.value = ''
return
}
inflight = true
try {
// 查不出来不等于欠费:失败只记日志、保留上一轮状态,下一轮再试,避免网络抖动刷出误报
const plan = await fetchProxyPlan().catch((error) => {
console.warn('[proxy-balance-alert] 套餐配置读取失败,本轮不提示:', error)
return null
})
if (plan === null) return
if (!plan?.configured) {
warning.value = ''
return
}
const balance = await fetchProxyBalanceSafely().catch((error) => {
console.warn('[proxy-balance-alert] 余量查询失败,本轮不提示:', error)
return null
})
if (balance === null || disposed) return
warning.value = proxyBalanceWarningReason(balance)
} finally {
inflight = false
}
}
function refreshWhenVisible(): void {
if (typeof document !== 'undefined' && document.visibilityState === 'hidden') return
void refresh()
}
onMounted(() => {
void refresh()
timer = window.setInterval(() => void refresh(), PROXY_BALANCE_POLL_MS)
window.addEventListener('focus', refreshWhenVisible)
window.addEventListener(PROXY_PLAN_CHANGED_EVENT, refreshWhenVisible)
document.addEventListener('visibilitychange', refreshWhenVisible)
})
onBeforeUnmount(() => {
disposed = true
if (timer !== null) window.clearInterval(timer)
window.removeEventListener('focus', refreshWhenVisible)
window.removeEventListener(PROXY_PLAN_CHANGED_EVENT, refreshWhenVisible)
document.removeEventListener('visibilitychange', refreshWhenVisible)
})
</script>
<template>
<div v-if="warning" class="proxy-balance-alert" role="alert" aria-live="assertive">
<div class="proxy-balance-alert-icon" aria-hidden="true">!</div>
<div class="proxy-balance-alert-content">
<div class="proxy-balance-alert-title">代理套餐余额不足</div>
<div class="proxy-balance-alert-reason">{{ warning }}</div>
<div class="proxy-balance-alert-hint">
请尽快到 jikip 后台充值;充值到账后本提示会自动消失。套餐信息可在「密钥设置 → 代理设置」中更新。
</div>
</div>
</div>
</template>
<style scoped>
.proxy-balance-alert {
position: fixed;
top: 68px;
right: 16px;
z-index: 3000;
display: flex;
align-items: flex-start;
gap: 10px;
width: 360px;
max-width: calc(100vw - 32px);
padding: 14px 16px;
box-sizing: border-box;
border: 1px solid #e0a13c;
border-radius: 12px;
background: #fff8e8;
color: #7a4a06;
box-shadow: 0 14px 36px -18px rgba(122, 74, 6, 0.6);
}
.proxy-balance-alert-icon {
flex-shrink: 0;
width: 22px;
height: 22px;
border-radius: 50%;
background: #e0a13c;
color: #ffffff;
font-size: 14px;
font-weight: 800;
line-height: 22px;
text-align: center;
}
.proxy-balance-alert-content {
display: flex;
flex-direction: column;
gap: 4px;
min-width: 0;
}
.proxy-balance-alert-title {
font-size: 14px;
font-weight: 700;
}
.proxy-balance-alert-reason {
font-size: 13px;
line-height: 1.5;
}
.proxy-balance-alert-hint {
color: #9a6a21;
font-size: 12px;
line-height: 1.5;
}
</style>
@@ -0,0 +1,23 @@
/**
* 客户端右上角代理余量警告的判定口径(纯函数,便于单测)。
*
* 只对「用户自己填的 jikip 套餐」报警:平台套餐由管理员侧巡检负责,
* 普通用户看到平台余量只会困惑,而且每个客户端都去查平台套餐只会白打供应商接口。
*/
import type { UserApiSecretBalance } from '../api/types/modules/user-secret.ts'
/** 轮询间隔:余量变化不需要秒级感知,10 分钟一轮即可。 */
export const PROXY_BALANCE_POLL_MS = 10 * 60 * 1000
/** 设置面板保存/清除套餐后广播,右上角警告立即按新配置刷新,不用等下一轮轮询。 */
export const PROXY_PLAN_CHANGED_EVENT = 'proxy-plan-changed'
/** 低余量兜底文案:服务端 lowReason 为空时仍要让用户看懂该做什么。 */
export const PROXY_BALANCE_FALLBACK_REASON = '代理套餐余额不足,耗尽后相关任务将无法购买代理。'
/** 返回需要常驻展示的警告文案;空串表示不展示。 */
export function proxyBalanceWarningReason(balance: UserApiSecretBalance | null | undefined): string {
if (!balance || balance.available === false) return ''
if (balance.scope !== 'user' || balance.low !== true) return ''
return (balance.lowReason || '').trim() || PROXY_BALANCE_FALLBACK_REASON
}
+2 -1
View File
@@ -312,7 +312,8 @@ test('test_endpoints_frozen_snapshot', () => {
"clear": "/api/user-secrets/{moduleKey}",
"check": "/api/user-secrets/{moduleKey}/check",
"migrate": "/api/user-secrets/migrate",
"proxyBalance": "/api/user-secrets/proxy-balance"
"proxyBalance": "/api/user-secrets/proxy-balance",
"proxyPlan": "/api/user-secrets/proxy-plan"
},
"notification": {
"summary": "/api/notifications/summary",
@@ -0,0 +1,141 @@
/**
* 代理套餐低余量常驻警告的组件挂载用例:判的是运行时行为,不是读源码形状。
*
* 需求原话:「如果欠费了就一直在客户端右上角有个弹窗警告」。
* 三组靶子:
* ① 用户自己的套餐 low=true 时,右上角必须出现警告且文案带原因;
* ② 未配套餐/余量恢复/查询失败时不许误弹,恢复后由轮询自动收起;
* ③ 失败不能把上一轮的警告清掉(网络抖一下不该骗用户说欠费已解决)。
*
* 跑法:`npx vitest run tests/mount/proxy-balance-alert.mount.test.ts`
*/
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import ProxyBalanceAlert from '@/shared/components/ProxyBalanceAlert.vue'
import { AUTH_TOKEN_KEY } from '@/shared/auth/session-keys'
import { PROXY_PLAN_CHANGED_EVENT } from '@/shared/utils/proxy-balance-alert'
const api = vi.hoisted(() => ({
fetchProxyPlan: vi.fn(),
fetchProxyBalanceSafely: vi.fn(),
}))
vi.mock('@/shared/api/types/modules/user-secret', () => ({
fetchProxyPlan: api.fetchProxyPlan,
}))
vi.mock('@/shared/utils/api-secret-store', () => ({
fetchProxyBalanceSafely: api.fetchProxyBalanceSafely,
}))
let wrapper: VueWrapper | null = null
function plan(configured: boolean) {
return {
planId: configured ? '20261010593613392231' : null,
jikipUserId: configured ? '626710989815' : null,
configured,
}
}
function balance(over: Record<string, unknown> = {}) {
return {
available: true,
surplus: null,
balance: '10',
message: null,
scope: 'user',
low: true,
lowReason: '账户余额已耗尽',
...over,
}
}
async function mountAlert() {
localStorage.setItem(AUTH_TOKEN_KEY, 'token')
wrapper = mount(ProxyBalanceAlert)
await flushPromises()
return wrapper
}
beforeEach(() => {
localStorage.clear()
api.fetchProxyPlan.mockReset()
api.fetchProxyBalanceSafely.mockReset()
vi.spyOn(console, 'warn').mockImplementation(() => {})
})
afterEach(() => {
wrapper?.unmount()
wrapper = null
vi.restoreAllMocks()
})
describe('ProxyBalanceAlert:低余量常驻警告', () => {
it('用户自己的套餐低余量:右上角常驻警告,文案带服务端给的原因', async () => {
api.fetchProxyPlan.mockResolvedValue(plan(true))
api.fetchProxyBalanceSafely.mockResolvedValue(balance())
await mountAlert()
const alert = wrapper!.find('.proxy-balance-alert')
expect(alert.exists()).toBe(true)
expect(alert.text()).toContain('代理套餐余额不足')
expect(alert.text()).toContain('账户余额已耗尽')
// 没有关闭件:用户点不掉,只能等充值后自动收起
expect(alert.find('button').exists()).toBe(false)
})
it('没配套餐:直接收起且一次都不查余量,不白打供应商接口', async () => {
api.fetchProxyPlan.mockResolvedValue(plan(false))
await mountAlert()
expect(wrapper!.find('.proxy-balance-alert').exists()).toBe(false)
expect(api.fetchProxyBalanceSafely).not.toHaveBeenCalled()
})
it('平台套餐/未低余量:普通用户不该看到平台侧的告警', async () => {
api.fetchProxyPlan.mockResolvedValue(plan(true))
api.fetchProxyBalanceSafely.mockResolvedValue(balance({ scope: 'platform', low: true }))
await mountAlert()
expect(wrapper!.find('.proxy-balance-alert').exists()).toBe(false)
})
it('余量恢复后回到前台立即刷新:警告自动消失,无需用户手动关闭', async () => {
api.fetchProxyPlan.mockResolvedValue(plan(true))
api.fetchProxyBalanceSafely.mockResolvedValue(balance())
await mountAlert()
expect(wrapper!.find('.proxy-balance-alert').exists()).toBe(true)
api.fetchProxyBalanceSafely.mockResolvedValue(balance({ low: false, lowReason: null }))
window.dispatchEvent(new Event('focus'))
await flushPromises()
expect(wrapper!.find('.proxy-balance-alert').exists()).toBe(false)
})
it('设置面板保存套餐后广播事件:警告立即按新配置刷新,不用等下一轮轮询', async () => {
api.fetchProxyPlan.mockResolvedValue(plan(false))
await mountAlert()
expect(wrapper!.find('.proxy-balance-alert').exists()).toBe(false)
api.fetchProxyPlan.mockResolvedValue(plan(true))
api.fetchProxyBalanceSafely.mockResolvedValue(balance())
window.dispatchEvent(new Event(PROXY_PLAN_CHANGED_EVENT))
await flushPromises()
expect(wrapper!.find('.proxy-balance-alert').exists()).toBe(true)
})
it('查询失败不清掉已有警告:网络抖动不能骗用户说欠费已解决', async () => {
api.fetchProxyPlan.mockResolvedValue(plan(true))
api.fetchProxyBalanceSafely.mockResolvedValue(balance())
await mountAlert()
api.fetchProxyBalanceSafely.mockRejectedValue(new Error('502 Bad Gateway'))
window.dispatchEvent(new Event('focus'))
await flushPromises()
expect(wrapper!.find('.proxy-balance-alert').exists()).toBe(true)
})
})
@@ -0,0 +1,99 @@
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { join } from 'node:path'
/**
* 客户端右上角代理余量常驻警告(2026-10-21 需求):
* 「如果欠费了就一直在客户端右上角有个弹窗警告」。
*
* 分两层钉:
* ① 行为层:warning 判定必须只认「用户自己的套餐 + low」,平台套餐/查询失败一律不弹;
* ② 源码层:只查用户套餐、定时轮询、无关闭件、挂在 App.vue——缺一条就是静默不弹或误报。
*/
const COMPONENT = 'src/shared/components/ProxyBalanceAlert.vue'
const APP = 'src/App.vue'
function read(rel: string): string {
return readFileSync(join(process.cwd(), rel), 'utf8')
}
function occurrences(text: string, token: string): number {
if (!token) return 0
let count = 0
let index = text.indexOf(token)
while (index !== -1) {
count += 1
index = text.indexOf(token, index + token.length)
}
return count
}
const source = read(COMPONENT)
const template = source.slice(source.indexOf('<template>'), source.lastIndexOf('</template>'))
const script = source.slice(source.indexOf('<script setup'), source.indexOf('</script>'))
test('判定口径:只有用户自己的套餐 low=true 才弹,平台套餐/未低/查询失败都不弹', async () => {
const { proxyBalanceWarningReason, PROXY_BALANCE_FALLBACK_REASON } =
await import('../src/shared/utils/proxy-balance-alert.ts')
assert.equal(
proxyBalanceWarningReason({ available: true, scope: 'user', low: true, lowReason: '账户余额已耗尽' } as never),
'账户余额已耗尽',
)
assert.equal(
proxyBalanceWarningReason({ available: true, scope: 'user', low: true, lowReason: ' ' } as never),
PROXY_BALANCE_FALLBACK_REASON,
'服务端没给原因时也要有兜底文案,不能弹一个空壳',
)
for (const balance of [
null,
undefined,
{ available: false, scope: 'user', low: true, lowReason: '账户余额已耗尽' },
{ available: true, scope: 'platform', low: true, lowReason: '平台套餐不足' },
{ available: true, scope: 'user', low: false, lowReason: null },
{ available: true, scope: 'user', low: null, lowReason: '账户余额已耗尽' },
]) {
assert.equal(proxyBalanceWarningReason(balance as never), '', `不该弹:${JSON.stringify(balance)}`)
}
})
test('先查套餐配置再查余量:没填套餐的用户不白打供应商接口', () => {
const planIndex = script.indexOf('await fetchProxyPlan()')
const balanceIndex = script.indexOf('await fetchProxyBalanceSafely()')
assert.ok(planIndex !== -1, '没读用户套餐配置')
assert.ok(balanceIndex !== -1, '没查代理余量')
assert.ok(planIndex < balanceIndex, '必须先确认 configured 再查余量')
assert.match(script, /if \(!plan\?\.configured\)/, '没配套餐时必须直接收起警告')
})
test('页面常开也会更新:10 分钟轮询 + 回到前台立即刷新,卸载清计时器与监听', () => {
assert.match(script, /window\.setInterval\(\(\) => void refresh\(\), PROXY_BALANCE_POLL_MS\)/, '没有按固定间隔轮询')
assert.match(script, /document\.addEventListener\('visibilitychange', refreshWhenVisible\)/, '回到前台没刷新')
assert.match(script, /window\.addEventListener\('focus', refreshWhenVisible\)/, '窗口获得焦点没刷新')
assert.match(script, /window\.clearInterval\(timer\)/, '卸载没清计时器')
assert.match(script, /document\.removeEventListener\('visibilitychange', refreshWhenVisible\)/, '卸载没摘监听')
assert.equal(occurrences(script, 'warning.value ='), 3, '只允许登录态/未配置/查询结果三处赋值,失败分支不得赋值')
})
test('只能自动消失不能手动关闭:模板里没有任何可点项或关闭开关', () => {
assert.equal(occurrences(template, '<button'), 0, '常驻警告不放关闭按钮')
assert.equal(occurrences(template, '@click'), 0, '没有任何点击交互')
assert.equal(occurrences(source, 'el-dialog'), 0, '对话框会带来关闭件')
assert.doesNotMatch(source, /show-close|close-on-click-modal|close-on-press-escape|:closable/, '存在关闭开关')
})
test('位置在右上角且避开 56px 顶栏,余量恢复后由轮询自动收起', () => {
assert.match(source, /position: fixed;/, '必须是全局浮层')
assert.match(source, /top: 68px;/, '要落在顶栏下方,不能盖住铃铛/用户菜单')
assert.match(source, /right: 16px;/, '必须在右上角')
assert.match(template, /v-if="warning"/, '没有内容时不该占位渲染')
})
test('挂在 App.vue:桌面壳与网页共用同一个根组件,不挂就整站看不见', () => {
const app = read(APP).replace(/<!--[\s\S]*?-->/g, '')
assert.match(app, /import ProxyBalanceAlert from '@\/shared\/components\/ProxyBalanceAlert\.vue'/, 'App.vue 没引组件')
assert.match(app, /<ProxyBalanceAlert\s*\/>/, 'App.vue 没渲染组件(注释掉等于没挂)')
})