* 从指定路径执行导入(支持拖拽)
(filePath: string)
| 221 | * 从指定路径执行导入(支持拖拽) |
| 222 | */ |
| 223 | async function importFileFromPath(filePath: string): Promise<{ |
| 224 | success: boolean |
| 225 | error?: string |
| 226 | diagnostics?: ImportDiagnosticsInfo |
| 227 | }> { |
| 228 | try { |
| 229 | isImporting.value = true |
| 230 | importProgress.value = { |
| 231 | stage: 'detecting', |
| 232 | progress: 0, |
| 233 | message: '', |
| 234 | } |
| 235 | |
| 236 | const queue: ImportProgress[] = [] |
| 237 | let isProcessing = false |
| 238 | let currentStage = 'reading' |
| 239 | let lastStageTime = Date.now() |
| 240 | const MIN_STAGE_TIME = 1000 |
| 241 | |
| 242 | const processQueue = async () => { |
| 243 | if (isProcessing) return |
| 244 | isProcessing = true |
| 245 | |
| 246 | while (queue.length > 0) { |
| 247 | const next = queue[0] |
| 248 | |
| 249 | if (next.stage !== currentStage) { |
| 250 | const elapsed = Date.now() - lastStageTime |
| 251 | if (elapsed < MIN_STAGE_TIME) { |
| 252 | await new Promise((resolve) => setTimeout(resolve, MIN_STAGE_TIME - elapsed)) |
| 253 | } |
| 254 | currentStage = next.stage |
| 255 | lastStageTime = Date.now() |
| 256 | } |
| 257 | |
| 258 | importProgress.value = queue.shift()! |
| 259 | } |
| 260 | isProcessing = false |
| 261 | } |
| 262 | |
| 263 | const importResult = await useImportService().importFile(filePath, undefined, (progress) => { |
| 264 | if (progress.stage === 'done') return |
| 265 | queue.push(progress) |
| 266 | processQueue() |
| 267 | }) |
| 268 | |
| 269 | while (queue.length > 0 || isProcessing) { |
| 270 | await new Promise((resolve) => setTimeout(resolve, 100)) |
| 271 | } |
| 272 | |
| 273 | const elapsed = Date.now() - lastStageTime |
| 274 | if (elapsed < MIN_STAGE_TIME) { |
| 275 | await new Promise((resolve) => setTimeout(resolve, MIN_STAGE_TIME - elapsed)) |
| 276 | } |
| 277 | |
| 278 | if (importProgress.value) { |
| 279 | importProgress.value.progress = 100 |
| 280 | } |
no test coverage detected