Feat: Add segmented progress bar for data extractor with dynamic phase calculation

- Add ExtractionProgress type with phase, batch, and subProgress fields
- Implement dynamic progress calculation: 1 (login) + N (batches) + 2 (merge/import)
- Create SegmentedProgressBar component with 4 colored phases (purple/blue/amber/green)
- Show batch-level progress during download phase (e.g., 批次 1/10)
- Display sub-progress during login phase (连接数据库/解析订单号/登录 ERP)
- Update IPC handler and extractor services to report detailed progress
- Add phase status indicators (completed/active/pending) with color-coded dots
This commit is contained in:
Misaka
2026-03-04 22:16:47 +08:00
parent 4494351e52
commit 2dea1f9556
11 changed files with 299 additions and 46 deletions

View File

@@ -1,7 +1,11 @@
import path from 'path'
import { ERP_LOCATORS } from './locators'
import type { ErpSession } from '../../types/erp.types'
import type { ExtractorCoreInput, ExtractorCoreResult } from '../../types/extractor.types'
import type {
ExtractorCoreInput,
ExtractorCoreResult,
ExtractionProgress
} from '../../types/extractor.types'
/**
* ExtractorCore - Handles all web page operations for data extraction
@@ -22,17 +26,25 @@ export class ExtractorCore {
errors: []
}
// Navigate to extractor page and get popup page + work frame
const totalBatches = this.createBatches(input.orderNumbers, input.batchSize).length
const totalPoints = 1 + totalBatches + 2
const progressPerPoint = 100 / totalPoints
const { popupPage, workFrame } = await this.navigateToExtractorPage(input.session)
// Process orders in batches
const batches = this.createBatches(input.orderNumbers, input.batchSize)
for (let i = 0; i < batches.length; i++) {
const batch = batches[i]
const progress = ((i + 1) / batches.length) * 100
const progress = (1 + (i + 1)) * progressPerPoint
input.onProgress?.(`Processing batch ${i + 1}/${batches.length}`, progress)
const progressExtra: Partial<ExtractionProgress> = {
phase: 'downloading',
currentBatch: i + 1,
totalBatches
}
input.onProgress?.(`处理批次 ${i + 1}/${totalBatches}`, progress, progressExtra)
try {
const filePath = await this.downloadBatch(