|
@@ -51,12 +51,39 @@ interface ApiResponse {
|
|
|
|
|
|
|
|
const apiClient = axios.create({
|
|
const apiClient = axios.create({
|
|
|
baseURL: BASE_URL,
|
|
baseURL: BASE_URL,
|
|
|
- timeout: 30000,
|
|
|
|
|
|
|
+ timeout: 60000,
|
|
|
headers: {
|
|
headers: {
|
|
|
'Content-Type': 'application/json',
|
|
'Content-Type': 'application/json',
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+// 请求拦截器:添加 token
|
|
|
|
|
+apiClient.interceptors.request.use(
|
|
|
|
|
+ (config) => {
|
|
|
|
|
+ return config;
|
|
|
|
|
+ },
|
|
|
|
|
+ (error) => {
|
|
|
|
|
+ return Promise.reject(error);
|
|
|
|
|
+ }
|
|
|
|
|
+);
|
|
|
|
|
+
|
|
|
|
|
+// 响应拦截器:统一处理错误
|
|
|
|
|
+apiClient.interceptors.response.use(
|
|
|
|
|
+ (response) => response,
|
|
|
|
|
+ (error) => {
|
|
|
|
|
+ if (error.code === 'ECONNABORTED') {
|
|
|
|
|
+ console.error('请求超时:', error.message);
|
|
|
|
|
+ return Promise.reject(new Error('请求超时,请检查网络连接'));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!error.response) {
|
|
|
|
|
+ console.error('网络错误:', error.message);
|
|
|
|
|
+ return Promise.reject(new Error('网络连接失败,请检查网络'));
|
|
|
|
|
+ }
|
|
|
|
|
+ console.error('API 错误:', error.response?.data || error.message);
|
|
|
|
|
+ return Promise.reject(error);
|
|
|
|
|
+ }
|
|
|
|
|
+);
|
|
|
|
|
+
|
|
|
async function login(authCode: string): Promise<{ token: string; userInfo: UserInfo; expirationTime: string }> {
|
|
async function login(authCode: string): Promise<{ token: string; userInfo: UserInfo; expirationTime: string }> {
|
|
|
const response = await axios.post<LoginResponse>(
|
|
const response = await axios.post<LoginResponse>(
|
|
|
`${BASE_URL}/sys_user/ddh5/login`,
|
|
`${BASE_URL}/sys_user/ddh5/login`,
|
|
@@ -120,10 +147,21 @@ async function callApi(apiItem: Record<string, any>, token: string, userId: stri
|
|
|
}));
|
|
}));
|
|
|
params.userId = userId;
|
|
params.userId = userId;
|
|
|
|
|
|
|
|
- const response = await apiClient.post('/ding/add', params, {
|
|
|
|
|
- headers: { token }
|
|
|
|
|
- });
|
|
|
|
|
- return response.data;
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ const response = await apiClient.post('/ding/add', params, {
|
|
|
|
|
+ headers: { token },
|
|
|
|
|
+ timeout: 90000 // 增加超时时间到90秒
|
|
|
|
|
+ });
|
|
|
|
|
+ return response.data;
|
|
|
|
|
+ } catch (error: any) {
|
|
|
|
|
+ console.error('调用API失败:', error);
|
|
|
|
|
+ // 返回错误响应而不是抛出异常
|
|
|
|
|
+ return {
|
|
|
|
|
+ code: -1,
|
|
|
|
|
+ msg: error?.message || '调用失败,请重试',
|
|
|
|
|
+ data: null
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function getDocumentInfo() {
|
|
async function getDocumentInfo() {
|