feat(orders): 缩短选号到支付链路并对齐旧站逻辑

This commit is contained in:
yml2213
2026-11-01 15:59:29 +08:00
parent efd9e62264
commit 079e04823f
4 changed files with 44 additions and 9 deletions
@@ -235,12 +235,8 @@ export function ListingDetailPage() {
try { try {
const order = await createOrder(data.id) const order = await createOrder(data.id)
setConfirmOpen(false) setConfirmOpen(false)
modal.success({ message.success('订单已创建,请完成支付')
title: '订单已创建', navigate(`/orders/${order.id}?pay=1`)
content: '订单已生成,接下来请完成支付;支付成功后才进入交接流程。',
okText: '去支付',
onOk: () => navigate(`/orders/${order.id}`),
})
} catch (error) { } catch (error) {
modal.error({ modal.error({
title: '下单失败', title: '下单失败',
@@ -1,4 +1,4 @@
import { useState } from 'react' import { useEffect, useRef, useState } from 'react'
import { import {
Alert, Alert,
App, App,
@@ -58,15 +58,23 @@ interface ActionFormValues {
interface OrderActionPanelProps { interface OrderActionPanelProps {
order: UserOrderDetail order: UserOrderDetail
onChanged: () => void | Promise<void> onChanged: () => void | Promise<void>
autoPay?: boolean
onAutoPayHandled?: () => void
} }
export function OrderActionPanel({ order, onChanged }: OrderActionPanelProps) { export function OrderActionPanel({
order,
onChanged,
autoPay = false,
onAutoPayHandled,
}: OrderActionPanelProps) {
const { message, modal } = App.useApp() const { message, modal } = App.useApp()
const [form] = Form.useForm<ActionFormValues>() const [form] = Form.useForm<ActionFormValues>()
const user = useSessionStore(state => state.user) const user = useSessionStore(state => state.user)
const [dialog, setDialog] = useState<DialogKind>(null) const [dialog, setDialog] = useState<DialogKind>(null)
const [busy, setBusy] = useState<string | null>(null) const [busy, setBusy] = useState<string | null>(null)
const [payURL, setPayURL] = useState('') const [payURL, setPayURL] = useState('')
const autoPayTriggered = useRef(false)
const actions = getOrderActionAvailability(order, user?.id) const actions = getOrderActionAvailability(order, user?.id)
const checkout = order.checkout const checkout = order.checkout
@@ -127,6 +135,14 @@ export function OrderActionPanel({ order, onChanged }: OrderActionPanelProps) {
setDialog(kind) setDialog(kind)
} }
useEffect(() => {
if (!autoPay || autoPayTriggered.current || !actions.canPay) return
autoPayTriggered.current = true
openDialog('pay')
onAutoPayHandled?.()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [autoPay, actions.canPay])
const run = async (key: string, fn: () => Promise<void>) => { const run = async (key: string, fn: () => Promise<void>) => {
setBusy(key) setBusy(key)
try { try {
@@ -15,7 +15,7 @@ import {
} from 'antd' } from 'antd'
import { ArrowLeftOutlined, CopyOutlined, MessageOutlined } from '@ant-design/icons' import { ArrowLeftOutlined, CopyOutlined, MessageOutlined } from '@ant-design/icons'
import { useQueryClient } from '@tanstack/react-query' import { useQueryClient } from '@tanstack/react-query'
import { Link, useNavigate, useParams } from 'react-router-dom' import { Link, useNavigate, useParams, useSearchParams } from 'react-router-dom'
import { BrandLogo } from '@/components/BrandLogo' import { BrandLogo } from '@/components/BrandLogo'
import { OrderActionPanel } from '@/features/orders/OrderActionPanel' import { OrderActionPanel } from '@/features/orders/OrderActionPanel'
@@ -52,6 +52,8 @@ function toneColor(tone: string) {
export function OrderDetailPage() { export function OrderDetailPage() {
const { id } = useParams() const { id } = useParams()
const navigate = useNavigate() const navigate = useNavigate()
const [searchParams, setSearchParams] = useSearchParams()
const autoPay = searchParams.get('pay') === '1'
const queryClient = useQueryClient() const queryClient = useQueryClient()
const { message } = App.useApp() const { message } = App.useApp()
const token = useSessionStore(state => state.token) const token = useSessionStore(state => state.token)
@@ -400,6 +402,12 @@ export function OrderDetailPage() {
</Button> </Button>
<OrderActionPanel <OrderActionPanel
order={order} order={order}
autoPay={autoPay}
onAutoPayHandled={() => {
const next = new URLSearchParams(searchParams)
next.delete('pay')
setSearchParams(next, { replace: true })
}}
onChanged={async () => { onChanged={async () => {
await Promise.all([query.refetch(), handoffQuery.refetch()]) await Promise.all([query.refetch(), handoffQuery.refetch()])
await queryClient.invalidateQueries({ queryKey: ['pc-my-orders'] }) await queryClient.invalidateQueries({ queryKey: ['pc-my-orders'] })
@@ -54,9 +54,11 @@ function toneColor(tone: string) {
function OrderCard({ function OrderCard({
order, order,
onOpen, onOpen,
onPay,
}: { }: {
order: UserOrderListItem order: UserOrderListItem
onOpen: () => void onOpen: () => void
onPay?: () => void
}) { }) {
const status = orderStatusMeta(order.status) const status = orderStatusMeta(order.status)
const handoff = handoffStatusMeta(order.handoff_status) const handoff = handoffStatusMeta(order.handoff_status)
@@ -116,6 +118,18 @@ function OrderCard({
<span className="pc-order-card__detail"> <span className="pc-order-card__detail">
查看详情 <RightOutlined /> 查看详情 <RightOutlined />
</span> </span>
{order.status === 'pending_payment' && onPay ? (
<Button
type="primary"
size="small"
onClick={event => {
event.stopPropagation()
onPay()
}}
>
去支付
</Button>
) : null}
</div> </div>
</div> </div>
</article> </article>
@@ -242,6 +256,7 @@ export function OrderListPage() {
key={order.id} key={order.id}
order={order} order={order}
onOpen={() => navigate(`/orders/${order.id}`)} onOpen={() => navigate(`/orders/${order.id}`)}
onPay={() => navigate(`/orders/${order.id}?pay=1`)}
/> />
))} ))}
</div> </div>