This commit is contained in:
@@ -101,43 +101,52 @@ async function handleExportToExcel() {
|
||||
return
|
||||
}
|
||||
|
||||
const selectedRows = data.value.filter(item => selectedRowKeys.value.includes(item.id))
|
||||
const rowsNeedTranscription = selectedRows.filter(row => !row.transcriptions)
|
||||
// 异步执行导出,不阻塞
|
||||
executeExport()
|
||||
}
|
||||
|
||||
globalLoading.value = true
|
||||
globalLoadingText.value = rowsNeedTranscription.length ? '正在分析中...' : '正在导出数据...'
|
||||
async function executeExport() {
|
||||
const id = toast.loading('准备导出...', { duration: Infinity })
|
||||
|
||||
try {
|
||||
const selectedRows = data.value.filter(item => selectedRowKeys.value.includes(item.id))
|
||||
const rowsNeedTranscription = selectedRows.filter(row => !row.transcriptions)
|
||||
|
||||
if (rowsNeedTranscription.length) {
|
||||
toast.loading(`分析中 (0/${rowsNeedTranscription.length})...`, { id })
|
||||
|
||||
try {
|
||||
const transcriptions = await getVoiceText(rowsNeedTranscription)
|
||||
rowsNeedTranscription.forEach(row => {
|
||||
rowsNeedTranscription.forEach((row, i) => {
|
||||
const transcription = transcriptions.find(item => item.audio_url === row.audio_url)
|
||||
const index = data.value.findIndex(item => item.id === row.id)
|
||||
if (transcription && index !== -1) {
|
||||
data.value[index].transcriptions = transcription.value
|
||||
}
|
||||
toast.loading(`分析中 (${i + 1}/${rowsNeedTranscription.length})...`, { id })
|
||||
})
|
||||
globalLoadingText.value = '正在导出...'
|
||||
} catch (error) {
|
||||
console.error('获取语音转写失败:', error)
|
||||
toast.warning('部分数据语音转写失败,将导出已有数据')
|
||||
toast.loading('部分语音转写失败,继续导出...', { id })
|
||||
}
|
||||
}
|
||||
|
||||
toast.loading('生成 Excel 文件...', { id })
|
||||
|
||||
const finalSelectedRows = data.value.filter(item => selectedRowKeys.value.includes(item.id))
|
||||
const result = exportBenchmarkDataToExcel(finalSelectedRows, {
|
||||
platform: form.value.platform,
|
||||
formatTime
|
||||
})
|
||||
|
||||
if (result.success) {
|
||||
toast.success(result.message)
|
||||
toast.success(result.message, { id, duration: 3000 })
|
||||
} else {
|
||||
toast.error(result.message)
|
||||
toast.error(result.message, { id, duration: 4000 })
|
||||
}
|
||||
} finally {
|
||||
globalLoading.value = false
|
||||
globalLoadingText.value = ''
|
||||
} catch (error) {
|
||||
console.error('导出失败:', error)
|
||||
toast.error('导出失败,请重试', { id, duration: 4000 })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user