import React, { useState, useEffect } from 'react'; import { Table, Button, Modal, Form, Input, Select, Tag, Space, Message, Typography } from '@arco-design/web-react'; const { TextArea } = Input; const { Title } = Typography; interface Requirement { id: string; title: string; description?: string; priority: 'must' | 'should' | 'could' | 'wont'; category: string; status: string; source?: string; } const PRIORITY_COLOR: Record = { must: 'red', should: 'orange', could: 'blue', wont: 'grey' }; const PRIORITY_LABEL: Record = { must: 'Must', should: 'Should', could: 'Could', wont: "Won't" }; export default function RequirementPage() { const [projectId] = useState('pmp-demo'); const [data, setData] = useState([]); const [loading, setLoading] = useState(false); const [modalVisible, setModalVisible] = useState(false); const [form] = Form.useForm(); const api = (path: string, opts?: RequestInit) => fetch(`/api/projects/${projectId}${path}`, opts); const fetchData = async () => { setLoading(true); try { const res = await api('/requirements'); if (res.ok) { const d = await res.json(); setData(d?.requirements || (Array.isArray(d) ? d : [])) }; } catch { Message.error('获取需求失败'); } setLoading(false); }; useEffect(() => { fetchData(); }, []); const handleAdd = async () => { const values = form.getFieldsValue(); try { const res = await api('/requirements', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(values) }); if (res.ok) { Message.success('添加成功'); setModalVisible(false); form.resetFields(); fetchData(); } else Message.error('添加失败'); } catch { Message.error('添加失败'); } }; const handleCoverage = async () => { try { const res = await api('/requirements/coverage'); if (res.ok) { const d = await res.json(); Modal.info({ title: '需求覆盖率', content: JSON.stringify(d, null, 2) }); } } catch { Message.error('获取覆盖率失败'); } }; const handleConflict = async () => { try { const res = await api('/requirements/detect-conflicts', { method: 'POST' }); if (res.ok) { const d = await res.json(); Modal.info({ title: '冲突检测结果', content: JSON.stringify(d, null, 2) }); } } catch { Message.error('冲突检测失败'); } }; const columns = [ { title: '标题', dataIndex: 'title' }, { title: '优先级', dataIndex: 'priority', render: (v: string) => {PRIORITY_LABEL[v]} }, { title: '分类', dataIndex: 'category' }, { title: '状态', dataIndex: 'status' }, { title: '来源', dataIndex: 'source' }, ]; return (
需求池管理 setModalVisible(false)}>