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

@@ -7,7 +7,8 @@ import type {
ExtractorInput,
ExtractorResult,
ImportResult,
LogLevel
LogLevel,
ExtractionProgress
} from '../../types/extractor.types'
import { DataImportService } from '../database/data-importer'
@@ -64,7 +65,16 @@ export class ExtractorService {
// Merge downloaded files (original logic preserved)
if (result.downloadedFiles.length > 0) {
input.onProgress?.('正在合并文件...', 95)
const totalBatches = result.downloadedFiles.length
const totalPoints = 1 + totalBatches + 2
const progressPerPoint = 100 / totalPoints
const mergeProgress = (1 + totalBatches) * progressPerPoint
const importProgress = (1 + totalBatches + 1) * progressPerPoint
input.onProgress?.('正在合并文件...', mergeProgress, {
phase: 'merging',
totalBatches
})
const mergeResult = await this.mergeFiles(result.downloadedFiles)
result.mergedFile = mergeResult.mergedFile
result.recordCount = mergeResult.recordCount
@@ -79,7 +89,11 @@ export class ExtractorService {
// Auto-import to database if merge was successful
if (result.mergedFile) {
input.onProgress?.('正在写入数据库...', 98)
const importProgress = (1 + totalBatches + 1) * progressPerPoint
input.onProgress?.('正在写入数据库...', importProgress, {
phase: 'importing',
totalBatches
})
const importResult = await this.importToDatabaseWithLogging(
result.mergedFile,
input.onLog