ct/app/config/api.ts

62 lines
1.5 KiB
TypeScript
Raw Normal View History

2025-10-13 09:32:00 +08:00
/**
* API配置文件
* API相关配置
*/
// API基础地址配置
export const API_CONFIG = {
// 开发环境API地址
2025-10-30 14:02:13 +08:00
BASE_URL: 'http://192.168.1.4:4101',
2025-10-13 09:32:00 +08:00
// API端点配置
ENDPOINTS: {
// 文章相关API
ARTICLE: {
LIST: '/app/owArticle/list',
GET: '/app/owArticle/get',
CREATE: '/app/owArticle/create',
UPDATE: '/app/owArticle/update',
DELETE: '/app/owArticle/delete'
}
},
// 请求配置
REQUEST: {
TIMEOUT: 10000, // 请求超时时间(毫秒)
RETRY_COUNT: 3, // 重试次数
HEADERS: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
}
} as const
/**
* API URL
* @param endpoint API端点
* @returns API URL
*/
export const getApiUrl = (endpoint: string): string => {
return `${API_CONFIG.BASE_URL}${endpoint}`
}
/**
* API URL
* @param action
* @param id ID
* @returns API URL
*/
export const getArticleApiUrl = (action: keyof typeof API_CONFIG.ENDPOINTS.ARTICLE, id?: string | number): string => {
const endpoint = API_CONFIG.ENDPOINTS.ARTICLE[action]
const baseUrl = getApiUrl(endpoint)
if (id && (action === 'GET' || action === 'UPDATE' || action === 'DELETE')) {
return `${baseUrl}/${id}`
}
return baseUrl
}
// 导出默认配置
export default API_CONFIG