优化(订单服务): 固定提交按钮并完善未成年提示滚动

This commit is contained in:
2026-11-27 16:20:12 +08:00
parent c3a13c5f36
commit 77371728c0
4 changed files with 352 additions and 5 deletions
@@ -130,3 +130,210 @@ test(
}
},
)
test(
'子分类无配置时继承父级,发布子配置后待补资料工单切换到子配置',
{ skip: !TEST_DATABASE_URL ? '未设置 ORDER_SERVICE_CONTENT_TEST_DATABASE_URL' : false },
async () => {
process.env.DATABASE_URL = TEST_DATABASE_URL
process.env.ENABLE_DEV_MOCK = '1'
const { closeDb, query, withTransaction } = await import('../../db/client.js')
const { publishAdminOrderServiceProfile, saveAdminOrderServiceProfile } =
await import('./order-service-profile-service.js')
const { createAdminMockWorkOrder } = await import('./admin-mock-work-order-service.js')
const { getOrderServiceByPlatformOrderId } = await import('./order-service-public-service.js')
const suffix = `${Date.now()}-${Math.floor(Math.random() * 1_000_000)}`
let parentCategoryId = 0
let childCategoryId = 0
let workOrderId = 0
try {
const parent = await query<{ id: number }>(
`INSERT INTO work_categories
(category_key, name, sort_order, status, created_at, updated_at)
VALUES ($1, $2, 1, 'active', NOW(), NOW())
RETURNING id`,
[`order-service-parent-test-${suffix}`, '订单服务父级测试分类'],
)
parentCategoryId = Number(parent.rows[0]?.id || 0)
const child = await query<{ id: number }>(
`INSERT INTO work_categories
(category_key, name, parent_id, sort_order, status, created_at, updated_at)
VALUES ($1, $2, $3, 1, 'active', NOW(), NOW())
RETURNING id`,
[`order-service-child-test-${suffix}`, '订单服务子级测试分类', parentCategoryId],
)
childCategoryId = Number(child.rows[0]?.id || 0)
const savedParent = await saveAdminOrderServiceProfile({
categoryId: parentCategoryId,
name: '父级订单服务',
title: '父级资料',
fields: [
{
key: 'gameId',
label: '游戏编号',
type: 'text',
validation: 'none',
required: true,
placeholder: '',
helpText: '',
options: [],
sortOrder: 10,
},
],
screenshots: { enabled: false, required: false, minCount: 0, maxCount: 5 },
autoPublish: { enabled: false, requireVoucherConsume: true, retryMax: 3 },
ageGate: {
enabled: true,
title: '父级未成年提示',
warningText: '父级警示',
content: '父级正文',
importantNotice: '父级重要提示',
adultButtonText: '我已成年',
minorButtonText: '我是未成年',
minorBlockedTitle: '不能购买',
minorBlockedContent: '流程停止',
},
bottomGuideImage: {
enabled: true,
image: {
objectKey: 'order-service-guide/integration/parent.png',
contentType: 'image/png',
},
},
})
await publishAdminOrderServiceProfile(Number(savedParent.profile?.id || 0))
const platformOrderId = `IT-ORDER-SERVICE-INHERIT-${suffix}`
const created = await createAdminMockWorkOrder({
platformOrderId,
productName: `订单服务继承测试-${suffix}`,
sellerId: '订单服务集成测试店铺',
categoryId: childCategoryId,
rewardAmount: 10,
paymentAmount: 12,
materialComplete: false,
})
workOrderId = Number(created.order.workOrderId)
assert.ok(workOrderId > 0)
const inheritedOrder = await getOrderServiceByPlatformOrderId(platformOrderId)
const inheritedItem = inheritedOrder.items[0]
assert.equal(inheritedItem?.ageGate?.title, '父级未成年提示')
assert.equal(
inheritedItem?.bottomGuideImage?.image.objectKey,
'order-service-guide/integration/parent.png',
)
const inheritedSnapshot = await query<{
service_profile_snapshot_json: {
inherited: boolean
sourceCategoryId: number
config: { ageGate: { title: string } }
}
}>(
`SELECT service_profile_snapshot_json
FROM work_orders
WHERE id = $1`,
[workOrderId],
)
assert.equal(inheritedSnapshot.rows[0]?.service_profile_snapshot_json.inherited, true)
assert.equal(
inheritedSnapshot.rows[0]?.service_profile_snapshot_json.sourceCategoryId,
parentCategoryId,
)
const savedChild = await saveAdminOrderServiceProfile({
categoryId: childCategoryId,
name: '子级订单服务',
title: '子级资料',
fields: [
{
key: 'gameId',
label: '游戏编号',
type: 'text',
validation: 'none',
required: true,
placeholder: '',
helpText: '',
options: [],
sortOrder: 10,
},
],
screenshots: { enabled: false, required: false, minCount: 0, maxCount: 5 },
autoPublish: { enabled: false, requireVoucherConsume: true, retryMax: 3 },
ageGate: {
enabled: true,
title: '子级未成年提示',
warningText: '子级警示',
content: '子级正文',
importantNotice: '子级重要提示',
adultButtonText: '我已成年',
minorButtonText: '我是未成年',
minorBlockedTitle: '不能购买',
minorBlockedContent: '流程停止',
},
bottomGuideImage: {
enabled: true,
image: {
objectKey: 'order-service-guide/integration/child.png',
contentType: 'image/png',
},
},
})
await publishAdminOrderServiceProfile(Number(savedChild.profile?.id || 0))
const overriddenOrder = await getOrderServiceByPlatformOrderId(platformOrderId)
const overriddenItem = overriddenOrder.items[0]
assert.equal(overriddenItem?.ageGate?.title, '子级未成年提示')
assert.equal(
overriddenItem?.bottomGuideImage?.image.objectKey,
'order-service-guide/integration/child.png',
)
const overriddenSnapshot = await query<{
service_profile_snapshot_json: {
inherited: boolean
sourceCategoryId: number
config: { ageGate: { title: string } }
}
}>(
`SELECT service_profile_snapshot_json
FROM work_orders
WHERE id = $1`,
[workOrderId],
)
assert.equal(overriddenSnapshot.rows[0]?.service_profile_snapshot_json.inherited, false)
assert.equal(
overriddenSnapshot.rows[0]?.service_profile_snapshot_json.sourceCategoryId,
childCategoryId,
)
assert.equal(
overriddenSnapshot.rows[0]?.service_profile_snapshot_json.config.ageGate.title,
'子级未成年提示',
)
} finally {
if (workOrderId > 0) {
await withTransaction(async (client) => {
await client.query("SET LOCAL session_replication_role = 'replica'")
await client.query('DELETE FROM work_order_events WHERE work_order_id = $1', [
workOrderId,
])
await client.query('DELETE FROM work_orders WHERE id = $1', [workOrderId])
})
}
if (childCategoryId > 0) {
await query('DELETE FROM order_service_profiles WHERE category_id = $1', [childCategoryId])
await query('DELETE FROM work_categories WHERE id = $1', [childCategoryId])
}
if (parentCategoryId > 0) {
await query('DELETE FROM order_service_profiles WHERE category_id = $1', [parentCategoryId])
await query('DELETE FROM work_categories WHERE id = $1', [parentCategoryId])
}
delete process.env.ENABLE_DEV_MOCK
await closeDb()
}
},
)
@@ -125,6 +125,7 @@ export default function OrderServicePage() {
required: ageGateRequired,
decision: ageGateDecision,
})
const hasFixedSubmit = !ageGateOpen && pendingItems.length === 1
useOrderServicePageMeta(ageGateOpen ? '购买前确认' : info?.items[0]?.title || '订单服务')
@@ -329,7 +330,7 @@ export default function OrderServicePage() {
].join('、') || '订单商品'
return (
<main className="collect-link-page">
<main className={`collect-link-page${hasFixedSubmit ? ' has-fixed-submit' : ''}`}>
{selectedAgeGate ? (
<OrderServiceAgeGateModal
open={ageGateOpen}
@@ -412,6 +413,7 @@ export default function OrderServicePage() {
code={orderNo}
submitting={submittingId === item.workOrderId}
disabled={submittingId !== 0}
fixedSubmit={hasFixedSubmit}
screenshots={screenshotsByOrder[item.workOrderId] ?? item.screenshots ?? []}
onScreenshotsChange={(files) => {
setScreenshotsByOrder((current) => ({
@@ -638,6 +640,7 @@ function OrderServiceForm({
code,
submitting,
disabled,
fixedSubmit,
screenshots,
onScreenshotsChange,
onSubmit,
@@ -646,6 +649,7 @@ function OrderServiceForm({
code: string
submitting: boolean
disabled: boolean
fixedSubmit: boolean
screenshots: UploadedFile[]
onScreenshotsChange: (files: UploadedFile[]) => void
onSubmit: (values: Record<string, unknown>) => void
@@ -767,7 +771,7 @@ function OrderServiceForm({
</Form.Item>
) : null}
<div className="collect-link-actions">
<div className={`collect-link-actions${fixedSubmit ? ' is-viewport-fixed' : ''}`}>
<Button
block
htmlType="submit"
+82 -3
View File
@@ -665,6 +665,46 @@
min-width: 180px;
}
/* 单商品待补资料时,提交按钮固定在一屏底部,避免长表单或引导图把按钮推离视口。 */
.collect-link-page.has-fixed-submit {
padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
}
.collect-link-actions.is-viewport-fixed {
position: fixed;
left: 50%;
bottom: calc(12px + env(safe-area-inset-bottom, 0px));
z-index: 30;
width: min(664px, calc(100vw - 88px));
margin: 0;
padding: 0;
background: transparent;
border: 0;
box-shadow: none;
transform: translateX(-50%);
}
.collect-link-actions.is-viewport-fixed .ant-btn {
width: 100%;
min-width: 0;
height: 48px;
color: #ffffff;
font-size: 16px;
font-weight: 600;
background: #ff6a00;
border-color: #ff6a00;
border-radius: 8px;
box-shadow: 0 10px 26px rgba(255, 106, 0, 0.28);
}
.collect-link-actions.is-viewport-fixed .ant-btn:not(:disabled):hover,
.collect-link-actions.is-viewport-fixed .ant-btn:not(:disabled):active,
.collect-link-actions.is-viewport-fixed .ant-btn:not(:disabled):focus-visible {
color: #ffffff;
background: #ff6a00;
border-color: #ff6a00;
}
.collect-link-footnote {
display: block;
text-align: center;
@@ -703,6 +743,15 @@
.collect-link-actions .ant-btn {
width: 100%;
}
.collect-link-page.has-fixed-submit {
padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px));
}
.collect-link-actions.is-viewport-fixed {
bottom: calc(10px + env(safe-area-inset-bottom, 0px));
width: min(664px, calc(100vw - 64px));
}
}
@media (max-width: 480px) {
@@ -767,6 +816,14 @@
.collect-link-order-meta {
display: grid;
}
.collect-link-page.has-fixed-submit {
padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
}
.collect-link-actions.is-viewport-fixed {
width: calc(100vw - 48px);
}
}
/* ===== 工单补资料页未成年提示 ===== */
@@ -797,16 +854,37 @@
}
.order-service-age-gate .ant-modal-body {
flex: 1 1 auto;
flex: 1 1 0;
min-height: 0;
padding-right: 6px;
max-height: max(96px, calc(100dvh - 230px));
padding-right: 8px;
overflow-y: auto;
overscroll-behavior: contain;
scrollbar-gutter: stable;
scrollbar-width: thin;
scrollbar-color: #cbd5e1 transparent;
-webkit-overflow-scrolling: touch;
}
.order-service-age-gate .ant-modal-body::-webkit-scrollbar {
width: 6px;
}
.order-service-age-gate .ant-modal-body::-webkit-scrollbar-track {
background: transparent;
}
.order-service-age-gate .ant-modal-body::-webkit-scrollbar-thumb {
background: #cbd5e1;
border-radius: 999px;
}
.order-service-age-gate .ant-modal-footer {
flex: none;
margin-top: 12px;
padding-top: 12px;
background: #ffffff;
border-top: 1px solid #eef2f7;
}
.order-service-age-gate-content {
@@ -966,7 +1044,8 @@
}
.order-service-age-gate .ant-modal-body {
padding-right: 2px;
max-height: max(88px, calc(100dvh - 220px));
padding-right: 4px;
}
.order-service-age-gate-warning {
@@ -0,0 +1,57 @@
import assert from 'node:assert/strict'
import { readFile } from 'node:fs/promises'
import test from 'node:test'
test('订单服务单商品提交按钮固定在一屏底部并预留手机安全区', async () => {
const [page, styles] = await Promise.all([
readFile(new URL('../src/pages/public/OrderServicePage.tsx', import.meta.url), 'utf8'),
readFile(new URL('../src/styles/client/collect.css', import.meta.url), 'utf8'),
])
assert.ok(page.includes('const hasFixedSubmit = !ageGateOpen && pendingItems.length === 1'))
assert.ok(page.includes('fixedSubmit={hasFixedSubmit}'))
assert.ok(page.includes('is-viewport-fixed'))
assert.ok(styles.includes('.collect-link-page.has-fixed-submit'))
assert.match(styles, /\.collect-link-actions\.is-viewport-fixed\s*\{[^}]*position:\s*fixed;/s)
assert.ok(styles.includes('env(safe-area-inset-bottom, 0px)'))
assert.ok(styles.includes('calc(100vw - 48px)'))
assert.match(
styles,
/\.collect-link-actions\.is-viewport-fixed\s*\{[^}]*background:\s*transparent;/s,
)
assert.match(
styles,
/\.collect-link-actions\.is-viewport-fixed \.ant-btn\s*\{[^}]*background:\s*#ff6a00;/s,
)
assert.match(
styles,
/\.collect-link-actions\.is-viewport-fixed \.ant-btn:not\(:disabled\):hover[\s\S]*background:\s*#ff6a00;/s,
)
})
test('多商品待补资料时保留逐商品按钮,避免固定按钮互相覆盖', async () => {
const page = await readFile(
new URL('../src/pages/public/OrderServicePage.tsx', import.meta.url),
'utf8',
)
assert.ok(page.includes('pendingItems.length === 1'))
assert.ok(page.includes('fixedSubmit={hasFixedSubmit}'))
assert.ok(page.includes('className={`collect-link-actions${fixedSubmit'))
})
test('未成年提示正文独立滚动,底部操作按钮始终可见', async () => {
const styles = await readFile(
new URL('../src/styles/client/collect.css', import.meta.url),
'utf8',
)
assert.match(
styles,
/\.order-service-age-gate \.ant-modal-body\s*\{[^}]*flex:\s*1 1 0;[^}]*max-height:\s*max\(96px, calc\(100dvh - 230px\)\);[^}]*overflow-y:\s*auto;/s,
)
assert.match(
styles,
/\.order-service-age-gate \.ant-modal-footer\s*\{[^}]*flex:\s*none;[^}]*border-top:/s,
)
assert.ok(styles.includes('.order-service-age-gate .ant-modal-body::-webkit-scrollbar-thumb'))
})