生产管理系统 - 企业管理页面联调
This commit is contained in:
37
crop-x/src/lib/api/config.ts
Normal file
37
crop-x/src/lib/api/config.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* filekorolheader: API配置文件 - API客户端配置和认证处理
|
||||
* 功能:API基础配置、认证头部处理、错误处理
|
||||
* 路径:/lib/api/config
|
||||
* 规范:遵循crop-x/docs/开发项目规范.md,统一API调用配置
|
||||
*/
|
||||
|
||||
import { getAuthToken } from '@/utils/token';
|
||||
|
||||
// API基础URL配置 - 开发环境直接使用真实API地址避免重定向问题
|
||||
export const API_BASE_URL = 'https://gitea-admin-hm-smart-agri-app.dev.maimaiag.com';
|
||||
|
||||
// 获取认证头部
|
||||
export const getAuthHeaders = () => {
|
||||
const token = getAuthToken();
|
||||
const headers: Record<string, string> = {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
// 添加缓存控制头部
|
||||
'Cache-Control': 'no-store, no-cache, must-revalidate',
|
||||
'Pragma': 'no-cache',
|
||||
'Expires': '0',
|
||||
};
|
||||
|
||||
if (token) {
|
||||
headers['Authorization'] = `Bearer ${token}`;
|
||||
}
|
||||
|
||||
return headers;
|
||||
};
|
||||
|
||||
// API请求配置
|
||||
export const apiConfig = {
|
||||
baseURL: API_BASE_URL,
|
||||
timeout: 30000, // 30秒超时
|
||||
headers: getAuthHeaders(),
|
||||
};
|
||||
Reference in New Issue
Block a user