|
|
|
@ -18,7 +18,8 @@ |
|
|
|
<!-- 功能按钮区域 --> |
|
|
|
<div class="add-item"> |
|
|
|
<el-button type="success" @click="handleAdd">添加</el-button> |
|
|
|
<el-button class="add-item-export" @click="handleBatchImport">批量导入</el-button> |
|
|
|
<!-- 后续需求 --> |
|
|
|
<!-- <el-button class="add-item-export" @click="handleBatchImport">批量导入</el-button> --> |
|
|
|
</div> |
|
|
|
|
|
|
|
<div> |
|
|
|
@ -188,7 +189,9 @@ |
|
|
|
|
|
|
|
<template #footer> |
|
|
|
<el-button @click="showEditDialog = false">取消</el-button> |
|
|
|
<el-button type="primary" @click="handleSave">保存</el-button> |
|
|
|
<el-button type="primary" :loading="saveLoading" @click="handleSave"> |
|
|
|
{{ saveLoading ? '保存中...' : '保存' }} |
|
|
|
</el-button> |
|
|
|
</template> |
|
|
|
</el-dialog> |
|
|
|
|
|
|
|
@ -246,6 +249,9 @@ const showImportDialog = ref(false) |
|
|
|
const showDeleteDialog = ref(false) |
|
|
|
const currentDeleteRow = ref(null) // 当前要删除的行数据 |
|
|
|
|
|
|
|
// 添加保存按钮加载状态 |
|
|
|
const saveLoading = ref(false) |
|
|
|
|
|
|
|
const editForm = ref({ |
|
|
|
id: '', |
|
|
|
chineseSimplified: '', |
|
|
|
@ -357,17 +363,15 @@ const getMenuTree = async function () { |
|
|
|
|
|
|
|
// 保存翻译 |
|
|
|
const handleSave = async () => { |
|
|
|
// 原文必填校验 |
|
|
|
if (!editForm.value.chineseSimplified || editForm.value.chineseSimplified.trim() === '') { |
|
|
|
ElMessage.error('原文为必填项') |
|
|
|
return |
|
|
|
} |
|
|
|
// 设置保存按钮为加载状态 |
|
|
|
saveLoading.value = true |
|
|
|
|
|
|
|
// 纯文本校验 |
|
|
|
const fields = ['english', 'thai', 'chineseTraditional', 'malay', 'vietnamese'] |
|
|
|
for (const field of fields) { |
|
|
|
if (editForm.value[field] && /<[^>]*>/.test(editForm.value[field])) { |
|
|
|
ElMessage.error('译文仅支持纯文本,不支持HTML标签') |
|
|
|
saveLoading.value = false // 校验失败,恢复按钮状态 |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
@ -379,10 +383,18 @@ const handleSave = async () => { |
|
|
|
data: editForm.value |
|
|
|
}) |
|
|
|
|
|
|
|
// 点击保存后,刷新菜单树 |
|
|
|
await getMenuTree() |
|
|
|
|
|
|
|
if (res.code === 200) { |
|
|
|
ElMessage.success(editForm.value.id ? '编辑成功' : '添加成功') |
|
|
|
showEditDialog.value = false |
|
|
|
getTranslationList() |
|
|
|
// getTranslationList() |
|
|
|
|
|
|
|
// 触发页面刷新以重新加载数据 |
|
|
|
setTimeout(() => { |
|
|
|
window.location.reload() |
|
|
|
}, 500) |
|
|
|
} else if (res.code === 0) { |
|
|
|
// 处理后端返回的错误信息 |
|
|
|
ElMessage.error(res.msg || '操作失败') |
|
|
|
@ -393,9 +405,10 @@ const handleSave = async () => { |
|
|
|
} catch (error) { |
|
|
|
console.error('保存失败:', error) |
|
|
|
ElMessage.error('保存失败') |
|
|
|
} finally { |
|
|
|
// 无论成功还是失败,都恢复按钮状态 |
|
|
|
saveLoading.value = false |
|
|
|
} |
|
|
|
// 点击保存后,刷新菜单树 |
|
|
|
await getMenuTree() |
|
|
|
} |
|
|
|
|
|
|
|
// 删除翻译 - 打开确认对话框 |
|
|
|
@ -412,9 +425,15 @@ const handleDeleteConfirm = async () => { |
|
|
|
data: { id: currentDeleteRow.value.id } |
|
|
|
}) |
|
|
|
|
|
|
|
// 点击删除后,刷新菜单树 |
|
|
|
await getMenuTree() |
|
|
|
if (res.code === 200) { |
|
|
|
ElMessage.success('删除成功') |
|
|
|
getTranslationList() |
|
|
|
// getTranslationList() |
|
|
|
// 触发页面刷新以重新加载数据 |
|
|
|
setTimeout(() => { |
|
|
|
window.location.reload() |
|
|
|
}, 500) |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.error('删除失败:', error) |
|
|
|
|