feat(product): 实现产品需求管理模块(后端 + 前端)
后端:Product Module(CRUD)、Requirement Module(CRUD + 状态机流转)、PrismaService 前端:产品列表页、产品详情页(含需求池 Tab)、Zustand Store、API 封装 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
30
apps/web/components/product/ProductCard.tsx
Normal file
30
apps/web/components/product/ProductCard.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
'use client';
|
||||
|
||||
import { Product } from '@ftb/shared';
|
||||
|
||||
interface ProductWithCount extends Product {
|
||||
_count?: { requirements: number; projects: number };
|
||||
}
|
||||
|
||||
interface Props {
|
||||
product: ProductWithCount;
|
||||
onClick: (id: string) => void;
|
||||
}
|
||||
|
||||
export function ProductCard({ product, onClick }: Props) {
|
||||
return (
|
||||
<div
|
||||
className="cursor-pointer rounded-lg border border-gray-200 p-5 transition-shadow hover:shadow-md"
|
||||
onClick={() => onClick(product.id)}
|
||||
>
|
||||
<h3 className="text-lg font-semibold text-gray-900">{product.name}</h3>
|
||||
{product.description && (
|
||||
<p className="mt-1 text-sm text-gray-500 line-clamp-2">{product.description}</p>
|
||||
)}
|
||||
<div className="mt-4 flex gap-4 text-xs text-gray-400">
|
||||
<span>{product._count?.requirements ?? 0} 需求</span>
|
||||
<span>{product._count?.projects ?? 0} 项目</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
62
apps/web/components/product/ProductForm.tsx
Normal file
62
apps/web/components/product/ProductForm.tsx
Normal file
@@ -0,0 +1,62 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
|
||||
interface Props {
|
||||
initialData?: { name: string; description: string };
|
||||
onSubmit: (data: { name: string; description: string }) => void;
|
||||
onCancel: () => void;
|
||||
}
|
||||
|
||||
export function ProductForm({ initialData, onSubmit, onCancel }: Props) {
|
||||
const [name, setName] = useState(initialData?.name || '');
|
||||
const [description, setDescription] = useState(initialData?.description || '');
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!name.trim()) return;
|
||||
onSubmit({ name: name.trim(), description: description.trim() });
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700">
|
||||
产品名称 <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
className="mt-1 block w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500"
|
||||
placeholder="输入产品名称"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700">描述</label>
|
||||
<textarea
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
rows={3}
|
||||
className="mt-1 block w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500"
|
||||
placeholder="输入产品描述"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex justify-end gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onCancel}
|
||||
className="rounded-md border border-gray-300 px-4 py-2 text-sm text-gray-700 hover:bg-gray-50"
|
||||
>
|
||||
取消
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
className="rounded-md bg-blue-600 px-4 py-2 text-sm text-white hover:bg-blue-700"
|
||||
>
|
||||
{initialData ? '保存' : '创建'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
76
apps/web/components/product/RequirementForm.tsx
Normal file
76
apps/web/components/product/RequirementForm.tsx
Normal file
@@ -0,0 +1,76 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { PRIORITY_LABEL } from '@/lib/constants';
|
||||
|
||||
interface Props {
|
||||
initialData?: { title: string; description: string; priority: number };
|
||||
onSubmit: (data: { title: string; description: string; priority: number }) => void;
|
||||
onCancel: () => void;
|
||||
}
|
||||
|
||||
export function RequirementForm({ initialData, onSubmit, onCancel }: Props) {
|
||||
const [title, setTitle] = useState(initialData?.title || '');
|
||||
const [description, setDescription] = useState(initialData?.description || '');
|
||||
const [priority, setPriority] = useState(initialData?.priority ?? 0);
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!title.trim()) return;
|
||||
onSubmit({ title: title.trim(), description: description.trim(), priority });
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700">
|
||||
需求标题 <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={title}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
className="mt-1 block w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500"
|
||||
placeholder="输入需求标题"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700">描述</label>
|
||||
<textarea
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
rows={4}
|
||||
className="mt-1 block w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500"
|
||||
placeholder="输入需求描述"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700">优先级</label>
|
||||
<select
|
||||
value={priority}
|
||||
onChange={(e) => setPriority(Number(e.target.value))}
|
||||
className="mt-1 block w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500"
|
||||
>
|
||||
{Object.entries(PRIORITY_LABEL).map(([value, label]) => (
|
||||
<option key={value} value={value}>{label}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="flex justify-end gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onCancel}
|
||||
className="rounded-md border border-gray-300 px-4 py-2 text-sm text-gray-700 hover:bg-gray-50"
|
||||
>
|
||||
取消
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
className="rounded-md bg-blue-600 px-4 py-2 text-sm text-white hover:bg-blue-700"
|
||||
>
|
||||
{initialData ? '保存' : '创建'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
16
apps/web/components/product/RequirementStatusBadge.tsx
Normal file
16
apps/web/components/product/RequirementStatusBadge.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
'use client';
|
||||
|
||||
import { RequirementStatus } from '@ftb/shared';
|
||||
import { REQUIREMENT_STATUS_LABEL, REQUIREMENT_STATUS_COLOR } from '@/lib/constants';
|
||||
|
||||
interface Props {
|
||||
status: RequirementStatus;
|
||||
}
|
||||
|
||||
export function RequirementStatusBadge({ status }: Props) {
|
||||
return (
|
||||
<span className={`inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium ${REQUIREMENT_STATUS_COLOR[status]}`}>
|
||||
{REQUIREMENT_STATUS_LABEL[status]}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
101
apps/web/components/product/RequirementTable.tsx
Normal file
101
apps/web/components/product/RequirementTable.tsx
Normal file
@@ -0,0 +1,101 @@
|
||||
'use client';
|
||||
|
||||
import { RequirementStatus } from '@ftb/shared';
|
||||
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,
|
||||
onStatusChange,
|
||||
onDelete,
|
||||
onCreate,
|
||||
}: Props) {
|
||||
return (
|
||||
<div>
|
||||
<div className="mb-4 flex items-center justify-between">
|
||||
<div className="flex gap-2">
|
||||
<button
|
||||
onClick={() => onFilterChange(null)}
|
||||
className={`rounded-full px-3 py-1 text-xs ${!statusFilter ? 'bg-blue-600 text-white' : 'bg-gray-100 text-gray-600 hover:bg-gray-200'}`}
|
||||
>
|
||||
全部
|
||||
</button>
|
||||
{ALL_STATUSES.map((s) => (
|
||||
<button
|
||||
key={s}
|
||||
onClick={() => onFilterChange(s)}
|
||||
className={`rounded-full px-3 py-1 text-xs ${statusFilter === s ? 'bg-blue-600 text-white' : 'bg-gray-100 text-gray-600 hover:bg-gray-200'}`}
|
||||
>
|
||||
{REQUIREMENT_STATUS_LABEL[s]}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<button
|
||||
onClick={onCreate}
|
||||
className="rounded-md bg-blue-600 px-4 py-2 text-sm text-white hover:bg-blue-700"
|
||||
>
|
||||
新建需求
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{requirements.length === 0 ? (
|
||||
<div className="py-12 text-center text-gray-400">暂无需求</div>
|
||||
) : (
|
||||
<table className="w-full text-left text-sm">
|
||||
<thead className="border-b text-xs text-gray-500">
|
||||
<tr>
|
||||
<th className="pb-3 font-medium">标题</th>
|
||||
<th className="pb-3 font-medium">状态</th>
|
||||
<th className="pb-3 font-medium">优先级</th>
|
||||
<th className="pb-3 font-medium">创建者</th>
|
||||
<th className="pb-3 font-medium">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y">
|
||||
{requirements.map((req) => (
|
||||
<tr key={req.id} className="hover:bg-gray-50">
|
||||
<td className="py-3 font-medium text-gray-900">{req.title}</td>
|
||||
<td className="py-3">
|
||||
<RequirementStatusBadge status={req.status} />
|
||||
</td>
|
||||
<td className="py-3 text-gray-600">{PRIORITY_LABEL[req.priority] || '无'}</td>
|
||||
<td className="py-3 text-gray-600">{req.creator?.name || '-'}</td>
|
||||
<td className="py-3">
|
||||
<div className="flex gap-2">
|
||||
<button onClick={() => onEdit(req)} className="text-blue-600 hover:underline">编辑</button>
|
||||
<button onClick={() => onDelete(req.id)} className="text-red-500 hover:underline">删除</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user