2026-06-10 14:06:16 +08:00
|
|
|
import { useSmoothedProgress } from "../../hooks/useSmoothedProgress";
|
2026-06-11 20:38:35 +08:00
|
|
|
import type { ReactNode } from "react";
|
2026-06-10 14:06:16 +08:00
|
|
|
|
|
|
|
|
interface EcommerceProgressBarProps {
|
|
|
|
|
status: "idle" | "generating" | "done" | "failed" | string;
|
|
|
|
|
label?: string;
|
2026-06-11 20:38:35 +08:00
|
|
|
onCancel?: () => void;
|
2026-06-10 14:06:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function mapStatus(status: string): "running" | "completed" | "failed" {
|
|
|
|
|
if (status === "done") return "completed";
|
|
|
|
|
if (status === "failed") return "failed";
|
|
|
|
|
if (status === "generating" || status === "modeling") return "running";
|
|
|
|
|
return "running";
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-11 20:38:35 +08:00
|
|
|
export function EcommerceProgressBar({ status, label, onCancel }: EcommerceProgressBarProps) {
|
2026-06-10 14:06:16 +08:00
|
|
|
const progress = mapStatus(status) === "running" ? 50 : 100;
|
|
|
|
|
const smoothed = useSmoothedProgress(progress, mapStatus(status));
|
|
|
|
|
|
|
|
|
|
if (status === "idle") return null;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="ecommerce-progress-bar">
|
|
|
|
|
<span className="ecommerce-progress-bar__label">{label || "AI 正在生成"}</span>
|
2026-06-11 20:38:35 +08:00
|
|
|
{onCancel ? (
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
className="ecommerce-progress-bar__cancel"
|
|
|
|
|
onClick={(e) => { e.stopPropagation(); onCancel(); }}
|
|
|
|
|
title="取消生成"
|
|
|
|
|
aria-label="取消生成"
|
|
|
|
|
>
|
|
|
|
|
取消
|
|
|
|
|
</button>
|
|
|
|
|
) : null}
|
2026-06-10 14:06:16 +08:00
|
|
|
<div className="ecommerce-progress-bar__track">
|
|
|
|
|
<div className="ecommerce-progress-bar__fill" style={{ width: `${smoothed}%` }} />
|
|
|
|
|
</div>
|
|
|
|
|
<span className="ecommerce-progress-bar__value">{smoothed}%</span>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|