From a8c58feebca1153b82d334b9d4c264bea11ef419 Mon Sep 17 00:00:00 2001 From: zhaoxing <2558691827@qq.com> Date: Tue, 10 Nov 2026 12:44:35 +0800 Subject: [PATCH] =?UTF-8?q?fix(consignment):=20=E5=85=BC=E5=AE=B9=E6=97=A7?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=BC=BA=E5=B0=91=20internalMatch=20?= =?UTF-8?q?=E5=B9=B6=E5=88=B7=E6=96=B0=E9=85=8D=E7=BD=AE=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - toFormValues/buildPayload 对 internalMatch 使用可选链,避免旧配置或旧缓存导致页面崩溃 - admin-consignment-profiles 查询增加 staleTime: 0,后台配置页每次进入重拉 - 补充前端回归断言 --- .../src/pages/admin/panels/ConsignmentConfigPanel.tsx | 11 +++++++---- .../tests/consignment-matching-config.test.ts | 7 +++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/apps/frontend/src/pages/admin/panels/ConsignmentConfigPanel.tsx b/apps/frontend/src/pages/admin/panels/ConsignmentConfigPanel.tsx index 08dde719..c19ec340 100644 --- a/apps/frontend/src/pages/admin/panels/ConsignmentConfigPanel.tsx +++ b/apps/frontend/src/pages/admin/panels/ConsignmentConfigPanel.tsx @@ -214,11 +214,12 @@ function toFormValues(profile: ConsignmentProfile): ConfigFormValues { }, internalMatch: { // 内部等待只属于手动匹配;非手动模式切回手动时给默认 30 分钟。 + // 兼容旧配置/旧缓存缺少 internalMatch 的情况,不能直接读嵌套字段。 delayMinutes: config.matching.mode === 'manual' - ? Number(config.internalMatch.delayMinutes || 0) - : Number(config.internalMatch.delayMinutes) > 0 - ? Number(config.internalMatch.delayMinutes) + ? Number(config.internalMatch?.delayMinutes || 0) + : Number(config.internalMatch?.delayMinutes ?? 0) > 0 + ? Number(config.internalMatch?.delayMinutes) : 30, }, timeout: { @@ -344,7 +345,7 @@ function buildPayload( internalMatch: { // 内部等待只属于手动匹配:关闭匹配不再等待;自动匹配不使用等待窗口。 delayMinutes: - values.matching.mode === 'off' ? 0 : Number(values.internalMatch.delayMinutes || 0), + values.matching.mode === 'off' ? 0 : Number(values.internalMatch?.delayMinutes || 0), }, timeout: { minutes: Math.max(0, Math.round(Number(values.timeout.hours || 0) * 60)), @@ -606,6 +607,8 @@ export default function ConsignmentConfigPanel() { const profilesQuery = useQuery({ queryKey: ['admin-consignment-profiles'], queryFn: () => fetchAdminConsignmentProfiles(), + // 后台配置页每次进入都重拉,避免旧缓存缺少新增字段(如 internalMatch)。 + staleTime: 0, }) const data = profilesQuery.data?.data const categories = data?.categories || [] diff --git a/apps/frontend/tests/consignment-matching-config.test.ts b/apps/frontend/tests/consignment-matching-config.test.ts index 38e4d88d..afe549f7 100644 --- a/apps/frontend/tests/consignment-matching-config.test.ts +++ b/apps/frontend/tests/consignment-matching-config.test.ts @@ -44,6 +44,13 @@ test('寄卖配置面板:必须覆盖保证金/服务费/数量限制/匹配/ } }) +test('寄卖配置:旧配置缺少 internalMatch 时不能崩溃', () => { + const panel = read('../src/pages/admin/panels/ConsignmentConfigPanel.tsx') + assert.ok(panel.includes('config.internalMatch?.delayMinutes'), '读取旧配置必须使用可选链') + assert.ok(panel.includes('values.internalMatch?.delayMinutes'), '保存旧配置必须使用可选链') + assert.ok(panel.includes('staleTime: 0'), '配置查询必须每次重拉,避免旧缓存缺字段') +}) + test('打手端:寄卖页必须按已发布配置动态生成 tab,并支持改价', () => { const page = read('../src/pages/worker/WorkerConsignmentPage.tsx') assert.ok(page.includes('fetchWorkerConsignmentProfiles'), '必须拉取已发布寄卖配置')