支持浏览器侧素材快照撰写、拒绝报告读时修复、Mermaid PNG 导出与 Word 导出加固。 Co-authored-by: Cursor <cursoragent@cursor.com>
189 lines
6.7 KiB
TypeScript
189 lines
6.7 KiB
TypeScript
"use client";
|
||
|
||
import { Clock, Gauge, Play, RefreshCw, ShieldCheck, Star, Users } from "lucide-react";
|
||
|
||
import type { ReportPlanCandidate } from "@/report-collaboration/api/types";
|
||
import { cn } from "@/lib/utils";
|
||
|
||
interface ReportPlanCardsProps {
|
||
plans: ReportPlanCandidate[];
|
||
selectedPlanId: string | null;
|
||
previewPlanId: string | null;
|
||
onPreview: (planId: string) => void;
|
||
onSelect: (planId: string) => void;
|
||
onStart: (planId: string) => void;
|
||
onRegenerate: () => void;
|
||
selectBusy: boolean;
|
||
startBusy: boolean;
|
||
regenerateBusy: boolean;
|
||
}
|
||
|
||
const STRATEGY_LABELS: Record<string, string> = {
|
||
balanced_review: "均衡审阅",
|
||
parallel_depth: "深度并行",
|
||
focused_fast: "快速聚焦",
|
||
};
|
||
|
||
function costLabel(level: string | null | undefined): string {
|
||
if (level === "low") return "成本 低";
|
||
if (level === "high") return "成本 高";
|
||
return "成本 中";
|
||
}
|
||
|
||
function durationLabel(seconds: number): string {
|
||
if (seconds >= 3600) return `约 ${Math.round(seconds / 3600)} 小时`;
|
||
if (seconds >= 60) return `约 ${Math.round(seconds / 60)} 分钟`;
|
||
return `约 ${seconds} 秒`;
|
||
}
|
||
|
||
/**
|
||
* 候选方案卡组:点击卡片只切换右侧画布预览(纯展示状态),
|
||
* 「采用此方案」才写服务器 selectedPlanId,「开始协作」创建 run。
|
||
*/
|
||
export function ReportPlanCards({
|
||
plans,
|
||
selectedPlanId,
|
||
previewPlanId,
|
||
onPreview,
|
||
onSelect,
|
||
onStart,
|
||
onRegenerate,
|
||
selectBusy,
|
||
startBusy,
|
||
regenerateBusy,
|
||
}: ReportPlanCardsProps) {
|
||
if (plans.length === 0) return null;
|
||
return (
|
||
<div className="flex w-full flex-col gap-2">
|
||
<div className="flex items-center justify-between px-1">
|
||
<span className="text-[13px] font-semibold">我整理了 {plans.length} 条候选协作方案</span>
|
||
<button
|
||
type="button"
|
||
className="rc-btn"
|
||
onClick={onRegenerate}
|
||
disabled={regenerateBusy}
|
||
>
|
||
<RefreshCw className={cn("size-3.5", regenerateBusy && "rc-spin")} aria-hidden />
|
||
重新生成
|
||
</button>
|
||
</div>
|
||
<p className="px-1 text-[12px] text-[var(--rc-text-secondary)]">
|
||
点击卡片在右侧预览协作流程;采用后才会按该方案执行。
|
||
</p>
|
||
{plans.map((plan, index) => {
|
||
const isSelected = plan.id === selectedPlanId;
|
||
const isPreviewed = plan.id === (previewPlanId ?? selectedPlanId ?? plans[0]?.id);
|
||
const invalid = plan.validation && plan.validation.ok === false;
|
||
return (
|
||
<article
|
||
key={plan.id}
|
||
className={cn(
|
||
"rc-plan-card",
|
||
isPreviewed && "rc-plan-card-selected",
|
||
invalid && "rc-plan-card-disabled",
|
||
)}
|
||
onClick={() => onPreview(plan.id)}
|
||
role="button"
|
||
tabIndex={0}
|
||
aria-pressed={isPreviewed}
|
||
onKeyDown={(event) => {
|
||
if (event.key === "Enter" || event.key === " ") {
|
||
event.preventDefault();
|
||
onPreview(plan.id);
|
||
}
|
||
}}
|
||
>
|
||
<div className="flex items-center gap-2">
|
||
<span className="rc-chip">
|
||
{plan.recommended || index === 0 ? (
|
||
<>
|
||
<Star className="size-3" aria-hidden /> 推荐
|
||
</>
|
||
) : (
|
||
`方案 ${index + 1}`
|
||
)}
|
||
</span>
|
||
<span className="rc-chip" style={{ background: "var(--rc-bg-secondary)", color: "var(--rc-text-secondary)" }}>
|
||
{STRATEGY_LABELS[plan.strategy] ?? plan.strategy}
|
||
</span>
|
||
{isSelected ? (
|
||
<span className="rc-chip" style={{ background: "rgba(22, 163, 74, 0.1)", color: "var(--rc-success)" }}>
|
||
已采用
|
||
</span>
|
||
) : null}
|
||
</div>
|
||
<h3 className="text-[13px] font-semibold leading-5">{plan.title}</h3>
|
||
<p className="text-[12px] leading-5 text-[var(--rc-text-secondary)]">{plan.summary}</p>
|
||
<p className="text-[11px] leading-4 text-[var(--rc-text-secondary)] opacity-80">{plan.rationale}</p>
|
||
|
||
<div className="flex flex-wrap items-center gap-1">
|
||
<Users className="size-3 text-[var(--rc-text-secondary)]" aria-hidden />
|
||
{plan.roles.slice(0, 6).map((role) => (
|
||
<span key={role.key} className="rc-chip">
|
||
{role.display_name}
|
||
</span>
|
||
))}
|
||
{plan.roles.length > 6 ? (
|
||
<span className="text-[11px] text-[var(--rc-text-secondary)]">+{plan.roles.length - 6}</span>
|
||
) : null}
|
||
</div>
|
||
|
||
<div className="flex flex-wrap gap-x-4 gap-y-1 text-[11px] text-[var(--rc-text-secondary)]">
|
||
<span className="inline-flex items-center gap-1">
|
||
<Clock className="size-3" aria-hidden />
|
||
{durationLabel(plan.estimated_duration_seconds)}
|
||
</span>
|
||
<span className="inline-flex items-center gap-1">
|
||
<Gauge className="size-3" aria-hidden />
|
||
{costLabel(plan.estimated_cost_level)}
|
||
</span>
|
||
<span className="inline-flex items-center gap-1">
|
||
<ShieldCheck className="size-3" aria-hidden />
|
||
{plan.nodes.length} 节点 · {plan.quality_gates.length} 质量门
|
||
</span>
|
||
</div>
|
||
|
||
{invalid ? (
|
||
<div
|
||
className="rounded-md px-2 py-1 text-[11px]"
|
||
style={{
|
||
background: "rgba(220, 38, 38, 0.08)",
|
||
color: "var(--rc-danger)",
|
||
}}
|
||
>
|
||
方案校验未通过:{plan.validation.errors.join(";")}
|
||
</div>
|
||
) : null}
|
||
|
||
<div className="mt-1 grid grid-cols-2 gap-2">
|
||
<button
|
||
type="button"
|
||
className="rc-btn"
|
||
disabled={isSelected || selectBusy || invalid}
|
||
onClick={(event) => {
|
||
event.stopPropagation();
|
||
onSelect(plan.id);
|
||
}}
|
||
>
|
||
{isSelected ? "已采用" : "采用此方案"}
|
||
</button>
|
||
<button
|
||
type="button"
|
||
className="rc-btn rc-btn-primary"
|
||
disabled={!isSelected || startBusy || invalid}
|
||
onClick={(event) => {
|
||
event.stopPropagation();
|
||
onStart(plan.id);
|
||
}}
|
||
>
|
||
<Play className="size-3.5" aria-hidden />
|
||
开始协作
|
||
</button>
|
||
</div>
|
||
</article>
|
||
);
|
||
})}
|
||
</div>
|
||
);
|
||
}
|