blob: a512fc615d8bf11e52f827b4fa11122ce3813858 [file] [log] [blame]
223010143d966302025-06-07 22:54:40 +08001import React, { useState, useEffect } from 'react';
2import { List, Button, Form, Input, Select, message, Typography, Tag, Divider, Pagination } from 'antd';
3import { BugOutlined } from '@ant-design/icons';
4import WorkAPI from '../api/workApi';
5import type { BugReport } from '../api/otherType';
6
7const { Text } = Typography;
8const { Option } = Select;
9const { TextArea } = Input;
10
11interface BugReportForm {
12 title: string;
13 description: string;
14 severity: 'low' | 'medium' | 'high';
15}
16
17const BugReportSection: React.FC<{ workId: number }> = ({ workId }) => {
18 const [bugs, setBugs] = useState<BugReport[]>([]);
19 const [loading, setLoading] = useState(false);
20 const [form] = Form.useForm();
21 const [currentPage, setCurrentPage] = useState(1);
22 const [pageSize, setPageSize] = useState(5); // 每页显示5条
23
24 // 加载Bug反馈列表
25 useEffect(() => {
26 const loadBugs = async () => {
27 try {
28 setLoading(true);
29 const bugList = await WorkAPI.getBugReports(workId);
30 setBugs(bugList);
31 } catch (error) {
32 message.error('加载Bug反馈失败');
33 } finally {
34 setLoading(false);
35 }
36 };
37
38 loadBugs();
39 }, [workId]);
40
41 // 获取当前页的Bug数据
42 const getCurrentPageBugs = () => {
43 const startIndex = (currentPage - 1) * pageSize;
44 const endIndex = startIndex + pageSize;
45 return bugs.slice(startIndex, endIndex);
46 };
47
48 // 提交Bug反馈
49 const handleSubmit = async (values: BugReportForm) => {
50 try {
51 await WorkAPI.reportBug(workId, values);
52 message.success('Bug反馈提交成功');
53 form.resetFields();
54 // 重新加载Bug列表
55 const bugList = await WorkAPI.getBugReports(workId);
56 setBugs(bugList);
57 // 重置到第一页
58 setCurrentPage(1);
59 } catch (error) {
60 message.error('Bug反馈提交失败');
61 }
62 };
63
64 const getSeverityColor = (severity: string) => {
65 switch (severity) {
66 case 'high': return 'red';
67 case 'medium': return 'orange';
68 default: return 'green';
69 }
70 };
71
72 return (
73 <div className="bug-report-section">
74 <Divider orientation="left">
75 <BugOutlined /> Bug反馈
76 </Divider>
77
78 <Form form={form} onFinish={handleSubmit} layout="vertical">
79 <Form.Item
80 name="title"
81 label="Bug标题"
82 rules={[{ required: true, message: '请输入Bug标题' }]}
83 >
84 <Input placeholder="简要描述Bug" />
85 </Form.Item>
86
87 <Form.Item
88 name="severity"
89 label="严重程度"
90 initialValue="medium"
91 rules={[{ required: true }]}
92 >
93 <Select>
94 <Option value="low">低</Option>
95 <Option value="medium">中</Option>
96 <Option value="high">高</Option>
97 </Select>
98 </Form.Item>
99
100 <Form.Item
101 name="description"
102 label="详细描述"
103 rules={[{ required: true, message: '请详细描述Bug' }]}
104 >
105 <TextArea rows={4} placeholder="请详细描述Bug出现的步骤、现象和预期结果" />
106 </Form.Item>
107
108 <Form.Item>
109 <Button type="primary" htmlType="submit">
110 提交Bug
111 </Button>
112 </Form.Item>
113 </Form>
114
115 <Divider orientation="left">Bug列表</Divider>
116
117 <List
118 dataSource={getCurrentPageBugs()}
119 loading={loading}
120 renderItem={bug => (
121 <List.Item>
122 <div className="bug-item">
123 <div className="bug-header">
124 <Text strong>{bug.title}</Text>
125 <Tag color={getSeverityColor(bug.severity)}>
126 {bug.severity === 'high' ? '严重' : bug.severity === 'medium' ? '中等' : '轻微'}
127 </Tag>
128 </div>
129 <Text type="secondary">报告人: {bug.reporter} | 时间: {new Date(bug.createTime).toLocaleString()}</Text>
130 <div className="bug-content">
131 <Text>{bug.description}</Text>
132 </div>
133 <Tag color={bug.status === 'open' ? 'red' : bug.status === 'resolved' ? 'green' : 'gray'}>
134 {bug.status === 'open' ? '未解决' : bug.status === 'resolved' ? '已解决' : '不予解决'}
135 </Tag>
136 </div>
137 </List.Item>
138 )}
139 />
140
141 <div style={{ textAlign: 'right', marginTop: 16 }}>
142 <Pagination
143 current={currentPage}
144 pageSize={pageSize}
145 total={bugs.length}
146 onChange={(page, size) => {
147 setCurrentPage(page);
148 setPageSize(size);
149 }}
150 showSizeChanger
151 showQuickJumper
152 showTotal={total => `共 ${total} 条`}
153 />
154 </div>
155 </div>
156 );
157};
158
159export default BugReportSection;