快速翻译代码中多语言文本,保持代码结构完整性,操作简洁高效。
提供专业的代码文本翻译解决方案,支持多语言翻译并保留代码结构。
支持复杂代码内容的批量翻译,兼顾效率与准确性,满足企业级多语言项目需求。
更多提示词
","preserveWhitespace":false,"handleSpecialChars":false,"sourceLanguage":"英文"},"caseName":"用例三"}]
function fillExample() {
inputForm.formData = JSON.parse(JSON.stringify(testCaseList[testCaseIndex].data));
testCaseIndex = (testCaseIndex + 1) % testCaseList.length;
}
// 检查表单是否有填写内容
function checkFormHasData() {
if (!inputForm || !inputForm.formData) {
return false;
}
const formData = inputForm.formData;
// 遍历所有表单字段,检查是否有非空值
for (const key in formData) {
const value = formData[key];
// 检查不同类型的值
if (value !== null && value !== undefined && value !== '') {
// 对于数组类型
if (Array.isArray(value)) {
// 检查数组是否有有效内容
const hasValidContent = value.some(item => {
return item !== null && item !== undefined && item !== '';
});
if (hasValidContent) {
return true;
}
} else if (typeof value === 'boolean') {
// 布尔值如果不是默认的false,认为有数据
if (value === true) {
return true;
}
} else {
// 其他类型的非空值
return true;
}
}
}
return false;
}
// 表单验证
function validateForm() {
return new Promise((resolve) => {
if (!inputForm || !inputForm.$refs || !inputForm.$refs.formRef) {
resolve(true); // 如果表单引用不存在,默认通过
return;
}
inputForm.$refs.formRef.validate((valid) => {
if (!valid) {
// 显示验证失败提示
showValidationError('请完善表单信息后再试用');
}
resolve(valid);
});
});
}
// 显示验证错误提示
function showValidationError(message) {
const modal = document.createElement('div');
// 设置样式
modal.style.position = 'fixed';
modal.style.top = '10%';
modal.style.left = '50%';
modal.style.transform = 'translate(-50%, -50%)';
modal.style.padding = '10px 24px';
modal.style.backgroundColor = '#fcf0f0';
modal.style.color = '#e47470';
modal.style.border = '1px solid #fcf0f0';
modal.style.borderRadius = '5px';
modal.style.textAlign = 'center';
modal.style.fontSize = '16px';
modal.style.zIndex = '100001';
modal.style.display = 'none';
modal.innerHTML = message;
// 添加到页面
document.body.appendChild(modal);
// 显示提示框
modal.style.display = 'block';
// 自动关闭
setTimeout(() => {
modal.style.display = 'none';
document.body.removeChild(modal);
}, 2000);
}
async function commonParameterJump(promptCode, openMorePrompt, openMoreProvider, notValidateForm) {
// 检查表单是否有填写内容
const hasFormData = checkFormHasData();
let autoSubmit = false;
// 如果表单有数据,进行表单验证
if (hasFormData && (!promptCode) && (!openMorePrompt) && (!openMoreProvider) && (!notValidateForm)) {
const isValid = await validateForm();
if (!isValid) {
return; // 验证失败,不继续执行
}
autoSubmit = true
}
let res = await window.header.request({
url: '/v1/manage/api-hub/prompt-api-compare/task/add',
method: 'POST',
data: {'serviceCode': 'PROMPT_TRANSLATE_CODE_TEXT'}
})
if (res.code === 'FP00000') {
// 构建URL,如果有表单数据则添加为query参数
let url = 'https://console.explinks.com' + "/myHomePage/try/promptToApi/" + res.taskNo;
// 创建一个统一的query参数对象
const queryParams = {};
if (hasFormData && inputForm.formData) {
// 将整个表单数据作为JSON对象放到query参数中
const formDataJson = JSON.stringify(inputForm.formData);
queryParams.formData = encodeURIComponent(formDataJson);
queryParams.autoSubmit = autoSubmit;
}
if (promptCode) {
queryParams.promptCode = promptCode;
}
// 展示更多提示词api
if (openMorePrompt) {
queryParams.openMorePrompt = true;
}
// 展示更多供应商渠道
if (openMoreProvider) {
queryParams.openMoreProvider = true;
}
// 构建最终的URL
const queryString = Object.keys(queryParams)
.filter(key => queryParams[key] !== undefined && queryParams[key] !== null)
.map(key => key + '=' + queryParams[key])
.join('&');
if (queryString) {
url += '?' + queryString;
}
window.open(url);
} else if (res.msg === 'FP98001') {
const modal = document.createElement('div');
// 通过 JavaScript 设置内联样式
modal.style.position = 'fixed';
modal.style.top = '10%';
modal.style.left = '50%';
modal.style.transform = 'translate(-50%, -50%)';
modal.style.padding = '10px 24px';
modal.style.backgroundColor = '#fcf0f0';
modal.style.color = '#e47470';
modal.style.border = '1px solid #fcf0f0';
modal.style.borderRadius = '5px';
modal.style.textAlign = 'center';
modal.style.fontSize = '16px';
modal.style.zIndex = '100001';
modal.style.display = 'none'; // 默认隐藏
modal.innerHTML = '试用工具请选择个人空间进行体验';
// 将提示框添加到页面中
document.body.appendChild(modal);
// 显示提示框
modal.style.display = 'block';
// 设置自动关闭提示框的时间
setTimeout(() => {
modal.style.display = 'none'; // 隐藏提示框
document.body.removeChild(modal); // 从 DOM 中移除
}, 1500);
} else if (res.code === 401) {
openLoginDialog(function () {
commonParameterJump(promptCode, openMorePrompt, openMoreProvider)
})
}
}