From ea8489cd41999cf3da2d5b4db46cc67f3db50f3e Mon Sep 17 00:00:00 2001 From: alfadb Date: Sun, 13 Sep 2026 05:19:02 +0800 Subject: [PATCH] fix(admin): mirror the full quota platform list in the frontend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 后端对 default_platform_quotas(setting_update.go)与用户平台配额 (user_handler.go PUT)都是整体替换语义,且以 AllowedQuotaPlatforms (11 平台)为白名单。前端配额平台镜像此前只硬编码 5 平台 (anthropic/openai/gemini/antigravity/grok),导致: - 保存 Settings 会静默丢弃 kimi/zhipu/deepseek/minimax/opencode_go/ ollama_cloud 六个平台的默认配额; - 管理员在用户配额弹窗不做修改直接保存,就会软删该用户经 API 配置的 ollama_cloud 等平台配额行(缺行等价于不限额 → 限额 fail-open)。 - settings.ts 新增单一常量 QUOTA_PLATFORMS(对齐后端 AllowedQuotaPlatforms 全部 11 平台),PlatformType/PlatformQuotaPlatform 由它派生,删除其余 5 平台硬编码副本(users.ts、配额弹窗、 UserPlatformQuotaCell、SettingsView 两处模板字面量); - normalizePlatformQuotasMap / sanitizePlatformQuotasMap 保留输入中 前端未知(后端新加)的平台 key;用户配额弹窗保留响应中的未知平台行, 避免后端先行加平台时再次静默删数据; - 测试:用户配额弹窗预置 ollama_cloud 不修改直接保存仍包含该配额; Settings 同路径覆盖;kimi/zhipu/deepseek/minimax/opencode_go 不再 被丢;未知平台 key 保留。 --- .../settings.authSourceDefaults.spec.ts | 66 ++++++++++--- frontend/src/api/admin/settings.ts | 73 +++++++++++---- frontend/src/api/admin/users.ts | 10 +- .../admin/user/UserPlatformQuotaModal.vue | 28 +++++- .../__tests__/UserPlatformQuotaModal.spec.ts | 93 ++++++++++++++++--- .../components/user/UserPlatformQuotaCell.vue | 6 +- frontend/src/views/admin/SettingsView.vue | 5 +- .../admin/__tests__/SettingsView.spec.ts | 37 +++++++- 8 files changed, 264 insertions(+), 54 deletions(-) diff --git a/frontend/src/api/__tests__/settings.authSourceDefaults.spec.ts b/frontend/src/api/__tests__/settings.authSourceDefaults.spec.ts index deeb758250..67ae218e47 100644 --- a/frontend/src/api/__tests__/settings.authSourceDefaults.spec.ts +++ b/frontend/src/api/__tests__/settings.authSourceDefaults.spec.ts @@ -5,18 +5,15 @@ import { buildAuthSourceDefaultsState, normalizePlatformQuotasMap, sanitizePlatformQuotasMap, + QUOTA_PLATFORMS, type UpdateSettingsRequest, type DefaultPlatformQuotasMap, } from "@/api/admin/settings"; -/** 全 null 的 5 平台 map,用于断言归一化默认值 */ -const allNullQuotas: DefaultPlatformQuotasMap = { - anthropic: { daily: null, weekly: null, monthly: null }, - openai: { daily: null, weekly: null, monthly: null }, - gemini: { daily: null, weekly: null, monthly: null }, - antigravity: { daily: null, weekly: null, monthly: null }, - grok: { daily: null, weekly: null, monthly: null }, -} +/** 全 null 的全平台 map,用于断言归一化默认值 */ +const allNullQuotas: DefaultPlatformQuotasMap = Object.fromEntries( + QUOTA_PLATFORMS.map((p) => [p, { daily: null, weekly: null, monthly: null }] as const), +); describe("admin settings auth source defaults helpers", () => { it("builds auth source defaults state from flat settings fields", () => { @@ -240,14 +237,47 @@ describe("normalizePlatformQuotasMap", () => { expect(result.grok).toEqual({ daily: null, weekly: null, monthly: null }); }); - it("无参数时返回全 5 平台全 null", () => { + it("无参数时返回全平台(对齐后端 AllowedQuotaPlatforms)全 null", () => { const result = normalizePlatformQuotasMap(); - expect(Object.keys(result)).toHaveLength(5); + expect(Object.keys(result)).toHaveLength(QUOTA_PLATFORMS.length); for (const v of Object.values(result)) { expect(v).toEqual({ daily: null, weekly: null, monthly: null }); } }); + it("预置 ollama_cloud 配额在 normalize 后保留(不再被旧 5 平台列表丢弃)", () => { + const result = normalizePlatformQuotasMap({ + ollama_cloud: { daily: 3, weekly: 30, monthly: 300 }, + kimi: { daily: 1, weekly: null, monthly: null }, + zhipu: { daily: null, weekly: 2, monthly: null }, + deepseek: { daily: null, weekly: null, monthly: 4 }, + minimax: { daily: 0.5, weekly: null, monthly: null }, + opencode_go: { daily: null, weekly: null, monthly: null }, + }); + expect(result.ollama_cloud).toEqual({ daily: 3, weekly: 30, monthly: 300 }); + expect(result.kimi).toEqual({ daily: 1, weekly: null, monthly: null }); + expect(result.zhipu).toEqual({ daily: null, weekly: 2, monthly: null }); + expect(result.deepseek).toEqual({ daily: null, weekly: null, monthly: 4 }); + expect(result.minimax).toEqual({ daily: 0.5, weekly: null, monthly: null }); + expect(result.opencode_go).toEqual({ daily: null, weekly: null, monthly: null }); + }); + + it("保留未知平台 key(后端新加、前端未收录)", () => { + const result = normalizePlatformQuotasMap({ + anthropic: { daily: 5, weekly: null, monthly: null }, + some_future_platform: { daily: 7, weekly: 8, monthly: 9 }, + } as DefaultPlatformQuotasMap); + expect(result.some_future_platform).toEqual({ daily: 7, weekly: 8, monthly: 9 }); + expect(result.anthropic).toEqual({ daily: 5, weekly: null, monthly: null }); + }); + + it("未知平台的非 number 值归一化为 null", () => { + const result = normalizePlatformQuotasMap({ + some_future_platform: { daily: "50" as unknown as number, weekly: undefined as unknown as number, monthly: null }, + } as DefaultPlatformQuotasMap); + expect(result.some_future_platform).toEqual({ daily: null, weekly: null, monthly: null }); + }); + it("非 number 类型的值归一化为 null", () => { const result = normalizePlatformQuotasMap({ anthropic: { daily: "50" as unknown as number, weekly: undefined as unknown as number, monthly: null }, @@ -288,9 +318,23 @@ describe("sanitizePlatformQuotasMap", () => { expect(result.gemini?.weekly).toBe(null); }); + it("预置 ollama_cloud 配额清洗后保留(提交 payload 不再丢行)", () => { + const result = sanitizePlatformQuotasMap({ + ollama_cloud: { daily: 3, weekly: 0, monthly: null }, + }); + expect(result.ollama_cloud).toEqual({ daily: 3, weekly: 0, monthly: null }); + }); + + it("保留未知平台 key 且同样清洗其值", () => { + const result = sanitizePlatformQuotasMap({ + some_future_platform: { daily: 7, weekly: -3, monthly: "x" as unknown as number }, + } as DefaultPlatformQuotasMap); + expect(result.some_future_platform).toEqual({ daily: 7, weekly: null, monthly: null }); + }); + it("缺失平台填充为全 null", () => { const result = sanitizePlatformQuotasMap({}); - expect(Object.keys(result)).toHaveLength(5); + expect(Object.keys(result)).toHaveLength(QUOTA_PLATFORMS.length); for (const v of Object.values(result)) { expect(v).toEqual({ daily: null, weekly: null, monthly: null }); } diff --git a/frontend/src/api/admin/settings.ts b/frontend/src/api/admin/settings.ts index 3118d2e17d..701411f734 100644 --- a/frontend/src/api/admin/settings.ts +++ b/frontend/src/api/admin/settings.ts @@ -18,7 +18,27 @@ export interface DefaultSubscriptionSetting { } // ── 平台限额类型 ────────────────────────────────────────────────── -export type PlatformType = "anthropic" | "openai" | "gemini" | "antigravity" | "grok" | "typesafe" + +// 配额平台镜像:与后端 service.AllowedQuotaPlatforms 保持一致(单一权威来源: +// backend/internal/service/domain_constants.go)。后端对 default_platform_quotas +// 与用户平台配额均为整体替换语义:这份列表缺一个平台,保存时就会静默丢弃 +// 该平台的配额行(缺行等价于不限额 → 限额 fail-open)。新增平台必须同步此列表。 +export const QUOTA_PLATFORMS = [ + "anthropic", + "openai", + "gemini", + "antigravity", + "grok", + "kimi", + "zhipu", + "deepseek", + "minimax", + "opencode_go", + "typesafe", + "ollama_cloud", +] as const + +export type PlatformType = (typeof QUOTA_PLATFORMS)[number] export type QuotaWindowType = "daily" | "weekly" | "monthly" /** 单平台三档限额;null = 不限制,undefined = 未填(等价 null) */ @@ -28,10 +48,13 @@ export interface PlatformQuotaLimits { monthly: number | null } -/** 全平台默认限额 map(key = PlatformType) */ -export type DefaultPlatformQuotasMap = Partial> - -const PLATFORMS: PlatformType[] = ["anthropic", "openai", "gemini", "antigravity", "grok", "typesafe"] +/** + * 全平台默认限额 map(key = PlatformType)。 + * 可能额外含后端新加、前端尚未收录的平台 key:整体替换语义下 normalize/sanitize + * 必须原样保留这些 key,否则一次保存就会静默删除该平台的默认配额。 + */ +export type DefaultPlatformQuotasMap = Partial> & + Record export type SchedulingThresholdPlatformType = | "openai" @@ -78,27 +101,45 @@ export function sanitizeAccountSchedulingThresholdsMap( return normalizeAccountSchedulingThresholdsMap(input) } -/** 归一化为全 4 平台 × 3 窗口(缺失填 null),供模板非空绑定 */ +/** 归一化为全平台 × 3 窗口(缺失填 null),供模板非空绑定;保留输入中的未知平台 key */ export function normalizePlatformQuotasMap(input?: DefaultPlatformQuotasMap | null): DefaultPlatformQuotasMap { + const normalizeOne = (src?: PlatformQuotaLimits): PlatformQuotaLimits => ({ + daily: typeof src?.daily === "number" ? src.daily : null, + weekly: typeof src?.weekly === "number" ? src.weekly : null, + monthly: typeof src?.monthly === "number" ? src.monthly : null, + }) const result: DefaultPlatformQuotasMap = {} - for (const p of PLATFORMS) { - const src = input?.[p] - result[p] = { - daily: typeof src?.daily === "number" ? src.daily : null, - weekly: typeof src?.weekly === "number" ? src.weekly : null, - monthly: typeof src?.monthly === "number" ? src.monthly : null, + for (const p of QUOTA_PLATFORMS) { + result[p] = normalizeOne(input?.[p]) + } + // 稳健性护栏:后端新加、前端尚未收录的平台 key 原样保留(整体替换语义下 + // 丢弃 = 静默删除该平台的默认配额)。 + if (input) { + for (const [key, value] of Object.entries(input)) { + if (!(QUOTA_PLATFORMS as readonly string[]).includes(key)) { + result[key] = normalizeOne(value) + } } } return result } -/** 提交前清洗:非有限数/负数/空字符串 → null(保留 0 = 显式禁用),返回全 4 平台嵌套 map */ +/** 提交前清洗:非有限数/负数/空字符串 → null(保留 0 = 显式禁用),返回全平台嵌套 map;保留未知平台 key */ export function sanitizePlatformQuotasMap(input?: DefaultPlatformQuotasMap | null): DefaultPlatformQuotasMap { const clean = (v: unknown): number | null => (typeof v === "number" && Number.isFinite(v) && v >= 0 ? v : null) + const sanitizeOne = (src?: PlatformQuotaLimits): PlatformQuotaLimits => ({ + daily: clean(src?.daily), weekly: clean(src?.weekly), monthly: clean(src?.monthly), + }) const result: DefaultPlatformQuotasMap = {} - for (const p of PLATFORMS) { - const src = input?.[p] - result[p] = { daily: clean(src?.daily), weekly: clean(src?.weekly), monthly: clean(src?.monthly) } + for (const p of QUOTA_PLATFORMS) { + result[p] = sanitizeOne(input?.[p]) + } + if (input) { + for (const [key, value] of Object.entries(input)) { + if (!(QUOTA_PLATFORMS as readonly string[]).includes(key)) { + result[key] = sanitizeOne(value) + } + } } return result } diff --git a/frontend/src/api/admin/users.ts b/frontend/src/api/admin/users.ts index 5e2140857c..be05db89c5 100644 --- a/frontend/src/api/admin/users.ts +++ b/frontend/src/api/admin/users.ts @@ -5,6 +5,7 @@ import { apiClient } from '../client' import type { AdminUser, UpdateUserRequest, PaginatedResponse, ApiKey } from '@/types' +import type { PlatformType } from './settings' export interface AdminBindAuthIdentityChannelRequest { channel: string @@ -330,12 +331,9 @@ export async function bindUserAuthIdentity( /** * Platform quota types */ -// Keep aligned with backend/internal/service/domain_constants.go AllowedQuotaPlatforms. -export const PLATFORM_QUOTA_PLATFORMS = [ - 'anthropic', 'openai', 'gemini', 'antigravity', 'grok', - 'kimi', 'zhipu', 'deepseek', 'minimax', 'opencode_go', 'typesafe', -] as const -export type PlatformQuotaPlatform = typeof PLATFORM_QUOTA_PLATFORMS[number] +// 与后端 AllowedQuotaPlatforms 对齐;单一来源为 settings.ts 的 QUOTA_PLATFORMS +// (后端用户平台配额 PUT 是整体替换语义,前端列表缺平台 = 保存即静默删行)。 +export type PlatformQuotaPlatform = PlatformType export type PlatformQuotaWindow = 'daily' | 'weekly' | 'monthly' export interface PlatformQuotaItem { diff --git a/frontend/src/components/admin/user/UserPlatformQuotaModal.vue b/frontend/src/components/admin/user/UserPlatformQuotaModal.vue index b1c5e799db..1a7bfa00e5 100644 --- a/frontend/src/components/admin/user/UserPlatformQuotaModal.vue +++ b/frontend/src/components/admin/user/UserPlatformQuotaModal.vue @@ -119,7 +119,7 @@ import { ref, reactive, watch, computed } from 'vue' import { useI18n } from 'vue-i18n' import { useAppStore } from '@/stores/app' import { adminAPI } from '@/api/admin' -import { PLATFORM_QUOTA_PLATFORMS } from '@/api/admin/users' +import { QUOTA_PLATFORMS } from '@/api/admin/settings' import type { AdminUser, PlatformQuotaItem, PlatformQuotaPlatform, PlatformQuotaWindow } from '@/types' import BaseDialog from '@/components/common/BaseDialog.vue' @@ -129,6 +129,10 @@ const emit = defineEmits(['close', 'success']) const { t } = useI18n() const appStore = useAppStore() +// 配额平台镜像,单一来源 settings.ts 的 QUOTA_PLATFORMS(对齐后端 AllowedQuotaPlatforms)。 +// PUT /admin/users/:id/platform-quotas 是整体替换语义:列表缺平台 = 保存即静默删行。 +const PLATFORMS = QUOTA_PLATFORMS + interface QuotaRow { platform: PlatformQuotaPlatform daily_limit_usd: number | null @@ -173,9 +177,9 @@ function emptyRow(p: PlatformQuotaPlatform): QuotaRow { } function normalize(items: PlatformQuotaItem[]): QuotaRow[] { - const byPlatform = new Map() + const byPlatform = new Map() for (const it of items) byPlatform.set(it.platform, it) - return PLATFORM_QUOTA_PLATFORMS.map((p) => { + const rows = PLATFORMS.map((p) => { const it = byPlatform.get(p) if (!it) return emptyRow(p) return { @@ -188,6 +192,22 @@ function normalize(items: PlatformQuotaItem[]): QuotaRow[] { monthly_usage_usd: it.monthly_usage_usd ?? 0, } }) + // 稳健性护栏:保留响应中前端未收录(后端新加)的平台行。整体替换语义下丢弃 + // 这些行,管理员不做任何修改直接保存也会软删其配额(限额 fail-open)。 + // platform 在前端收录前以服务端返回值透传(服务端返回即其白名单成员)。 + for (const it of items) { + if (PLATFORMS.includes(it.platform)) continue + rows.push({ + platform: it.platform as PlatformQuotaPlatform, + daily_limit_usd: it.daily_limit_usd ?? null, + weekly_limit_usd: it.weekly_limit_usd ?? null, + monthly_limit_usd: it.monthly_limit_usd ?? null, + daily_usage_usd: it.daily_usage_usd ?? 0, + weekly_usage_usd: it.weekly_usage_usd ?? 0, + monthly_usage_usd: it.monthly_usage_usd ?? 0, + }) + } + return rows } function formatUsage(n: number): string { @@ -204,7 +224,7 @@ async function load() { savedConfigured.value = configuredPlatforms(data.platform_quotas || []) } catch { appStore.showError(t('admin.users.platformQuota.loadFailed')) - quotas.value = PLATFORM_QUOTA_PLATFORMS.map(emptyRow) + quotas.value = PLATFORMS.map(emptyRow) savedConfigured.value = new Set() } finally { loading.value = false diff --git a/frontend/src/components/admin/user/__tests__/UserPlatformQuotaModal.spec.ts b/frontend/src/components/admin/user/__tests__/UserPlatformQuotaModal.spec.ts index 9651153151..901efe9132 100644 --- a/frontend/src/components/admin/user/__tests__/UserPlatformQuotaModal.spec.ts +++ b/frontend/src/components/admin/user/__tests__/UserPlatformQuotaModal.spec.ts @@ -50,6 +50,7 @@ vi.mock('@/components/common/BaseDialog.vue', () => ({ })) import UserPlatformQuotaModal from '../UserPlatformQuotaModal.vue' +import { QUOTA_PLATFORMS } from '@/api/admin/settings' import type { PlatformQuotaUpdateItem, UserSubscription } from '@/types' function makeUser(overrides: { subscriptions?: UserSubscription[] } = {}) { @@ -101,19 +102,19 @@ describe('UserPlatformQuotaModal', () => { expect(apiMocks.getPlatformQuotas).toHaveBeenCalledWith(99) }) - it('renders all eleven supported platforms with empty limits', async () => { + it('空数据渲染全平台(对齐后端 AllowedQuotaPlatforms)行', async () => { const w = await mountAndOpen() + const html = w.html() + for (const p of QUOTA_PLATFORMS) { + expect(html).toContain(p) + } const rows = w.findAll('tbody tr') - expect(rows.map(row => row.find('td').text())).toEqual([ - 'anthropic', 'openai', 'gemini', 'antigravity', 'grok', - 'kimi', 'zhipu', 'deepseek', 'minimax', 'opencode_go', 'typesafe', - ]) + expect(rows.map(row => row.find('td').text())).toEqual([...QUOTA_PLATFORMS]) for (const row of rows) { const inputs = row.findAll('input[type=number]') expect(inputs).toHaveLength(3) expect(inputs.map(input => input.element.value)).toEqual(['', '', '']) } - w.unmount() }) it.each(['kimi', 'zhipu', 'deepseek', 'minimax', 'opencode_go', 'typesafe'] as const)( @@ -137,7 +138,7 @@ describe('UserPlatformQuotaModal', () => { : item) expect(apiMocks.updatePlatformQuotas).toHaveBeenCalledTimes(1) expect(apiMocks.updatePlatformQuotas).toHaveBeenCalledWith(99, expect.arrayContaining(expected)) - expect(apiMocks.updatePlatformQuotas.mock.calls[0][1]).toHaveLength(11) + expect(apiMocks.updatePlatformQuotas.mock.calls[0][1]).toHaveLength(QUOTA_PLATFORMS.length) expect(w.emitted('success')).toHaveLength(1) w.unmount() }, @@ -152,13 +153,13 @@ describe('UserPlatformQuotaModal', () => { }) const w = await mountAndOpen() const inputs = w.findAll('input[type=number]') - // 11 platforms × 3 windows = 33 inputs - expect(inputs.length).toBe(33) + // 全平台 × 3 windows = QUOTA_PLATFORMS.length × 3 inputs + expect(inputs.length).toBe(QUOTA_PLATFORMS.length * 3) // 第一个 input 是 anthropic.daily = 10 expect((inputs[0].element as HTMLInputElement).value).toBe('10') }) - it('保存提交完整 11 platform payload', async () => { + it('保存提交完整全平台 payload', async () => { apiMocks.getPlatformQuotas.mockResolvedValueOnce({ platform_quotas: [ { platform: 'openai', daily_limit_usd: null, weekly_limit_usd: 20, monthly_limit_usd: null, @@ -175,11 +176,79 @@ describe('UserPlatformQuotaModal', () => { expect(apiMocks.updatePlatformQuotas).toHaveBeenCalledTimes(1) const [uid, payload] = apiMocks.updatePlatformQuotas.mock.calls[0] expect(uid).toBe(99) - expect(payload).toHaveLength(11) // 11 platforms always submitted + expect(payload).toHaveLength(QUOTA_PLATFORMS.length) // 全平台总是提交(整体替换语义) const openai = payload.find((p: any) => p.platform === 'openai') expect(openai.weekly_limit_usd).toBe(20) }) + it('预置 ollama_cloud 配额后不做修改直接保存,payload 仍包含该配额(整体替换不丢行)', async () => { + apiMocks.getPlatformQuotas.mockResolvedValueOnce({ + platform_quotas: [ + { platform: 'ollama_cloud', daily_limit_usd: 3, weekly_limit_usd: 30, monthly_limit_usd: 300, + daily_usage_usd: 0.5, weekly_usage_usd: 2, monthly_usage_usd: 10 }, + ], + }) + const w = await mountAndOpen() + const saveBtn = w.findAll('button').find((b) => b.text() === 'admin.users.platformQuota.save') + await saveBtn!.trigger('click') + await flushPromises() + expect(apiMocks.updatePlatformQuotas).toHaveBeenCalledTimes(1) + const [, payload] = apiMocks.updatePlatformQuotas.mock.calls[0] + const ollama = payload.find((p: any) => p.platform === 'ollama_cloud') + expect(ollama).toEqual({ + platform: 'ollama_cloud', + daily_limit_usd: 3, + weekly_limit_usd: 30, + monthly_limit_usd: 300, + }) + }) + + it('kimi/zhipu/deepseek/minimax/opencode_go 预置配额保存后不丢', async () => { + apiMocks.getPlatformQuotas.mockResolvedValueOnce({ + platform_quotas: (['kimi', 'zhipu', 'deepseek', 'minimax', 'opencode_go'] as const).map((platform, i) => ({ + platform, + daily_limit_usd: i + 1, + weekly_limit_usd: null, + monthly_limit_usd: null, + daily_usage_usd: 0, + weekly_usage_usd: 0, + monthly_usage_usd: 0, + })), + }) + const w = await mountAndOpen() + const saveBtn = w.findAll('button').find((b) => b.text() === 'admin.users.platformQuota.save') + await saveBtn!.trigger('click') + await flushPromises() + const [, payload] = apiMocks.updatePlatformQuotas.mock.calls[0] + for (const platform of ['kimi', 'zhipu', 'deepseek', 'minimax', 'opencode_go']) { + const row = payload.find((p: any) => p.platform === platform) + expect(row).toBeDefined() + expect(row.daily_limit_usd).not.toBeNull() + } + }) + + it('响应中的未知平台 key 被保留并随保存提交', async () => { + apiMocks.getPlatformQuotas.mockResolvedValueOnce({ + platform_quotas: [ + { platform: 'some_future_platform', daily_limit_usd: 7, weekly_limit_usd: null, monthly_limit_usd: 9, + daily_usage_usd: 0, weekly_usage_usd: 0, monthly_usage_usd: 0 }, + ], + }) + const w = await mountAndOpen() + expect(w.html()).toContain('some_future_platform') + const saveBtn = w.findAll('button').find((b) => b.text() === 'admin.users.platformQuota.save') + await saveBtn!.trigger('click') + await flushPromises() + const [, payload] = apiMocks.updatePlatformQuotas.mock.calls[0] + const row = payload.find((p: any) => p.platform === 'some_future_platform') + expect(row).toEqual({ + platform: 'some_future_platform', + daily_limit_usd: 7, + weekly_limit_usd: null, + monthly_limit_usd: 9, + }) + }) + it('全部清空把所有 limit 置 null(确认通过)', async () => { const confirmSpy = vi.spyOn(window, 'confirm').mockReturnValue(true) apiMocks.getPlatformQuotas.mockResolvedValueOnce({ @@ -240,7 +309,7 @@ describe('UserPlatformQuotaModal', () => { it('未配置限额的平台重置按钮禁用并提示不可用', async () => { const w = await mountAndOpen() const resetBtns = w.findAll('button').filter((b) => b.text() === '↻') - expect(resetBtns.length).toBe(33) // 11 平台 × 3 窗口 + expect(resetBtns.length).toBe(QUOTA_PLATFORMS.length * 3) // 全平台 × 3 窗口 for (const b of resetBtns) { expect((b.element as HTMLButtonElement).disabled).toBe(true) expect(b.attributes('title')).toBe('admin.users.platformQuota.reset.unavailable') diff --git a/frontend/src/components/user/UserPlatformQuotaCell.vue b/frontend/src/components/user/UserPlatformQuotaCell.vue index f59d262904..e042ed5343 100644 --- a/frontend/src/components/user/UserPlatformQuotaCell.vue +++ b/frontend/src/components/user/UserPlatformQuotaCell.vue @@ -29,12 +29,14 @@