|
|
@ -50,6 +50,25 @@ |
|
|
</el-form-item> |
|
|
</el-form-item> |
|
|
</el-form> |
|
|
</el-form> |
|
|
</el-tab-pane> |
|
|
</el-tab-pane> |
|
|
|
|
|
|
|
|
|
|
|
<el-tab-pane label="谷歌翻译" name="google" lazy> |
|
|
|
|
|
<el-form |
|
|
|
|
|
ref="googleFormRef" |
|
|
|
|
|
:model="googleSettingData" |
|
|
|
|
|
:rules="googleRules" |
|
|
|
|
|
label-width="120px" |
|
|
|
|
|
style="max-width: 600px; margin-top: 20px" |
|
|
|
|
|
> |
|
|
|
|
|
<el-form-item label="API Key" prop="googleApiKey"> |
|
|
|
|
|
<el-input v-model="googleSettingData.googleApiKey" placeholder="请输入谷歌API Key"></el-input> |
|
|
|
|
|
</el-form-item> |
|
|
|
|
|
<el-form-item> |
|
|
|
|
|
<div style="margin-left: 130px; margin-top: 20px"> |
|
|
|
|
|
<el-button type="primary" @click="submitGoogleForm">保存配置</el-button> |
|
|
|
|
|
</div> |
|
|
|
|
|
</el-form-item> |
|
|
|
|
|
</el-form> |
|
|
|
|
|
</el-tab-pane> |
|
|
</el-tabs> |
|
|
</el-tabs> |
|
|
</div> |
|
|
</div> |
|
|
</el-card> |
|
|
</el-card> |
|
|
@ -75,6 +94,7 @@ const defaultSettingData = ref({ |
|
|
// 存储初始获取的数据 |
|
|
// 存储初始获取的数据 |
|
|
const initialBaiduData = ref({}); |
|
|
const initialBaiduData = ref({}); |
|
|
const initialYoudaoData = ref({}); |
|
|
const initialYoudaoData = ref({}); |
|
|
|
|
|
const initialGoogleData = ref({}); // 添加谷歌初始数据存储 |
|
|
|
|
|
|
|
|
const baiduSettingData = ref({ |
|
|
const baiduSettingData = ref({ |
|
|
appId: '', |
|
|
appId: '', |
|
|
@ -86,6 +106,10 @@ const youdaoSettingData = ref({ |
|
|
appSecret: '' |
|
|
appSecret: '' |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const googleSettingData = ref({ |
|
|
|
|
|
googleApiKey: '' |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
// 百度翻译配置验证规则 |
|
|
// 百度翻译配置验证规则 |
|
|
const baiduRules = { |
|
|
const baiduRules = { |
|
|
appId: [ |
|
|
appId: [ |
|
|
@ -110,6 +134,14 @@ const youdaoRules = { |
|
|
] |
|
|
] |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// 谷歌翻译配置验证规则 |
|
|
|
|
|
const googleRules = { |
|
|
|
|
|
googleApiKey: [ |
|
|
|
|
|
{ required: true, message: '请输入谷歌API Key', trigger: 'blur' }, |
|
|
|
|
|
{ min: 1, max: 200, message: '长度在 1 到 200 个字符', trigger: 'blur' } |
|
|
|
|
|
] |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
/** 查询配置列表 */ |
|
|
/** 查询配置列表 */ |
|
|
const getList = async () => { |
|
|
const getList = async () => { |
|
|
loading.value = true; |
|
|
loading.value = true; |
|
|
@ -147,6 +179,16 @@ const getList = async () => { |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 添加谷歌翻译数据初始化 |
|
|
|
|
|
if (parsedData.googleApiKey) { |
|
|
|
|
|
Object.assign(googleSettingData.value, { |
|
|
|
|
|
googleApiKey: parsedData.googleApiKey |
|
|
|
|
|
}); |
|
|
|
|
|
Object.assign(initialGoogleData.value, { |
|
|
|
|
|
googleApiKey: parsedData.googleApiKey |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 根据type判断是否使用默认配置 |
|
|
// 根据type判断是否使用默认配置 |
|
|
if (parsedData.type === '0') { |
|
|
if (parsedData.type === '0') { |
|
|
defaultSettingData.value.useDefault = true; |
|
|
defaultSettingData.value.useDefault = true; |
|
|
@ -162,10 +204,15 @@ const getList = async () => { |
|
|
Object.assign(youdaoSettingData.value, parsedData); |
|
|
Object.assign(youdaoSettingData.value, parsedData); |
|
|
Object.assign(initialYoudaoData.value, parsedData); // 保存初始数据 |
|
|
Object.assign(initialYoudaoData.value, parsedData); // 保存初始数据 |
|
|
activeTab.value = 'youdao'; |
|
|
activeTab.value = 'youdao'; |
|
|
|
|
|
} else if (parsedData.type === '3') { |
|
|
|
|
|
// 添加谷歌翻译类型 |
|
|
|
|
|
Object.assign(googleSettingData.value, parsedData); |
|
|
|
|
|
Object.assign(initialGoogleData.value, parsedData); // 保存初始数据 |
|
|
|
|
|
activeTab.value = 'google'; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
console.log('成功:', baiduSettingData.value, youdaoSettingData.value); |
|
|
console.log('成功:', baiduSettingData.value, youdaoSettingData.value, googleSettingData.value); |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
ElMessage.error('获取配置失败'); |
|
|
ElMessage.error('获取配置失败'); |
|
|
} finally { |
|
|
} finally { |
|
|
@ -222,7 +269,8 @@ const submitBaiduForm = async () => { |
|
|
appId: baiduSettingData.value.appId, |
|
|
appId: baiduSettingData.value.appId, |
|
|
secretKey: baiduSettingData.value.secretKey, |
|
|
secretKey: baiduSettingData.value.secretKey, |
|
|
appKey: '', // 有道翻译相关的字段清空 |
|
|
appKey: '', // 有道翻译相关的字段清空 |
|
|
appSecret: '' |
|
|
appSecret: '', |
|
|
|
|
|
googleApiKey: '' // 谷歌翻译相关字段清空 |
|
|
}; |
|
|
}; |
|
|
await updateSetting(params); |
|
|
await updateSetting(params); |
|
|
ElMessage.success('启用百度翻译'); |
|
|
ElMessage.success('启用百度翻译'); |
|
|
@ -255,7 +303,8 @@ const submitYoudaoForm = async () => { |
|
|
appId: '', // 百度翻译相关的字段清空 |
|
|
appId: '', // 百度翻译相关的字段清空 |
|
|
secretKey: '', |
|
|
secretKey: '', |
|
|
appKey: youdaoSettingData.value.appKey, |
|
|
appKey: youdaoSettingData.value.appKey, |
|
|
appSecret: youdaoSettingData.value.appSecret |
|
|
appSecret: youdaoSettingData.value.appSecret, |
|
|
|
|
|
googleApiKey: '' // 谷歌翻译相关字段清空 |
|
|
}; |
|
|
}; |
|
|
await updateSetting(params); |
|
|
await updateSetting(params); |
|
|
ElMessage.success('启用有道翻译'); |
|
|
ElMessage.success('启用有道翻译'); |
|
|
@ -273,6 +322,39 @@ const submitYoudaoForm = async () => { |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** 提交谷歌翻译配置表单 */ |
|
|
|
|
|
const submitGoogleForm = async () => { |
|
|
|
|
|
const formRef = proxy.$refs.googleFormRef as (typeof import('element-plus'))['ElForm']; |
|
|
|
|
|
const isValid = await formRef.validate().catch(() => false); |
|
|
|
|
|
|
|
|
|
|
|
if (!isValid) return; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
buttonLoading.value = true; |
|
|
|
|
|
const params = { |
|
|
|
|
|
settingName: 'TRANSLATION_SETTING', |
|
|
|
|
|
type: '3', // 谷歌翻译 |
|
|
|
|
|
appId: '', // 百度翻译相关的字段清空 |
|
|
|
|
|
secretKey: '', |
|
|
|
|
|
appKey: '', // 有道翻译相关的字段清空 |
|
|
|
|
|
appSecret: '', |
|
|
|
|
|
googleApiKey: googleSettingData.value.googleApiKey |
|
|
|
|
|
}; |
|
|
|
|
|
await updateSetting(params); |
|
|
|
|
|
ElMessage.success('启用谷歌翻译'); |
|
|
|
|
|
|
|
|
|
|
|
// 更新初始数据 |
|
|
|
|
|
Object.assign(initialGoogleData.value, { |
|
|
|
|
|
googleApiKey: googleSettingData.value.googleApiKey |
|
|
|
|
|
}); |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.error('更新谷歌翻译配置失败:', error); |
|
|
|
|
|
ElMessage.error('更新谷歌翻译配置失败'); |
|
|
|
|
|
} finally { |
|
|
|
|
|
buttonLoading.value = false; |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
/** 重置百度翻译配置表单 */ |
|
|
/** 重置百度翻译配置表单 */ |
|
|
const resetBaiduForm = () => { |
|
|
const resetBaiduForm = () => { |
|
|
const formRef = proxy.$refs.baiduFormRef as (typeof import('element-plus'))['ElForm']; |
|
|
const formRef = proxy.$refs.baiduFormRef as (typeof import('element-plus'))['ElForm']; |
|
|
@ -303,6 +385,20 @@ const resetYoudaoForm = () => { |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** 重置谷歌翻译配置表单 */ |
|
|
|
|
|
const resetGoogleForm = () => { |
|
|
|
|
|
const formRef = proxy.$refs.googleFormRef as (typeof import('element-plus'))['ElForm']; |
|
|
|
|
|
|
|
|
|
|
|
// 重置为初始获取的数据 |
|
|
|
|
|
if (initialGoogleData.value && Object.keys(initialGoogleData.value).length > 0) { |
|
|
|
|
|
Object.assign(googleSettingData.value, { |
|
|
|
|
|
googleApiKey: initialGoogleData.value.googleApiKey || '' |
|
|
|
|
|
}); |
|
|
|
|
|
} else { |
|
|
|
|
|
formRef.resetFields(); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
onMounted(() => { |
|
|
onMounted(() => { |
|
|
getList(); |
|
|
getList(); |
|
|
}); |
|
|
}); |
|
|
|