blob: 9c1ef3426e0c430401ff1c5d1b4e9c8dd28d6de4 [file] [log] [blame]
崔向南464e19d2025-06-05 17:46:27 +08001// src/services/bounty.ts
2import { request } from '@umijs/max';
3
4// 查询悬赏列表
5export async function getBountyList(params?: Record<string, any>) {
6 return request('/api/bounties', {
7 method: 'GET',
8 headers: {
9 'Content-Type': 'application/json;charset=UTF-8',
10 },
11 params,
12 });
13}
14
15export async function getBountyDetail(id: number | string) {
16 return request(`/api/bounties/${id}`, {
17 method: 'GET',
18 headers: {
19 'Content-Type': 'application/json;charset=UTF-8',
20 },
21 }).then(data => ({ code: 200, data })); // ✅ 自动包装成标准结构
22}
23
24// 新增:发布悬赏
25export async function publishBounty(params: {
26 title: string;
27 description: string;
28 reward: number;
29 deadline: string;
30}) {
31 return request('/api/bounties/publish', {
32 method: 'POST',
33 headers: {
34 'Content-Type': 'application/json;charset=UTF-8',
35 },
36 data: {
37 ...params,
38 status: 0
39 },
40 });
41}
42
43// 新增:上传附件接口
44export async function uploadBountyAttachment(file: File) {
45 const formData = new FormData();
46 formData.append('file', file);
47
48 return request('/api/bounty-submissions/upload', {
49 method: 'POST',
50 data: formData,
51 // ✅ 移除手动设置 Content-Type
52 // headers: {
53 // 'Content-Type': 'multipart/form-data', // ❌ 浏览器会自动设置 boundary
54 // },
55 });
56}
57
58// 修改:提交悬赏回复(不再处理文件)
59// src/services/bounty/bounty.ts
60// src/services/bounty/bounty.ts
61// src/services/bounty/bounty.ts
62export async function submitBountyReply(params: {
63 bountyId: number;
64 content: string;
65 attachment?: string;
66 file?: File;
67}) {
68 console.log('【提交请求】/api/bounty-submissions 参数:', params);
69
70 const formData = new FormData();
71 formData.append('submission', new Blob([JSON.stringify(params)], { type: 'application/json' }));
72 if (params.file) {
73 formData.append('file', params.file);
74 }
75
76 return request('/api/bounty-submissions', {
77 method: 'POST',
78 data: formData,
79 }).then(res => {
80 console.log('【接口响应】/api/bounty-submissions:', res);
81 // ✅ 确保返回统一结构
82 return {
83 code: res.code || (res ? 200 : 500),
84 data: res.data || res,
85 msg: res.message || '操作成功',
86 };
87 });
88}
89
90
91export async function downloadAttachment(attachmentPath: string): Promise<Blob> {
92 // ✅ 提取文件名
93 const filename = attachmentPath.split('/').pop() || 'file';
94
95 return request(`/api/bounty-submissions/download`, {
96 method: 'GET',
97 params: {
98 filename, // ✅ 只传递文件名
99 },
100 responseType: 'blob',
101 });
102}
103
104export async function getProfile() {
105 return request('/api/system/user/profile', {
106 method: 'GET',
107 headers: {
108 'Content-Type': 'application/json;charset=UTF-8',
109 },
110 });
111}
112
113export async function adoptSubmission(submissionId: number) {
114 return request(`/api/bounty-submissions/${submissionId}/adopt`, {
115 method: 'PUT',
116 headers: {
117 'Content-Type': 'application/json;charset=UTF-8',
118 },
119 });
120}