diff --git a/apps/frontend/src/pages/worker/WorkerConsignmentPage.tsx b/apps/frontend/src/pages/worker/WorkerConsignmentPage.tsx index d10a076b..a0c7051a 100644 --- a/apps/frontend/src/pages/worker/WorkerConsignmentPage.tsx +++ b/apps/frontend/src/pages/worker/WorkerConsignmentPage.tsx @@ -64,6 +64,7 @@ import type { UploadedFile } from '@/types/worker-platform' import { DEFAULT_CONSIGNMENT_INTAKE_FIELDS, buildSpecItemName } from '@/utils/consignment-spec' import { formatConsignmentContactSupporter } from '@/utils/consignment-contact' import { formatGiftCooldownRemaining } from '@/utils/consignment-cooldown' +import { resolveConsignmentPageTitle } from '@/utils/consignment-page-title' import { canWorkerPublishConsignment } from '@/utils/consignment-whitelist' import { formatDateTime } from '@/utils/date-time' import { useIsMobile } from '@/utils/use-is-mobile' @@ -205,6 +206,7 @@ export default function WorkerConsignmentPage() { consignmentProfiles[0] || null const selectedSpecs: ConsignmentSpecField[] = selectedProfile?.config.specs ?? [] + const pageTitle = resolveConsignmentPageTitle(selectedProfile) const intakeFields: ConsignmentIntakeField[] = selectedProfile?.config.intake?.fields ?? DEFAULT_CONSIGNMENT_INTAKE_FIELDS useEffect(() => { @@ -684,7 +686,7 @@ export default function WorkerConsignmentPage() { 寄卖功能暂未开通 - 平台当前开启寄卖白名单。请联系客服申请开通,由后台运营开通后即可发布苏尔南寄卖。 + 平台当前开启寄卖白名单。请联系客服申请开通,由后台运营开通后即可发布寄卖。 - 苏尔南寄卖 + {pageTitle} diff --git a/apps/frontend/src/styles/worker.css b/apps/frontend/src/styles/worker.css index e2117130..1caefd57 100644 --- a/apps/frontend/src/styles/worker.css +++ b/apps/frontend/src/styles/worker.css @@ -4460,6 +4460,19 @@ body { .worker-consignment-page .worker-orders-desktop-header { margin-bottom: 8px; } + + /* 标题跟随分类配置,最长 30 字;移动端允许换行,避免挤压右侧刷新按钮 */ + .worker-consignment-page .worker-orders-header-left { + min-width: 0; + flex-shrink: 1; + align-items: flex-start; + } + + .worker-consignment-page .worker-orders-heading.ant-typography { + white-space: normal; + overflow-wrap: anywhere; + line-height: 1.25; + } } .worker-consignment-page .worker-orders-card { diff --git a/apps/frontend/src/utils/consignment-page-title.ts b/apps/frontend/src/utils/consignment-page-title.ts new file mode 100644 index 00000000..663c3c83 --- /dev/null +++ b/apps/frontend/src/utils/consignment-page-title.ts @@ -0,0 +1,18 @@ +import type { WorkerConsignmentProfile } from '../types/consignment' + +type ConsignmentPageTitleProfile = + | Pick + | null + | undefined + +/** + * 打手端寄卖页大标题:跟随当前选中的寄卖分类。 + * 后台「打手端 tab 名称」留空时按分类名称兜底,与配置页提示保持一致。 + */ +export function resolveConsignmentPageTitle(profile: ConsignmentPageTitleProfile): string { + const tabTitle = profile?.tabTitle?.trim() + if (tabTitle) return tabTitle + const categoryName = profile?.categoryName?.trim() + if (categoryName) return categoryName + return '寄卖' +} diff --git a/apps/frontend/tests/consignment-page-title.test.ts b/apps/frontend/tests/consignment-page-title.test.ts new file mode 100644 index 00000000..48ca126e --- /dev/null +++ b/apps/frontend/tests/consignment-page-title.test.ts @@ -0,0 +1,44 @@ +import assert from 'node:assert/strict' +import { readFileSync } from 'node:fs' +import { fileURLToPath } from 'node:url' +import test from 'node:test' + +import { resolveConsignmentPageTitle } from '../src/utils/consignment-page-title.ts' + +test('寄卖页标题优先使用打手端 tab 名称', () => { + assert.equal( + resolveConsignmentPageTitle({ tabTitle: ' 苏尔南寄卖 ', categoryName: '苏尔南手枪' }), + '苏尔南寄卖', + ) +}) + +test('打手端 tab 名称为空时回退分类名称', () => { + assert.equal( + resolveConsignmentPageTitle({ tabTitle: ' ', categoryName: ' 暗潮手枪 ' }), + '暗潮手枪', + ) +}) + +test('tab 名称与分类名称都为空时回退「寄卖」', () => { + assert.equal(resolveConsignmentPageTitle({ tabTitle: '', categoryName: '' }), '寄卖') + assert.equal(resolveConsignmentPageTitle(null), '寄卖') + assert.equal(resolveConsignmentPageTitle(undefined), '寄卖') +}) + +test('打手端寄卖页标题必须跟随选中分类,不得硬编码', () => { + const page = readFileSync( + fileURLToPath(new URL('../src/pages/worker/WorkerConsignmentPage.tsx', import.meta.url)), + 'utf8', + ) + assert.ok( + page.includes('const pageTitle = resolveConsignmentPageTitle(selectedProfile)'), + '标题必须由当前选中的寄卖配置计算', + ) + const headingStart = page.indexOf('className="worker-orders-heading"') + assert.ok(headingStart > 0, '找不到寄卖页大标题') + const headingBlock = page.slice(headingStart, headingStart + 160) + assert.ok(headingBlock.includes('{pageTitle}'), '大标题必须渲染动态 pageTitle') + assert.ok(!headingBlock.includes('苏尔南寄卖'), '大标题不得再硬编码苏尔南寄卖') + assert.ok(page.includes('即可发布寄卖'), '白名单提示应使用通用「寄卖」文案') + assert.ok(!page.includes('即可发布苏尔南寄卖'), '白名单提示不得再硬编码苏尔南寄卖') +})