- 需求模块:完整 CRUD、状态流转(采纳/拒绝/关闭)、详情抽屉、产品→项目级联选择 - 加班记录:产品→项目→版本三级联动、月份筛选(MonthPicker)、CSV 导出 - 成员管理:左右布局(部门树+成员列表)、手机号脱敏、初始密码自动生成及规则设置 - 角色管理:卡片列表、系统角色保护、CRUD - 通用组件:FilterSelect 下拉、MonthPicker 月份选择器、Pagination 分页 - 样式统一:状态标签加 border、日期输入现代化、筛选组件风格一致 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
101 lines
3.8 KiB
TypeScript
101 lines
3.8 KiB
TypeScript
'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">
|
|
<Field label="标题" required>
|
|
<input
|
|
type="text"
|
|
value={title}
|
|
onChange={(e) => setTitle(e.target.value)}
|
|
placeholder="一句话描述需求"
|
|
className="h-9 w-full rounded-lg border border-[var(--line)] bg-[var(--bg-card)] px-3 text-[13px] text-[var(--ink)] placeholder:text-[var(--ink-muted)] focus:border-[var(--accent)] focus:outline-none focus:ring-2 focus:ring-[var(--accent-ring)]"
|
|
/>
|
|
</Field>
|
|
<Field label="描述">
|
|
<textarea
|
|
value={description}
|
|
onChange={(e) => setDescription(e.target.value)}
|
|
rows={4}
|
|
placeholder="详细说明需求背景、目标、验收标准"
|
|
className="w-full resize-none rounded-lg border border-[var(--line)] bg-[var(--bg-card)] px-3 py-2 text-[13px] leading-relaxed text-[var(--ink)] placeholder:text-[var(--ink-muted)] focus:border-[var(--accent)] focus:outline-none focus:ring-2 focus:ring-[var(--accent-ring)]"
|
|
/>
|
|
</Field>
|
|
<Field label="优先级">
|
|
<div className="flex gap-1">
|
|
{Object.entries(PRIORITY_LABEL).map(([value, label]) => {
|
|
const v = Number(value);
|
|
const active = priority === v;
|
|
return (
|
|
<button
|
|
key={value}
|
|
type="button"
|
|
onClick={() => setPriority(v)}
|
|
className={`h-7 rounded-md px-2.5 text-[12px] 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)]'
|
|
}`}
|
|
>
|
|
{label}
|
|
</button>
|
|
);
|
|
})}
|
|
</div>
|
|
</Field>
|
|
<FormActions onCancel={onCancel} submitLabel={initialData ? '保存' : '创建'} />
|
|
</form>
|
|
);
|
|
}
|
|
|
|
function Field({ label, required, children }: { label: string; required?: boolean; children: React.ReactNode }) {
|
|
return (
|
|
<div>
|
|
<label className="mb-1.5 block text-[12px] font-medium text-[var(--ink-soft)]">
|
|
{label}
|
|
{required && <span className="ml-0.5 text-red-500">*</span>}
|
|
</label>
|
|
{children}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function FormActions({ onCancel, submitLabel }: { onCancel: () => void; submitLabel: string }) {
|
|
return (
|
|
<div className="flex justify-end gap-2 pt-2">
|
|
<button
|
|
type="button"
|
|
onClick={onCancel}
|
|
className="h-8 rounded-lg border border-[var(--line)] bg-[var(--bg-card)] px-3 text-[13px] text-[var(--ink-soft)] hover:bg-[var(--bg-subtle)] hover:text-[var(--ink)]"
|
|
>
|
|
取消
|
|
</button>
|
|
<button
|
|
type="submit"
|
|
className="h-8 rounded-lg bg-[var(--accent)] px-4 text-[13px] font-medium text-white shadow-[var(--shadow-sm)] hover:bg-[var(--accent-hover)]"
|
|
>
|
|
{submitLabel}
|
|
</button>
|
|
</div>
|
|
);
|
|
}
|