fix(consignment): 兼容旧配置缺少 internalMatch 并刷新配置缓存
- toFormValues/buildPayload 对 internalMatch 使用可选链,避免旧配置或旧缓存导致页面崩溃 - admin-consignment-profiles 查询增加 staleTime: 0,后台配置页每次进入重拉 - 补充前端回归断言
This commit is contained in:
@@ -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 || []
|
||||
|
||||
@@ -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'), '必须拉取已发布寄卖配置')
|
||||
|
||||
Reference in New Issue
Block a user