batch.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import axios from 'axios'
  2. const api = axios.create({
  3. baseURL: '/api',
  4. timeout: 300000 // 5分钟超时,批量处理可能需要较长时间
  5. })
  6. /**
  7. * 文件对
  8. */
  9. export interface FilePair {
  10. json_path: string
  11. image_path: string
  12. }
  13. /**
  14. * 批量处理请求
  15. */
  16. export interface BatchProcessRequest {
  17. template_name: string
  18. file_pairs: FilePair[]
  19. output_dir: string
  20. parallel?: boolean
  21. adjust_rows?: boolean
  22. }
  23. /**
  24. * 批量处理结果
  25. */
  26. export interface BatchProcessResult {
  27. success: boolean
  28. json_path: string
  29. image_path: string
  30. structure_path?: string
  31. filename: string
  32. rows?: number
  33. cols?: number
  34. error?: string
  35. }
  36. /**
  37. * 批量处理响应
  38. */
  39. export interface BatchProcessResponse {
  40. success: boolean
  41. total: number
  42. processed: number
  43. failed: number
  44. results: BatchProcessResult[]
  45. message?: string
  46. }
  47. /**
  48. * 批量绘图请求
  49. */
  50. export interface DrawBatchRequest {
  51. results: BatchProcessResult[]
  52. line_width?: number
  53. line_color?: number[]
  54. }
  55. /**
  56. * 批量绘图响应
  57. */
  58. export interface DrawBatchResponse {
  59. success: boolean
  60. total: number
  61. drawn: number
  62. results: Array<{
  63. success: boolean
  64. image_path?: string
  65. filename: string
  66. error?: string
  67. }>
  68. message?: string
  69. }
  70. /**
  71. * 批量处理文件
  72. */
  73. export async function batchProcess(request: BatchProcessRequest): Promise<BatchProcessResponse> {
  74. const response = await api.post<BatchProcessResponse>('/batch/process', request)
  75. return response.data
  76. }
  77. /**
  78. * 批量绘制表格线
  79. */
  80. export async function batchDraw(request: DrawBatchRequest): Promise<DrawBatchResponse> {
  81. const response = await api.post<DrawBatchResponse>('/batch/draw', request)
  82. return response.data
  83. }
  84. /**
  85. * 健康检查
  86. */
  87. export async function healthCheck(): Promise<{ status: string; service: string }> {
  88. const response = await api.get('/batch/health')
  89. return response.data
  90. }