63 lines
1.5 KiB
TypeScript
63 lines
1.5 KiB
TypeScript
/**
|
||
* API配置文件
|
||
* 统一管理所有API相关配置
|
||
*/
|
||
|
||
// API基础地址配置
|
||
export const API_CONFIG = {
|
||
// 开发环境API地址
|
||
// BASE_URL: 'http://192.168.1.4:4101',
|
||
BASE_URL: 'https://ele.ccttiot.com/prod-api',
|
||
|
||
// 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
|