「分步结账」包含在 Pro 里,开通会员后显示预览。
用法
import { ShopCheckout } from './ShopCheckout.jsx'
// Without onPlaceOrder the checkout runs on its sample order. Wire it to your shop:
<ShopCheckout
locale="en"
currency="USD"
freeFrom={80}
items={bag.lines} // [{ id, name, variant, price, qty, image }]
methods={[
{ id: 'standard', label: 'Standard', eta: 'In 2–4 days', price: 5 },
{ id: 'express', label: 'Express', eta: 'Tomorrow', price: 9 },
]}
customer={account.address} // { name, phone, region, street }, or null for a blank form
card={account.card} // { last4, expiry }, or null when no card is saved
loading={bag.loading}
error={bag.error}
onRetry={bag.reload}
onPlaceOrder={async (order) => (await api.placeOrder(order)).number}
onDone={() => router.push('/')}
/>属性
| 属性 | 类型 | 默认值 | 作用 |
|---|---|---|---|
locale | 'en' | 'zh-CN' | 'es' | 'ja' | 'en' | 内置文字和示例订单的语言。 |
items | Array<{ id, name, variant, price, qty, image? }> | sample bag | 要结算的商品,显示在订单明细里。传空数组显示空状态。`image` 是商品图片,不传时画一个素色包裹。 |
currency | string | by locale | 所有金额使用的 ISO 货币代码。 |
methods | Array<{ id, label, eta, price }> | standard and express | 配送方式。第一种在达到 `freeFrom` 后包邮,其余始终按价格收费。 |
freeFrom | number | by locale | 商品金额达到此数时,第一种配送方式免运费。 |
customer | { name, phone, region, street } | null | sample customer | 为老顾客预填收货信息;传 null 则从空白开始。 |
card | { last4, expiry } | null | sample card | 优先提供的已保存银行卡;传 null 则直接填写新卡。 |
loading | boolean | false | 加载时显示结算页骨架。 |
error | boolean | string | false | 显示带重试按钮的错误提示;传字符串可替换说明。 |
onPlaceOrder | ({ items, address, method, payment, totals }) => Promise<string | void> | — | 提交订单;返回订单号即可显示。抛出错误时,确认页会提示支付没有成功。 |
onDone / onBrowse / onRetry | () => void | — | 分别在下单后、没有商品时和出错提示中调用。 |
labels | object | — | 替换任意内置文字(键名见 copy.js),包括字段名和错误提示。 |
className | string | — | 加在根元素上;其他属性也会传给根元素。 |
装进你的项目
Pro 包含这个区块的完整源码。复制指令,让你的 Agent 把它安装到项目中。
ShopCheckout.jsxshop-checkout.csscopy.jskit.jsxkit.cssui/base-button/ui/empty-state/ui/rolling-number/ui/alert-banner/ui/shake-feedback/ui/success-check/ui/checkbox/ui/form-field/ui/radio-group/ui/text-input/ui/skeleton-shimmer/ui/step-progress/tokens.cssREADME.md
区块本身、样式和文案、共用的 kit、用到的组件和 tokens.css 会一起装进同一个文件夹。
