feat(ctrt): 完成 CTRT-01~03 响应契约统一 - 三端拦截器+portal_token清理+调用点适配
This commit is contained in:
@@ -60,12 +60,9 @@ interface ApiResponse<T> {
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Axios 实例(继承全局 baseURL)
|
||||
// 复用全局 apiClient(CTRT-01 统一契约)
|
||||
// -----------------------------------------------------------------------------
|
||||
const http = axios.create({
|
||||
baseURL: '/api',
|
||||
timeout: 30000,
|
||||
})
|
||||
import apiClient from './index'
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// 5 个端点
|
||||
@@ -73,29 +70,20 @@ const http = axios.create({
|
||||
|
||||
/** GET /api/troubleshooting-templates — 获取模板列表 */
|
||||
export async function listTemplates(): Promise<TroubleshootingTemplate[]> {
|
||||
const res = await http.get<ApiResponse<TroubleshootingTemplate[]>>(
|
||||
'/troubleshooting-templates'
|
||||
)
|
||||
return res.data.data || []
|
||||
const res = await apiClient.get<TroubleshootingTemplate[]>('/troubleshooting-templates')
|
||||
return res || []
|
||||
}
|
||||
|
||||
/** GET /api/troubleshooting-templates/{id} — 获取模板详情 */
|
||||
export async function getTemplate(id: string): Promise<TroubleshootingTemplate> {
|
||||
const res = await http.get<ApiResponse<TroubleshootingTemplate>>(
|
||||
`/troubleshooting-templates/${id}`
|
||||
)
|
||||
return res.data.data
|
||||
return await apiClient.get<TroubleshootingTemplate>(`/troubleshooting-templates/${id}`)
|
||||
}
|
||||
|
||||
/** POST /api/troubleshooting-templates — 新建模板 */
|
||||
export async function createTemplate(
|
||||
data: TroubleshootingTemplate
|
||||
): Promise<TroubleshootingTemplate> {
|
||||
const res = await http.post<ApiResponse<TroubleshootingTemplate>>(
|
||||
'/troubleshooting-templates',
|
||||
data
|
||||
)
|
||||
return res.data.data
|
||||
return await apiClient.post<TroubleshootingTemplate>('/troubleshooting-templates', data)
|
||||
}
|
||||
|
||||
/** PUT /api/troubleshooting-templates/{id} — 更新模板 */
|
||||
@@ -103,16 +91,12 @@ export async function updateTemplate(
|
||||
id: string,
|
||||
data: TroubleshootingTemplate
|
||||
): Promise<TroubleshootingTemplate> {
|
||||
const res = await http.put<ApiResponse<TroubleshootingTemplate>>(
|
||||
`/troubleshooting-templates/${id}`,
|
||||
data
|
||||
)
|
||||
return res.data.data
|
||||
return await apiClient.put<TroubleshootingTemplate>(`/troubleshooting-templates/${id}`, data)
|
||||
}
|
||||
|
||||
/** DELETE /api/troubleshooting-templates/{id} — 删除模板 */
|
||||
export async function deleteTemplate(id: string): Promise<void> {
|
||||
await http.delete(`/troubleshooting-templates/${id}`)
|
||||
await apiClient.delete(`/troubleshooting-templates/${id}`)
|
||||
}
|
||||
|
||||
/** 工具:把对象格式化成 JSON 字符串(带缩进) */
|
||||
|
||||
Reference in New Issue
Block a user