Files
ftb-project-management/apps/web/components/product/RequirementTable.tsx
Script Generator eca65f1bce feat: 实现产品/项目/版本三大模块完整功能
- 产品列表:拖拽排序持久化、编辑弹窗、删除校验(活跃版本需迁移)
- 项目列表:新建项目表单(产品选择+重名校验)、产品筛选、版本归属修复
- 版本列表:新建版本表单(迭代类型自动生成版本号)、状态/项目筛选、倒序排列
- 项目详情页:概览统计、人员墙(参与次数)、版本时间线(阶段流水线+进度条)
- 全局优化:筛选栏统一为header下方固定行、按钮颜色改为主题蓝、API探测300ms、store缓存
- 数据持久化到localStorage,支持离线开发

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-08 17:11:23 +08:00

137 lines
5.3 KiB
TypeScript

'use client';
import { RequirementStatus } from '@ftb/shared';
import { Pencil, Trash2 } from 'lucide-react';
import { RequirementStatusBadge } from './RequirementStatusBadge';
import { PRIORITY_LABEL, REQUIREMENT_STATUS_LABEL } from '@/lib/constants';
interface RequirementItem {
id: string;
title: string;
description: string;
status: RequirementStatus;
priority: number;
creator?: { id: string; name: string };
createdAt: string;
}
interface Props {
requirements: RequirementItem[];
statusFilter: RequirementStatus | null;
onFilterChange: (status: RequirementStatus | null) => void;
onEdit: (req: RequirementItem) => void;
onStatusChange: (id: string, status: RequirementStatus) => void;
onDelete: (id: string) => void;
onCreate: () => void;
}
const ALL_STATUSES = Object.values(RequirementStatus);
export function RequirementTable({
requirements,
statusFilter,
onFilterChange,
onEdit,
onDelete,
onCreate,
}: Props) {
return (
<div>
<div className="mb-4 flex flex-wrap items-center justify-between gap-3">
<div className="flex flex-wrap gap-1">
<FilterChip active={!statusFilter} onClick={() => onFilterChange(null)}>
</FilterChip>
{ALL_STATUSES.map((s) => (
<FilterChip key={s} active={statusFilter === s} onClick={() => onFilterChange(s)}>
{REQUIREMENT_STATUS_LABEL[s]}
</FilterChip>
))}
</div>
<button
onClick={onCreate}
className="flex h-8 items-center gap-1 rounded-lg bg-[var(--accent)] px-3 text-[13px] font-medium text-white shadow-[var(--shadow-sm)] transition-colors hover:bg-[var(--accent-hover)]"
>
+
</button>
</div>
{requirements.length === 0 ? (
<div className="rounded-2xl border border-dashed border-[var(--line)] bg-[var(--bg-card)] py-16 text-center">
<p className="text-[14px] font-medium text-[var(--ink-soft)]"></p>
<p className="mt-1.5 text-[12.5px] text-[var(--ink-muted)]">"新建需求"</p>
</div>
) : (
<div className="overflow-hidden rounded-2xl border border-[var(--line)] bg-[var(--bg-card)] shadow-[var(--shadow-sm)]">
<table className="w-full text-left text-[13px]">
<thead>
<tr className="border-b border-[var(--line)] bg-[var(--bg-subtle)]">
<th className="px-4 py-2.5 text-[11.5px] font-medium uppercase tracking-wide text-[var(--ink-muted)]"></th>
<th className="px-4 py-2.5 text-[11.5px] font-medium uppercase tracking-wide text-[var(--ink-muted)]"></th>
<th className="px-4 py-2.5 text-[11.5px] font-medium uppercase tracking-wide text-[var(--ink-muted)]"></th>
<th className="px-4 py-2.5 text-[11.5px] font-medium uppercase tracking-wide text-[var(--ink-muted)]"></th>
<th className="px-4 py-2.5 text-right text-[11.5px] font-medium uppercase tracking-wide text-[var(--ink-muted)]"></th>
</tr>
</thead>
<tbody>
{requirements.map((req) => (
<tr key={req.id} className="border-b border-[var(--line-soft)] last:border-0 hover:bg-[var(--bg-subtle)]">
<td className="max-w-md truncate px-4 py-3 font-medium text-[var(--ink)]" title={req.title}>
{req.title}
</td>
<td className="px-4 py-3">
<RequirementStatusBadge status={req.status} />
</td>
<td className="px-4 py-3 text-[var(--ink-soft)]">{PRIORITY_LABEL[req.priority] || '无'}</td>
<td className="px-4 py-3 text-[var(--ink-soft)]">{req.creator?.name || '—'}</td>
<td className="px-4 py-3 text-right">
<div className="inline-flex gap-1">
<button
onClick={() => onEdit(req)}
className="rounded-md p-1.5 text-[var(--ink-muted)] transition-colors hover:bg-[var(--bg-hover)] hover:text-[var(--ink)]"
title="编辑"
>
<Pencil className="h-3.5 w-3.5" strokeWidth={1.75} />
</button>
<button
onClick={() => onDelete(req.id)}
className="rounded-md p-1.5 text-[var(--ink-muted)] transition-colors hover:bg-red-50 hover:text-red-600"
title="删除"
>
<Trash2 className="h-3.5 w-3.5" strokeWidth={1.75} />
</button>
</div>
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</div>
);
}
function FilterChip({
active,
onClick,
children,
}: {
active: boolean;
onClick: () => void;
children: React.ReactNode;
}) {
return (
<button
onClick={onClick}
className={`h-7 rounded-md px-2.5 text-[12.5px] transition-colors ${
active
? 'bg-[var(--accent)] text-white'
: 'border border-[var(--line)] bg-[var(--bg-card)] text-[var(--ink-soft)] hover:border-[var(--ink-muted)] hover:text-[var(--ink)]'
}`}
>
{children}
</button>
);
}