This commit is contained in:
parent
2bba341755
commit
41ee8c5305
|
|
@ -57,6 +57,8 @@
|
|||
<el-empty v-else description="无数据" />
|
||||
|
||||
<template #footer>
|
||||
<el-button v-if="activeTab === 'EN'" type="success" title="不覆盖翻译后的数据,从ZH补全"
|
||||
@click="handleCompleteData">补全数据</el-button>
|
||||
<el-button v-if="activeTab === 'EN'" type="warning" :loading="translating"
|
||||
@click="handleTranslateAll">一键翻译</el-button>
|
||||
<el-button @click="close">取消</el-button>
|
||||
|
|
@ -132,7 +134,7 @@ function collectChineseStrings(obj: any, result: { parent: any; key: string | nu
|
|||
} else if (typeof obj === 'object') {
|
||||
for (const k of Object.keys(obj)) {
|
||||
const val = obj[k]
|
||||
if (typeof val === 'string' && hasChinese(val)) {
|
||||
if (typeof val === 'string' && hasChinese(val) && !k.startsWith('untranslate_')) {
|
||||
result.push({ parent: obj, key: k })
|
||||
} else if (typeof val === 'object') {
|
||||
collectChineseStrings(val, result)
|
||||
|
|
@ -196,6 +198,46 @@ function delay(ms: number) {
|
|||
return new Promise(resolve => setTimeout(resolve, ms))
|
||||
}
|
||||
|
||||
function handleCompleteData() {
|
||||
if (!formData.value.ZH) return
|
||||
if (!formData.value.EN) {
|
||||
formData.value.EN = JSON.parse(JSON.stringify(formData.value.ZH))
|
||||
ElMessage.success('补全完成')
|
||||
return
|
||||
}
|
||||
completeFromSource(formData.value.EN, formData.value.ZH)
|
||||
ElMessage.success('补全完成')
|
||||
}
|
||||
|
||||
function completeFromSource(target: any, source: any) {
|
||||
if (source === null || source === undefined) return
|
||||
|
||||
if (Array.isArray(source) && Array.isArray(target)) {
|
||||
for (let i = target.length; i < source.length; i++) {
|
||||
target.push(JSON.parse(JSON.stringify(source[i])))
|
||||
}
|
||||
for (let i = 0; i < Math.min(target.length, source.length); i++) {
|
||||
if (typeof target[i] === 'object' && target[i] !== null &&
|
||||
typeof source[i] === 'object' && source[i] !== null) {
|
||||
completeFromSource(target[i], source[i])
|
||||
} else if (typeof target[i] === 'string' && target[i] === '' && source[i] !== '') {
|
||||
target[i] = JSON.parse(JSON.stringify(source[i]))
|
||||
}
|
||||
}
|
||||
} else if (typeof source === 'object' && !Array.isArray(source)) {
|
||||
for (const key of Object.keys(source)) {
|
||||
if (!(key in target) || target[key] === undefined || target[key] === null) {
|
||||
target[key] = JSON.parse(JSON.stringify(source[key]))
|
||||
} else if (typeof target[key] === 'string' && target[key] === '') {
|
||||
target[key] = JSON.parse(JSON.stringify(source[key]))
|
||||
} else if (typeof target[key] === 'object' && target[key] !== null &&
|
||||
typeof source[key] === 'object' && source[key] !== null) {
|
||||
completeFromSource(target[key], source[key])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function handleTranslateAll() {
|
||||
if (!formData.value.ZH || translating.value) return
|
||||
formData.value.EN = JSON.parse(JSON.stringify(formData.value.ZH))
|
||||
|
|
@ -376,6 +418,7 @@ const NodeEditor: Component = defineComponent({
|
|||
|
||||
const zhVal = p.zhParent?.[key]
|
||||
const showTranslateBtn = p.lang === 'EN' && typeof zhVal === 'string' && hasChinese(zhVal)
|
||||
&& !key.startsWith('untranslate_')
|
||||
if (showTranslateBtn) {
|
||||
return h(ElFormItem, { label, class: 'jfd-form-item' }, () =>
|
||||
h('div', { class: 'jfd-field-with-translate' }, [
|
||||
|
|
@ -474,7 +517,8 @@ const NodeEditor: Component = defineComponent({
|
|||
]),
|
||||
h(ElCollapse, { class: 'jfd-obj-array' }, () =>
|
||||
value.map((item: any, i: number) => {
|
||||
const tag = item.title || item.name || item.text || item.label || item.year || ''
|
||||
const v = Object.values(item)
|
||||
const tag = v[0]
|
||||
return h(ElCollapseItem, {
|
||||
title: `${label} #${i + 1}${tag ? ' - ' + tag : ''}`,
|
||||
name: `${String(key)}-${i}`,
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ const data: TableData = {
|
|||
key: 'pid',
|
||||
name: '父ID',
|
||||
type: 'input',
|
||||
hide: true
|
||||
},
|
||||
{
|
||||
key: 'name',
|
||||
|
|
@ -86,7 +87,8 @@ const data: TableData = {
|
|||
key: 'pid',
|
||||
name: 'PID',
|
||||
width: '80px',
|
||||
showJson: '*'
|
||||
showJson: '*',
|
||||
hide: true
|
||||
},
|
||||
{
|
||||
key: 'name',
|
||||
|
|
@ -108,6 +110,7 @@ const data: TableData = {
|
|||
key: 'pid',
|
||||
name: '父ID',
|
||||
type: 'input',
|
||||
hide: true
|
||||
},
|
||||
{
|
||||
key: 'name',
|
||||
|
|
|
|||
Loading…
Reference in New Issue