feat: 1. 将大部分的请求从fetch改成axios方便管理。
2. 给文档类型添加入口模块和相关数据的渲染。并且给文档类型进行功能上的角色权限区分 3. 新增角色权限管理页面
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { postgrestGet, type PostgrestParams } from '../postgrest-client';
|
||||
import dayjs from 'dayjs';
|
||||
import { UPLOAD_URL } from '../../config/api-config';
|
||||
import axios from 'axios';
|
||||
// import { API_BASE_URL } from '../client';
|
||||
|
||||
/**
|
||||
@@ -213,26 +214,15 @@ export async function uploadContractTemplate(
|
||||
}
|
||||
|
||||
// 发送请求
|
||||
const response = await fetch(uploadUrl, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: formData
|
||||
const response = await axios.post(uploadUrl, formData, {
|
||||
headers
|
||||
});
|
||||
|
||||
|
||||
console.log('【合同模板上传】服务器响应状态:', response.status);
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
console.error('【合同模板上传】服务器返回错误:', errorText);
|
||||
return {
|
||||
error: `服务器错误: ${response.status} ${response.statusText}`,
|
||||
status: response.status
|
||||
};
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
const result = response.data;
|
||||
console.log('【合同模板上传】服务器返回结果:', result);
|
||||
|
||||
|
||||
if (result.success) {
|
||||
return { data: result.result };
|
||||
} else {
|
||||
@@ -299,26 +289,15 @@ export async function appendContractAttachments(
|
||||
}
|
||||
|
||||
// 发送请求
|
||||
const response = await fetch(uploadUrl, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: formData
|
||||
const response = await axios.post(uploadUrl, formData, {
|
||||
headers
|
||||
});
|
||||
|
||||
|
||||
console.log('【合同附件追加】服务器响应状态:', response.status);
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
console.error('【合同附件追加】服务器返回错误:', errorText);
|
||||
return {
|
||||
error: `服务器错误: ${response.status} ${response.statusText}`,
|
||||
status: response.status
|
||||
};
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
const result = response.data;
|
||||
console.log('【合同附件追加】服务器返回结果:', result);
|
||||
|
||||
|
||||
if (result.success) {
|
||||
return { data: result.result };
|
||||
} else {
|
||||
@@ -388,12 +367,12 @@ export async function uploadDocumentToServer(
|
||||
// console.log('【调试】准备发送请求到服务器:', uploadUrl);
|
||||
|
||||
// 发送请求
|
||||
// const response = await fetch(`${API_BASE_URL}/admin/documents/upload`, {
|
||||
// const response = await axios.post(`${API_BASE_URL}/admin/documents/upload`, ...
|
||||
try {
|
||||
// console.log('【调试】开始fetch请求...');
|
||||
// console.log('【调试】开始axios请求...');
|
||||
|
||||
// 构建请求头,只在有JWT token时添加Authorization
|
||||
const headers: HeadersInit = {
|
||||
const headers: Record<string, string> = {
|
||||
'X-File-Name': encodeURIComponent(fileName)
|
||||
};
|
||||
|
||||
@@ -401,37 +380,16 @@ export async function uploadDocumentToServer(
|
||||
headers['Authorization'] = `Bearer ${jwtToken}`;
|
||||
}
|
||||
|
||||
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);
|
||||
// console.log('【上传调试】响应类型:', typeof responseData);
|
||||
// console.log('【上传调试】响应keys:', Object.keys(responseData));
|
||||
} catch (jsonError) {
|
||||
console.error('【调试】JSON解析失败:', jsonError);
|
||||
return {
|
||||
error: `解析响应JSON失败: ${jsonError instanceof Error ? jsonError.message : '未知错误'}`,
|
||||
status: 500
|
||||
};
|
||||
}
|
||||
|
||||
const responseData = response.data;
|
||||
// console.log('【上传调试】服务器原始JSON响应:', responseData);
|
||||
// console.log('【上传调试】响应类型:', typeof responseData);
|
||||
// console.log('【上传调试】响应keys:', Object.keys(responseData));
|
||||
|
||||
const extractedData = extractApiData<FileUploadResponse>(responseData);
|
||||
// console.log('【上传调试】提取后的数据:', extractedData);
|
||||
@@ -449,10 +407,17 @@ export async function uploadDocumentToServer(
|
||||
|
||||
// console.log('【调试】上传成功,返回数据');
|
||||
return { data: extractedData };
|
||||
} 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
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user