121 lines
3.6 KiB
TypeScript
121 lines
3.6 KiB
TypeScript
// =============================================================================
|
||
// 企微IT智能服务台 — H5用户端排查模板 API 调用模块(v5.4 增强)
|
||
// =============================================================================
|
||
// 说明:封装与排查模板相关的所有 HTTP 请求
|
||
// 对应后端 API:/api/troubleshooting-templates
|
||
// 包括:获取模板列表、获取模板详情
|
||
// =============================================================================
|
||
|
||
import apiClient from './index'
|
||
import type { AxiosResponse } from 'axios'
|
||
|
||
// --------------------------------------------------------------------------
|
||
// TypeScript 类型定义 — 与后端 Schema 保持一致
|
||
// --------------------------------------------------------------------------
|
||
|
||
/** 排查步骤路径节点 */
|
||
export interface PathStep {
|
||
/** 节点唯一标识(用于进度追踪) */
|
||
nodeId?: string
|
||
/** 步骤标题 */
|
||
label: string
|
||
/** 步骤状态: done / current / pending */
|
||
status: 'done' | 'current' | 'pending'
|
||
}
|
||
|
||
/** 决策树递归节点 */
|
||
export interface FlowchartNode {
|
||
/** 节点唯一标识 */
|
||
id: string
|
||
/** 节点类型: step / decision */
|
||
type: 'step' | 'decision'
|
||
/** 节点标签文字 */
|
||
label: string
|
||
/** 节点状态: done / current / pending */
|
||
status?: 'done' | 'current' | 'pending'
|
||
/** 子步骤列表(step 类型的操作明细) */
|
||
children?: FlowchartNode[]
|
||
/** "是" 分支(decision 类型)/ 下一步(step 类型) */
|
||
yes_branch?: FlowchartNode
|
||
/** "否" 分支(decision 类型) */
|
||
no_branch?: FlowchartNode
|
||
}
|
||
|
||
/** 排查模板对象(对应后端 TroubleshootingTemplateResponse) */
|
||
export interface TroubleshootingTemplate {
|
||
/** 模板唯一标识 */
|
||
id: string
|
||
/** 模板名称 */
|
||
name: string
|
||
/** 分类: vpn/email/system/account */
|
||
category: string
|
||
/** 排障步骤路径 */
|
||
path_steps: PathStep[]
|
||
/** 流程图定义 */
|
||
flowchart: FlowchartNode
|
||
/** 是否启用 */
|
||
is_active: boolean
|
||
/** 创建时间 */
|
||
created_at: string
|
||
/** 更新时间 */
|
||
updated_at: string
|
||
}
|
||
|
||
/** 排查模板列表响应 */
|
||
export interface TroubleshootingTemplateListData {
|
||
/** 模板列表 */
|
||
items: TroubleshootingTemplate[]
|
||
/** 总数 */
|
||
total: number
|
||
}
|
||
|
||
/** 查询参数 */
|
||
export interface TroubleshootingTemplateQuery {
|
||
/** 按分类过滤(可选) */
|
||
category?: string
|
||
/** 页码(从1开始) */
|
||
page?: number
|
||
/** 每页数量 */
|
||
page_size?: number
|
||
}
|
||
|
||
// --------------------------------------------------------------------------
|
||
// API 函数
|
||
// --------------------------------------------------------------------------
|
||
|
||
/**
|
||
* 获取排查模板列表
|
||
* 支持按分类过滤和分页
|
||
*
|
||
* @param params - 查询参数
|
||
* @param params.category - 按分类过滤(可选)
|
||
* @param params.page - 页码(可选,默认 1)
|
||
* @param params.page_size - 每页数量(可选,默认 20)
|
||
* @returns 排查模板列表数据
|
||
*/
|
||
export async function getTroubleshootingTemplates(
|
||
params?: TroubleshootingTemplateQuery,
|
||
): Promise<TroubleshootingTemplateListData> {
|
||
const response: AxiosResponse = await apiClient.get('/troubleshooting-templates', {
|
||
params: {
|
||
category: params?.category || undefined,
|
||
page: params?.page || 1,
|
||
page_size: params?.page_size || 20,
|
||
},
|
||
})
|
||
return response
|
||
}
|
||
|
||
/**
|
||
* 获取排查模板详情
|
||
*
|
||
* @param id - 模板ID
|
||
* @returns 排查模板详情
|
||
*/
|
||
export async function getTroubleshootingTemplate(
|
||
id: string,
|
||
): Promise<TroubleshootingTemplate> {
|
||
const response: AxiosResponse = await apiClient.get(`/troubleshooting-templates/${id}`)
|
||
return response
|
||
}
|