13th_fix combine download
This commit is contained in:
@@ -114,8 +114,8 @@
|
||||
<div class="notification-list">
|
||||
<div v-if="notifications.length === 0" class="empty-state">
|
||||
<el-icon class="empty-icon"><Bell /></el-icon>
|
||||
<div class="empty-title">暂无通知</div>
|
||||
<div class="empty-description">您目前没有未读通知</div>
|
||||
<div class="empty-title">暫無通知</div>
|
||||
<div class="empty-description">您目前沒有未讀通知</div>
|
||||
</div>
|
||||
|
||||
<div v-else>
|
||||
@@ -327,7 +327,7 @@ onMounted(() => {
|
||||
sidebarCollapsed.value = savedCollapsed === 'true'
|
||||
}
|
||||
|
||||
// 暫時禁用 WebSocket 避免連接錯誤
|
||||
// 暫時禁用 WebSocket 連接
|
||||
// initWebSocket()
|
||||
|
||||
// 載入通知
|
||||
|
@@ -92,6 +92,16 @@ export const filesAPI = {
|
||||
responseType: 'blob'
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 下載合併檔案
|
||||
* @param {string} jobUuid - 任務 UUID
|
||||
*/
|
||||
downloadCombineFile(jobUuid) {
|
||||
return request.get(`/files/${jobUuid}/download/combine`, {
|
||||
responseType: 'blob'
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 取得檔案資訊
|
||||
|
@@ -120,13 +120,17 @@ export const useJobsStore = defineStore('jobs', {
|
||||
try {
|
||||
const response = await jobsAPI.getJobDetail(jobUuid)
|
||||
|
||||
if (response.success) {
|
||||
this.currentJob = response.data
|
||||
if (response && response.success) {
|
||||
this.currentJob = response.data.job
|
||||
return response.data
|
||||
} else {
|
||||
console.error('API 響應格式錯誤:', response)
|
||||
throw new Error('API 響應格式錯誤')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('取得任務詳情失敗:', error)
|
||||
ElMessage.error('載入任務詳情失敗')
|
||||
throw error
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -20,24 +20,20 @@ class WebSocketService {
|
||||
* 初始化並連接 WebSocket
|
||||
*/
|
||||
connect() {
|
||||
// 暫時禁用 WebSocket 連接
|
||||
console.warn('WebSocket 功能已暫時禁用,避免連接錯誤')
|
||||
return
|
||||
|
||||
// 以下代碼已暫時禁用
|
||||
/*
|
||||
if (this.socket) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
// 建立 Socket.IO 連接
|
||||
const wsUrl = import.meta.env.VITE_WS_BASE_URL || 'ws://127.0.0.1:5000'
|
||||
const wsUrl = import.meta.env.VITE_WS_BASE_URL || 'http://127.0.0.1:5000'
|
||||
console.log('🔌 [WebSocket] 嘗試連接到:', wsUrl)
|
||||
|
||||
this.socket = io(wsUrl, {
|
||||
path: '/socket.io/',
|
||||
transports: ['websocket', 'polling'],
|
||||
upgrade: true,
|
||||
rememberUpgrade: true,
|
||||
transports: ['polling'],
|
||||
upgrade: false,
|
||||
rememberUpgrade: false,
|
||||
autoConnect: true,
|
||||
forceNew: false,
|
||||
reconnection: true,
|
||||
@@ -49,7 +45,6 @@ class WebSocketService {
|
||||
} catch (error) {
|
||||
console.error('WebSocket 連接失敗:', error)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -49,11 +49,11 @@
|
||||
下載 {{ getLanguageText(lang) }} 版本
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
v-if="job.target_languages.length > 1 && hasCombinedFile"
|
||||
v-if="hasCombinedFile"
|
||||
command="download_combined"
|
||||
divided
|
||||
>
|
||||
下載組合翻譯檔案 (多語言)
|
||||
下載合併檔案
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item command="download_all" divided>
|
||||
下載全部檔案 (ZIP)
|
||||
@@ -352,6 +352,7 @@
|
||||
import { ref, computed, onMounted, onUnmounted } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useJobsStore } from '@/stores/jobs'
|
||||
import { jobsAPI, filesAPI } from '@/services/jobs'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import {
|
||||
DocumentDelete, ArrowLeft, Refresh, Download, ArrowDown,
|
||||
@@ -387,7 +388,10 @@ const jobUuid = computed(() => route.params.uuid)
|
||||
|
||||
// 檢查是否有combined檔案
|
||||
const hasCombinedFile = computed(() => {
|
||||
return jobFiles.value.some(file => file.language_code === 'combined')
|
||||
return jobFiles.value.some(file =>
|
||||
file.language_code === 'combined' ||
|
||||
file.filename.toLowerCase().includes('combine')
|
||||
)
|
||||
})
|
||||
|
||||
// 方法
|
||||
@@ -395,8 +399,13 @@ const loadJobDetail = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const response = await jobsStore.fetchJobDetail(jobUuid.value)
|
||||
|
||||
if (!response || !response.job) {
|
||||
throw new Error('響應資料格式錯誤')
|
||||
}
|
||||
|
||||
job.value = response.job
|
||||
jobFiles.value = response.files || []
|
||||
jobFiles.value = response.job.files || []
|
||||
|
||||
// 訂閱 WebSocket 狀態更新
|
||||
if (['PENDING', 'PROCESSING', 'RETRY'].includes(job.value.status)) {
|
||||
@@ -453,15 +462,40 @@ const downloadFile = async (langCode, customFilename = null) => {
|
||||
|
||||
const downloadCombinedFile = async () => {
|
||||
try {
|
||||
// 找到combined檔案
|
||||
const combinedFile = jobFiles.value.find(file => file.language_code === 'combined')
|
||||
if (combinedFile) {
|
||||
await jobsStore.downloadFile(jobUuid.value, 'combined', combinedFile.filename)
|
||||
// 使用新的 combine 下載 API
|
||||
const response = await filesAPI.downloadCombineFile(jobUuid.value)
|
||||
|
||||
// 從響應頭獲取檔案名
|
||||
let filename = 'combined_file.xlsx'
|
||||
if (response.headers && response.headers['content-disposition']) {
|
||||
const contentDisposition = response.headers['content-disposition']
|
||||
const match = contentDisposition.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/)
|
||||
if (match) {
|
||||
filename = match[1].replace(/['"]/g, '')
|
||||
}
|
||||
} else {
|
||||
ElMessage.error('找不到組合翻譯檔案')
|
||||
// 使用預設檔名或從任務資料獲取
|
||||
const originalName = job.value.original_filename
|
||||
const baseName = originalName ? originalName.split('.')[0] : 'combined'
|
||||
filename = `combined_${baseName}.xlsx`
|
||||
}
|
||||
|
||||
// 創建下載連結
|
||||
const blobData = response.data || response
|
||||
const url = window.URL.createObjectURL(new Blob([blobData]))
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.setAttribute('download', filename)
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
link.remove()
|
||||
window.URL.revokeObjectURL(url)
|
||||
|
||||
ElMessage.success('合併檔案下載成功')
|
||||
|
||||
} catch (error) {
|
||||
console.error('下載組合檔案失敗:', error)
|
||||
console.error('下載合併檔案失敗:', error)
|
||||
ElMessage.error('合併檔案下載失敗')
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user