This commit is contained in:
1 parent
2cedb02bcc
commit
8cf7c55a0b
10 files changed
+568
-17
No files matched your search
@@ -256,3 +256,33 @@
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.translate-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.translation-banner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
background: var(--el-color-primary-light-9, #ecf5ff);
|
||||
color: var(--el-color-primary, #409eff);
|
||||
border: 1px solid var(--el-color-primary-light-7, #d9ecff);
|
||||
border-radius: 8px;
|
||||
padding: 10px 16px;
|
||||
margin-bottom: 16px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.banner-icon {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.toggle-back-link {
|
||||
margin-left: auto;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import {onBeforeUnmount, ref, watch} from 'vue'
|
||||
import {computed, onBeforeUnmount, ref, watch} from 'vue'
|
||||
|
||||
import {useRoute, useRouter} from 'vue-router'
|
||||
|
||||
import {Document, Back, Delete, Download} from '@element-plus/icons-vue';
|
||||
import {Document, Back, Delete, Download, Operation} from '@element-plus/icons-vue';
|
||||
|
||||
import {ElMessage, ElMessageBox} from 'element-plus';
|
||||
|
||||
@@ -37,6 +37,12 @@ export function usePage() {
|
||||
const loadError = ref('')
|
||||
let requestSequence = 0
|
||||
|
||||
// 翻译相关状态
|
||||
const isTranslated = ref(false)
|
||||
const translating = ref(false)
|
||||
const translationCache = ref(null)
|
||||
const detectedLang = ref('')
|
||||
|
||||
const parseAddresses = (value) => {
|
||||
try {
|
||||
const addresses = JSON.parse(value || '[]')
|
||||
@@ -57,6 +63,12 @@ export function usePage() {
|
||||
loadError.value = ''
|
||||
loading.value = true
|
||||
|
||||
// 重置翻译状态
|
||||
isTranslated.value = false
|
||||
translating.value = false
|
||||
translationCache.value = null
|
||||
detectedLang.value = ''
|
||||
|
||||
const rawId = String(route.params.id || '')
|
||||
const id = Number(rawId)
|
||||
if (!/^\d+$/.test(rawId) || !Number.isSafeInteger(id) || id <= 0) {
|
||||
@@ -67,7 +79,6 @@ export function usePage() {
|
||||
|
||||
try {
|
||||
const res = await http.post('/api/v1/email/detail', {id})
|
||||
// 切换邮件或离开页面后,旧请求不得覆盖当前状态。
|
||||
if (sequence !== requestSequence) return
|
||||
if (res?.errorNo !== 0) {
|
||||
loadError.value = res?.errorMsg || '读取邮件失败,请重试'
|
||||
@@ -82,7 +93,6 @@ export function usePage() {
|
||||
tos.value = parseAddresses(data.to)
|
||||
ccs.value = parseAddresses(data.cc)
|
||||
showCC.value = ccs.value.length > 0
|
||||
// 仅在本人的发件副本展示密送;后端仍负责所有权校验和收件副本脱敏。
|
||||
bccs.value = data.type === 1 ? parseAddresses(data.bcc) : []
|
||||
showBCC.value = bccs.value.length > 0
|
||||
} catch {
|
||||
@@ -99,6 +109,66 @@ export function usePage() {
|
||||
requestSequence++
|
||||
})
|
||||
|
||||
const toggleTranslate = async () => {
|
||||
if (loading.value || loadError.value) return
|
||||
if (isTranslated.value) {
|
||||
isTranslated.value = false
|
||||
return
|
||||
}
|
||||
|
||||
if (translationCache.value) {
|
||||
isTranslated.value = true
|
||||
return
|
||||
}
|
||||
|
||||
const emailId = Number(detailData.value?.id)
|
||||
if (!Number.isSafeInteger(emailId) || emailId <= 0) return
|
||||
|
||||
translating.value = true
|
||||
try {
|
||||
const res = await http.post('/api/v1/email/translate', {
|
||||
id: emailId,
|
||||
target_lang: 'zh-CN'
|
||||
})
|
||||
if (res?.errorNo === 0 && res.data) {
|
||||
translationCache.value = res.data
|
||||
detectedLang.value = res.data.detected_lang || 'auto'
|
||||
isTranslated.value = true
|
||||
ElMessage.success('翻译完成')
|
||||
} else {
|
||||
ElMessage.error(res?.errorMsg || '翻译失败,请稍后重试')
|
||||
}
|
||||
} catch (err) {
|
||||
ElMessage.error('翻译服务连接失败,请稍后重试')
|
||||
} finally {
|
||||
translating.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const displaySubject = computed(() => {
|
||||
if (isTranslated.value && translationCache.value?.subject_translated) {
|
||||
return translationCache.value.subject_translated
|
||||
}
|
||||
return detailData.value?.subject || ''
|
||||
})
|
||||
|
||||
const displayContent = computed(() => {
|
||||
if (isTranslated.value && translationCache.value?.content_translated) {
|
||||
return translationCache.value.content_translated
|
||||
}
|
||||
if (detailData.value?.html) {
|
||||
return detailData.value.html
|
||||
}
|
||||
return detailData.value?.text || ''
|
||||
})
|
||||
|
||||
const displayIsText = computed(() => {
|
||||
if (isTranslated.value) {
|
||||
return true
|
||||
}
|
||||
return !detailData.value?.html
|
||||
})
|
||||
|
||||
const backToList = () => router.push({name: 'list'})
|
||||
const handleReply = () => {
|
||||
const id = Number(detailData.value.id)
|
||||
@@ -178,6 +248,7 @@ export function usePage() {
|
||||
Back,
|
||||
Delete,
|
||||
Download,
|
||||
Operation,
|
||||
ElMessage,
|
||||
ElMessageBox,
|
||||
lang,
|
||||
@@ -202,7 +273,14 @@ export function usePage() {
|
||||
formatSenderName,
|
||||
hasSenderName,
|
||||
formatDetailDate,
|
||||
handleDelete
|
||||
handleDelete,
|
||||
isTranslated,
|
||||
translating,
|
||||
detectedLang,
|
||||
displaySubject,
|
||||
displayContent,
|
||||
displayIsText,
|
||||
toggleTranslate
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,5 +288,6 @@ export {
|
||||
Back,
|
||||
Delete,
|
||||
Document,
|
||||
Download
|
||||
Download,
|
||||
Operation
|
||||
}
|
||||
@@ -5,6 +5,16 @@
|
||||
<el-icon><Back /></el-icon>
|
||||
</el-button>
|
||||
<div v-if="!loading && !loadError" class="action-buttons">
|
||||
<el-button
|
||||
:type="isTranslated ? 'warning' : 'default'"
|
||||
:loading="translating"
|
||||
plain
|
||||
@click="toggleTranslate"
|
||||
class="translate-btn"
|
||||
>
|
||||
<el-icon><Operation /></el-icon>
|
||||
<span>{{ isTranslated ? '查看原文' : '一键翻译' }}</span>
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="detailData.type === 0"
|
||||
type="primary"
|
||||
@@ -38,7 +48,14 @@
|
||||
:closable="false"
|
||||
show-icon
|
||||
/>
|
||||
<h1 class="mail-subject">{{ detailData.subject }}</h1>
|
||||
|
||||
<div v-if="isTranslated" class="translation-banner">
|
||||
<el-icon class="banner-icon"><Operation /></el-icon>
|
||||
<span>已自动翻译为中文(源语言:{{ detectedLang || '自动识别' }})</span>
|
||||
<el-button link type="primary" @click="toggleTranslate" class="toggle-back-link">查看原文</el-button>
|
||||
</div>
|
||||
|
||||
<h1 class="mail-subject">{{ displaySubject }}</h1>
|
||||
|
||||
<div class="mail-meta-card">
|
||||
<div class="meta-left">
|
||||
@@ -78,10 +95,10 @@
|
||||
<el-divider class="custom-divider"/>
|
||||
|
||||
<div class="mail-body">
|
||||
<div class="body-text" v-if="detailData.html === ''">
|
||||
{{ detailData.text }}
|
||||
<div class="body-text" v-if="displayIsText">
|
||||
{{ displayContent }}
|
||||
</div>
|
||||
<div class="body-html" v-else v-html="detailData.html"></div>
|
||||
<div class="body-html" v-else v-html="displayContent"></div>
|
||||
</div>
|
||||
|
||||
<div v-if="detailData.attachments && detailData.attachments.length > 0" class="attachments-section">
|
||||
@@ -100,7 +117,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { usePage, Back, Delete, Document, Download } from './EmailDetail.js'
|
||||
import { usePage, Back, Delete, Document, Download, Operation } from './EmailDetail.js'
|
||||
|
||||
const {
|
||||
handleReply,
|
||||
@@ -119,7 +136,14 @@ const {
|
||||
bccs,
|
||||
formatSenderName,
|
||||
hasSenderName,
|
||||
formatDetailDate
|
||||
formatDetailDate,
|
||||
isTranslated,
|
||||
translating,
|
||||
detectedLang,
|
||||
displaySubject,
|
||||
displayContent,
|
||||
displayIsText,
|
||||
toggleTranslate
|
||||
} = usePage()
|
||||
</script>
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
<el-icon><Setting /></el-icon>
|
||||
<span class="settings-label">{{ lang.settings }}</span>
|
||||
</div>
|
||||
<span class="app-version-badge">V2.13.1</span>
|
||||
<span class="app-version-badge">V2.14.0</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user