diff --git a/apps/frontend/src/pages/worker/WorkerConsignmentPage.tsx b/apps/frontend/src/pages/worker/WorkerConsignmentPage.tsx
index b8c6b493..4dcc148a 100644
--- a/apps/frontend/src/pages/worker/WorkerConsignmentPage.tsx
+++ b/apps/frontend/src/pages/worker/WorkerConsignmentPage.tsx
@@ -198,11 +198,11 @@ export default function WorkerConsignmentPage() {
}),
})
- // 已发布的分类寄卖配置 → 打手端动态 tab
+ // 已发布的分类寄卖配置 → 打手端动态 tab。
+ // activeQuantity(在售+待审核占用)是动态值:不设 staleTime,进入页面/窗口聚焦都拉最新。
const consignmentProfilesQuery = useQuery({
queryKey: ['worker-consignment-profiles'],
queryFn: () => fetchWorkerConsignmentProfiles(),
- staleTime: 60_000,
})
const consignmentProfiles = consignmentProfilesQuery.data?.data.profiles || []
const selectedProfile: WorkerConsignmentProfile | null =
@@ -247,10 +247,12 @@ export default function WorkerConsignmentPage() {
const contactSupporters = consignmentContactsQuery.data?.data.items || []
const firstContactSupporterId = contactSupporters[0]?.id ?? null
- // 切换标签页时自动刷新最新数据
+ // 切换标签页时自动刷新最新数据;回到发布页时同步刷新各分类占用(activeQuantity)
useEffect(() => {
if (activeTab === 'records') {
void queryClient.invalidateQueries({ queryKey: ['worker-my-consignments'] })
+ } else {
+ void queryClient.invalidateQueries({ queryKey: ['worker-consignment-profiles'] })
}
void queryClient.invalidateQueries({ queryKey: ['worker-profile'] })
}, [activeTab, queryClient])
@@ -586,7 +588,12 @@ export default function WorkerConsignmentPage() {
setPriceState({ status: 'idle' })
lastPriceQueryKeyRef.current = ''
setIntakeImages({})
- await Promise.all([myConsignmentsQuery.refetch(), profileQuery.refetch()])
+ await Promise.all([
+ myConsignmentsQuery.refetch(),
+ profileQuery.refetch(),
+ // 发布后立即刷新各分类占用,否则同一页面连续发布仍显示发布前的剩余额度
+ consignmentProfilesQuery.refetch(),
+ ])
setRecordFilter('reviewing')
setActiveTab('records')
} catch (err: any) {
@@ -1123,8 +1130,10 @@ export default function WorkerConsignmentPage() {
}
- loading={myConsignmentsQuery.isFetching}
- onClick={() => myConsignmentsQuery.refetch()}
+ loading={myConsignmentsQuery.isFetching || consignmentProfilesQuery.isFetching}
+ onClick={() =>
+ Promise.all([myConsignmentsQuery.refetch(), consignmentProfilesQuery.refetch()])
+ }
>
刷新
diff --git a/apps/frontend/tests/consignment-publish-limits.test.ts b/apps/frontend/tests/consignment-publish-limits.test.ts
index 1844435c..02404ad5 100644
--- a/apps/frontend/tests/consignment-publish-limits.test.ts
+++ b/apps/frontend/tests/consignment-publish-limits.test.ts
@@ -59,3 +59,46 @@ test('打手端发布页:价格与数量限制必须走同一套规则', () =>
assert.ok(page.includes('quantityLimit.blocked'), '达到上限时必须禁用提交')
assert.ok(page.includes('quantityLimit.activeQuantity'), '必须带入当前在售/待审核件数')
})
+
+test('打手端发布页:发布成功、切回发布 tab、手动刷新都会同步最新寄售占用', () => {
+ const page = readFileSync(
+ fileURLToPath(new URL('../src/pages/worker/WorkerConsignmentPage.tsx', import.meta.url)),
+ 'utf8',
+ )
+
+ // 含 activeQuantity 的配置查询不能有缓存,否则发布后仍显示旧额度
+ const queryStart = page.indexOf('const consignmentProfilesQuery = useQuery({')
+ const queryEnd = page.indexOf('const consignmentProfiles =', queryStart)
+ assert.ok(queryStart > 0 && queryEnd > queryStart, '必须存在寄卖配置查询')
+ assert.ok(
+ !page.slice(queryStart, queryEnd).includes('staleTime'),
+ '含 activeQuantity 的配置查询不得设置 staleTime',
+ )
+
+ // 发布成功后必须刷新配置占用,否则同一页面连续发布仍按旧额度提示
+ const publishStart = page.indexOf('async function handlePublishSubmit')
+ const publishEnd = page.indexOf('function resolveActionSubmissionId')
+ assert.ok(publishStart > 0 && publishEnd > publishStart, '必须存在发布提交处理函数')
+ assert.ok(
+ page.slice(publishStart, publishEnd).includes('consignmentProfilesQuery.refetch()'),
+ '发布成功后必须刷新寄卖配置占用',
+ )
+
+ // 切回「发布寄卖」tab 时必须失效缓存(客服审核/驳回后占用会变)
+ const effectStart = page.indexOf('切换标签页时自动刷新最新数据')
+ const effectEnd = page.indexOf('// 后端已按「一件货一行」聚合')
+ assert.ok(effectStart > 0 && effectEnd > effectStart, '必须存在切 tab 刷新逻辑')
+ assert.ok(
+ page.slice(effectStart, effectEnd).includes("queryKey: ['worker-consignment-profiles']"),
+ '切回发布 tab 必须失效寄卖配置缓存',
+ )
+
+ // 顶部「刷新」按钮必须同时刷新寄卖记录与剩余额度
+ const refreshStart = page.indexOf('loading={myConsignmentsQuery.isFetching')
+ const refreshEnd = page.indexOf('刷新', refreshStart)
+ assert.ok(refreshStart > 0 && refreshEnd > refreshStart, '必须存在顶部刷新按钮')
+ assert.ok(
+ page.slice(refreshStart, refreshEnd).includes('consignmentProfilesQuery.refetch()'),
+ '手动刷新必须同步刷新剩余寄卖额度',
+ )
+})