提交 50a8c95b authored 作者: 张伊明's avatar 张伊明

feat 智能翻译接入接口、部分优化

上级 7f1603ac
流水线 #581 已失败 于阶段
in 1 分 3 秒
import request from '@/api/request.js'
const INTELLIGENT_TRANSLATION_BASE_URL = '/doc-detail-pdf-api'
const INTELLIGENT_TRANSLATION_HEADERS = {
'Client-ID': 'test_client',
'X-API-Key': 'test_key'
}
export function submitTranslationTask(file) {
const formData = new FormData()
formData.append('files', file)
return request({
url: `${INTELLIGENT_TRANSLATION_BASE_URL}/submit`,
method: 'POST',
data: formData,
headers: INTELLIGENT_TRANSLATION_HEADERS
})
}
export function queryTranslationTaskStatus(taskId) {
return request({
url: `${INTELLIGENT_TRANSLATION_BASE_URL}/status/${taskId}`,
method: 'GET',
headers: INTELLIGENT_TRANSLATION_HEADERS
})
}
export function queryTranslationTaskResult(taskId) {
return request({
url: `${INTELLIGENT_TRANSLATION_BASE_URL}/result/${taskId}`,
method: 'GET',
headers: INTELLIGENT_TRANSLATION_HEADERS
})
}
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
<img class="workspace-toolbar-icon" src="@/assets/icons/tool-item-icon2.png" alt="" /> <img class="workspace-toolbar-icon" src="@/assets/icons/tool-item-icon2.png" alt="" />
<span class="workspace-toolbar-heading">智能翻译</span> <span class="workspace-toolbar-heading">智能翻译</span>
</div> </div>
<button class="translate-btn" type="button" @click="onTranslate"> <button class="translate-btn" type="button" :disabled="submitLoading" @click="onTranslate">
AI翻译 {{ submitLoading ? '提交中...' : 'AI翻译' }}
</button> </button>
</div> </div>
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<div v-else class="upload-file-panel"> <div v-else class="upload-file-panel">
<ul class="upload-file-list"> <ul class="upload-file-list">
<li v-for="(file, index) in selectedFiles" :key="`${file.name}-${index}`" class="upload-file-item"> <li v-for="(file, index) in selectedFiles" :key="`${file.name}-${file.lastModified}-${file.size}`" class="upload-file-item">
<img class="upload-file-type-icon" :src="fileTypeIconUrl" alt="" /> <img class="upload-file-type-icon" :src="fileTypeIconUrl" alt="" />
<span class="upload-file-name">{{ file.name }}</span> <span class="upload-file-name">{{ file.name }}</span>
<button type="button" class="upload-file-item-delete" aria-label="删除该文件" @click="removeFileAt(index)"> <button type="button" class="upload-file-item-delete" aria-label="删除该文件" @click="removeFileAt(index)">
...@@ -90,8 +90,10 @@ ...@@ -90,8 +90,10 @@
<script setup> <script setup>
import { computed, ref } from 'vue' import { computed, ref } from 'vue'
import { ElMessage } from 'element-plus'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import IntelligenceLeftTabBar from '@/components/intelligenceLeftTabBar/index.vue' import IntelligenceLeftTabBar from '@/components/intelligenceLeftTabBar/index.vue'
import { submitTranslationTask } from '@/api/intelligentTranslation/index'
import { uploadRecordMock } from './mock' import { uploadRecordMock } from './mock'
import fileTypeIconUrl from './icons/file-type-icon.png' import fileTypeIconUrl from './icons/file-type-icon.png'
import lineUploadIconSvg from './icons/Line_Upload.svg?raw' import lineUploadIconSvg from './icons/Line_Upload.svg?raw'
...@@ -106,24 +108,45 @@ const sourceText = ref('') ...@@ -106,24 +108,45 @@ const sourceText = ref('')
const translatedText = ref('点击“翻译”后展示占位结果') const translatedText = ref('点击“翻译”后展示占位结果')
const selectedFiles = ref([]) const selectedFiles = ref([])
const uploadRecords = ref(uploadRecordMock) const uploadRecords = ref(uploadRecordMock)
const submitLoading = ref(false)
const isTextMode = computed(() => selectedFiles.value.length === 0) const isTextMode = computed(() => selectedFiles.value.length === 0)
const onTranslate = () => { const onTranslate = async () => {
if (isTextMode.value) { if (isTextMode.value) {
const text = sourceText.value.trim() ElMessage.warning('请先上传 PDF 文件后再发起翻译')
translatedText.value = text
? `【Mock译文】${text}`
: '【Mock译文】当前没有输入文本,请先填写原文内容。'
return return
} }
const targetFile = selectedFiles.value[0]
if (!targetFile) {
ElMessage.warning('请先上传 PDF 文件')
return
}
if (submitLoading.value) {
return
}
submitLoading.value = true
try {
const response = await submitTranslationTask(targetFile)
const taskId = response?.data?.task_id || response?.data?.task_ids?.[0]
if (!taskId) {
throw new Error('未获取到任务ID')
}
router.push({ router.push({
name: 'intelligentTranslationDocument', name: 'intelligentTranslationDocument',
query: { query: {
fileName: selectedFiles.value[0]?.name || '' taskId,
fileName: targetFile.name || ''
} }
}) })
} catch (error) {
ElMessage.error(error?.message || '翻译任务提交失败,请稍后重试')
} finally {
submitLoading.value = false
}
} }
const onFileChange = (event) => { const onFileChange = (event) => {
...@@ -291,6 +314,11 @@ function formatRecordDateOnly(timeStr) { ...@@ -291,6 +314,11 @@ function formatRecordDateOnly(timeStr) {
cursor: pointer; cursor: pointer;
} }
.translate-btn:disabled {
opacity: 0.7;
cursor: not-allowed;
}
.workspace-source-block { .workspace-source-block {
box-sizing: border-box; box-sizing: border-box;
flex: 1; flex: 1;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论