blob: 609e6c603a07143a8f1431a5fbb74d2ad5766aa2 [file] [log] [blame]
崔向南464e19d2025-06-05 17:46:27 +08001import React, { useState, useEffect } from 'react';
2import { Table, Button, message, Space } from 'antd';
3import axios from 'axios'; // 新增 axios 导入
4
5const BountyManage: React.FC = () => {
6 const [dataSource, setDataSource] = useState<API.Bounty[]>([]);
7
8 // 加载悬赏列表(修改请求方式)
9 useEffect(() => {
10 const loadBountyList = async () => {
11 try {
12 const res = await axios.get('/api/bounties', { params: { status: [0, 1, 2].join(',') } }); // 替换 get 为 axios.get
13 if (res.data.code === 200) {
14 setDataSource(res.data.data.records || []);
15 }
16 } catch (err) {
17 message.error('加载悬赏列表失败');
18 }
19 };
20 loadBountyList();
21 }, []);
22
23 // 操作列(修改请求方式)
24 const handleClose = async (id: number) => {
25 try {
26 //这个接口哪来的??
27 const res = await axios.post('/api/bounties/close', { id }); // 替换 post 为 axios.post
28 if (res.data.code === 200) {
29 message.success('悬赏已关闭');
30 setDataSource(dataSource.map(item => item.id === id ? { ...item, status: 2 } : item));
31 }
32 } catch (err) {
33 message.error('关闭失败');
34 }
35 };
36
37 const columns = [
38 { title: '我是manage标题', dataIndex: 'title' },
39 { title: '奖励', dataIndex: 'reward' },
40 {
41 title: '状态',
42 dataIndex: 'status',
43 // 显式声明 status 为 number 类型
44 render: (status: number) => status === 0 ? '进行中' : status === 1 ? '已完成' : '已关闭'
45 },
46 {
47 title: '操作',
48 // 显式声明 record 为 API.Bounty 类型(需确保 API.Bounty 已在 types.d.ts 中定义)
49 render: (value: unknown, record: API.Bounty) => (
50 <Space>
51 <Button type="link" onClick={() => handleClose(record.id)}>关闭</Button>
52 </Space>
53 )
54 }
55 ];
56
57 return (
58 <div className="page-container">
59 <h2>悬赏管理</h2>
60 <Table
61 dataSource={dataSource}
62 columns={columns}
63 rowKey="id"
64 pagination={{ pageSize: 10 }}
65 />
66 </div>
67 );
68};
69
70export default BountyManage;