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
@@ -1,4 +1,4 @@
import { useState } from 'react'
import { useEffect, useRef, useState } from 'react'
import {
Alert,
App,
@@ -58,15 +58,23 @@ interface ActionFormValues {
interface OrderActionPanelProps {
order: UserOrderDetail
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 [form] = Form.useForm<ActionFormValues>()
const user = useSessionStore(state => state.user)
const [dialog, setDialog] = useState<DialogKind>(null)
const [busy, setBusy] = useState<string | null>(null)
const [payURL, setPayURL] = useState('')
const autoPayTriggered = useRef(false)
const actions = getOrderActionAvailability(order, user?.id)
const checkout = order.checkout
@@ -127,6 +135,14 @@ export function OrderActionPanel({ order, onChanged }: OrderActionPanelProps) {
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>) => {
setBusy(key)
try {