feat: 1. 将大部分的请求从fetch改成axios方便管理。
2. 给文档类型添加入口模块和相关数据的渲染。并且给文档类型进行功能上的角色权限区分 3. 新增角色权限管理页面
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { postgrestGet, postgrestPut } from "../postgrest-client";
|
||||
import axios from 'axios';
|
||||
|
||||
/**
|
||||
* 从不同格式的 API 响应中提取数据
|
||||
@@ -134,26 +135,18 @@ export async function submitCrossCheckingOpinion(
|
||||
evaluation_result_id: opinionData.reviewPointResultId
|
||||
};
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/admin/cross_review/proposals`, {
|
||||
method: 'POST',
|
||||
const response = await axios.post(`${API_BASE_URL}/admin/cross_review/proposals`, requestData, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify(requestData)
|
||||
}
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.message || '提交失败');
|
||||
}
|
||||
|
||||
return {
|
||||
data: {
|
||||
success: true,
|
||||
message: '意见提交成功',
|
||||
data: data
|
||||
data: response.data
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
@@ -190,23 +183,19 @@ export async function getCrossCheckingOpinions(
|
||||
// 如果没传userId,默认用1
|
||||
const realUserId = userId ?? 1;
|
||||
// 实际后端API调用,拼接API_BASE_URL
|
||||
const response = await fetch(`${API_BASE_URL}/admin/cross_review/proposals/document`, {
|
||||
method: 'POST',
|
||||
const response = await axios.post(`${API_BASE_URL}/admin/cross_review/proposals/document`, {
|
||||
user_id: realUserId,
|
||||
document_id: documentId, // 如果后端需要document_id可以加上
|
||||
page,
|
||||
page_size: pageSize
|
||||
}, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
user_id: realUserId,
|
||||
document_id: documentId, // 如果后端需要document_id可以加上
|
||||
page,
|
||||
page_size: pageSize
|
||||
})
|
||||
}
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error('获取意见列表失败');
|
||||
}
|
||||
const data = await response.json();
|
||||
|
||||
const data = response.data;
|
||||
console.log('最原始的返回data', data);
|
||||
// 处理新的数据结构,支持分页
|
||||
const responseData = data.data || data;
|
||||
@@ -328,23 +317,24 @@ export async function performOpinionAction(
|
||||
throw new Error('无效的操作类型');
|
||||
}
|
||||
|
||||
const response = await fetch(endpoint, {
|
||||
method: actionData.action === 'withdraw_opinion' ? 'DELETE' : 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify(requestBody)
|
||||
});
|
||||
const response = actionData.action === 'withdraw_opinion'
|
||||
? await axios.delete(endpoint, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
})
|
||||
: await axios.post(endpoint, requestBody, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
const data = response.data;
|
||||
|
||||
console.log('返回的意见列表数据',data);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.message || data.error || '操作失败');
|
||||
}
|
||||
|
||||
return {
|
||||
data: {
|
||||
success: true,
|
||||
@@ -417,20 +407,15 @@ export async function checkProposalVotes(
|
||||
document_id: documentId
|
||||
};
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/admin/cross_review/proposals/document/check_pending_votes`, {
|
||||
method: 'POST',
|
||||
const response = await axios.post(`${API_BASE_URL}/admin/cross_review/proposals/document/check_pending_votes`, requestData, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify(requestData)
|
||||
}
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
const data = response.data;
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.message || '检查失败');
|
||||
}
|
||||
console.log("检查投票数据",data);
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { UPLOAD_URL } from '../../config/api-config';
|
||||
import axios from 'axios';
|
||||
|
||||
/**
|
||||
* 从不同格式的 API 响应中提取数据
|
||||
@@ -146,8 +147,8 @@ export async function uploadCrossCheckingDocument(
|
||||
|
||||
// 发送请求
|
||||
try {
|
||||
console.log('【交叉评查上传】开始fetch请求...');
|
||||
const headers: HeadersInit = {
|
||||
console.log('【交叉评查上传】开始axios请求...');
|
||||
const headers: Record<string, string> = {
|
||||
'X-File-Name': encodeURIComponent(fileName),
|
||||
};
|
||||
|
||||
@@ -155,50 +156,35 @@ export async function uploadCrossCheckingDocument(
|
||||
headers['Authorization'] = `Bearer ${token}`;
|
||||
}
|
||||
|
||||
const response = await fetch(uploadUrl, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: formData
|
||||
const response = await axios.post(uploadUrl, formData, {
|
||||
headers
|
||||
});
|
||||
|
||||
|
||||
console.log('【交叉评查上传】收到服务器响应:', { status: response.status, statusText: response.statusText });
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
console.error(`【交叉评查上传】上传失败 (${response.status}): ${errorText}`);
|
||||
return {
|
||||
error: `上传失败: ${response.status} ${response.statusText} - ${errorText}`,
|
||||
status: response.status
|
||||
};
|
||||
}
|
||||
|
||||
console.log('【交叉评查上传】开始解析JSON响应');
|
||||
let responseData;
|
||||
try {
|
||||
responseData = await response.json();
|
||||
console.log('【交叉评查上传】JSON响应解析成功:', responseData);
|
||||
} catch (jsonError) {
|
||||
console.error('【交叉评查上传】JSON解析失败:', jsonError);
|
||||
return {
|
||||
error: `解析响应JSON失败: ${jsonError instanceof Error ? jsonError.message : '未知错误'}`,
|
||||
status: 500
|
||||
};
|
||||
}
|
||||
|
||||
const extractedData = extractApiData<CrossCheckingFileUploadResponse>(responseData);
|
||||
|
||||
console.log('【交叉评查上传】JSON响应解析成功:', response.data);
|
||||
|
||||
const extractedData = extractApiData<CrossCheckingFileUploadResponse>(response.data);
|
||||
console.log('【交叉评查上传】提取的数据:', extractedData);
|
||||
|
||||
|
||||
if (!extractedData) {
|
||||
console.error('【交叉评查上传】无法提取数据');
|
||||
return { error: '处理上传响应失败', status: 500 };
|
||||
}
|
||||
|
||||
|
||||
console.log('【交叉评查上传】上传成功,返回数据');
|
||||
return { data: extractedData as CrossCheckingFileUploadResponse };
|
||||
} catch (fetchError) {
|
||||
console.error('【交叉评查上传】fetch请求失败:', fetchError);
|
||||
return {
|
||||
error: `fetch请求错误: ${fetchError instanceof Error ? fetchError.message : '未知错误'}`,
|
||||
} catch (axiosError) {
|
||||
console.error('【交叉评查上传】axios请求失败:', axiosError);
|
||||
if (axios.isAxiosError(axiosError)) {
|
||||
const errorText = axiosError.response?.data || axiosError.message;
|
||||
return {
|
||||
error: `上传失败: ${axiosError.response?.status || 500} ${axiosError.response?.statusText || ''} - ${errorText}`,
|
||||
status: axiosError.response?.status || 500
|
||||
};
|
||||
}
|
||||
return {
|
||||
error: `axios请求错误: ${axiosError instanceof Error ? axiosError.message : '未知错误'}`,
|
||||
status: 500
|
||||
};
|
||||
}
|
||||
@@ -258,14 +244,12 @@ export async function batchUploadAndAssignCrossCheckingFiles(
|
||||
};
|
||||
formData.append('upload_info', JSON.stringify(uploadInfo));
|
||||
formData.append('assign_user_ids', JSON.stringify(assignUserIds));
|
||||
const headers: HeadersInit = {};
|
||||
const headers: Record<string, string> = {};
|
||||
if (token) headers['Authorization'] = `Bearer ${token}`;
|
||||
const response = await fetch(uploadUrl, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: formData
|
||||
const response = await axios.post(uploadUrl, formData, {
|
||||
headers
|
||||
});
|
||||
const result = await response.json();
|
||||
const result = response.data;
|
||||
if (result && result.success) {
|
||||
successes.push({ file: fileInfo, result });
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { API_BASE_URL } from '../../config/api-config';
|
||||
import { postgrestPut } from '../postgrest-client';
|
||||
import axios from 'axios';
|
||||
|
||||
// 交叉评查任务状态枚举
|
||||
export enum CrossCheckingTaskStatus {
|
||||
@@ -393,33 +394,28 @@ export async function getUserTaskDocuments(page: number = 1, pageSize: number =
|
||||
// 拼接绝对路径,去除多余斜杠
|
||||
const base = API_BASE_URL.endsWith('/') ? API_BASE_URL.slice(0, -1) : API_BASE_URL;
|
||||
const url = `${base}/admin/cross_review/tasks/user_tasks`;
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${jwtToken || ''}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
page: page,
|
||||
page_size: pageSize
|
||||
})
|
||||
|
||||
const response = await axios.post(url, {
|
||||
page: page,
|
||||
page_size: pageSize
|
||||
}, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${jwtToken || ''}`
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return {
|
||||
success: false,
|
||||
error: `HTTP ${response.status}: ${response.statusText}`
|
||||
};
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: result
|
||||
data: response.data
|
||||
};
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
return {
|
||||
success: false,
|
||||
error: `HTTP ${error.response?.status}: ${error.response?.statusText || error.message}`
|
||||
};
|
||||
}
|
||||
return {
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : '获取用户任务列表失败'
|
||||
@@ -441,33 +437,28 @@ export async function getTaskDocuments(taskId: number, page: number = 1, pageSiz
|
||||
const base = API_BASE_URL.endsWith('/') ? API_BASE_URL.slice(0, -1) : API_BASE_URL;
|
||||
const url = `${base}/admin/cross_review/tasks/${taskId}/documents`;
|
||||
// console.log('最终请求URL:', url);
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${jwtToken || ''}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
page: page,
|
||||
page_size: pageSize
|
||||
})
|
||||
|
||||
const response = await axios.post(url, {
|
||||
page: page,
|
||||
page_size: pageSize
|
||||
}, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${jwtToken || ''}`
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return {
|
||||
success: false,
|
||||
error: `HTTP ${response.status}: ${response.statusText}`
|
||||
};
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: result
|
||||
data: response.data
|
||||
};
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
return {
|
||||
success: false,
|
||||
error: `HTTP ${error.response?.status}: ${error.response?.statusText || error.message}`
|
||||
};
|
||||
}
|
||||
return {
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : '获取任务文档列表失败'
|
||||
|
||||
Reference in New Issue
Block a user