前端美化
This commit is contained in:
26
InfoGenie-frontend/public/aimodelapp/AI语言翻译助手/env.js
Normal file
26
InfoGenie-frontend/public/aimodelapp/AI语言翻译助手/env.js
Normal file
@@ -0,0 +1,26 @@
|
||||
// 环境配置文件
|
||||
// 此文件定义了AI应用的基本配置
|
||||
|
||||
// API配置
|
||||
window.API_CONFIG = {
|
||||
baseUrl: 'http://127.0.0.1:5002',
|
||||
endpoints: {
|
||||
translation: '/api/aimodelapp/translation'
|
||||
}
|
||||
};
|
||||
|
||||
// 认证配置
|
||||
window.AUTH_CONFIG = {
|
||||
tokenKey: 'token',
|
||||
getToken: () => localStorage.getItem('token'),
|
||||
isAuthenticated: () => !!localStorage.getItem('token')
|
||||
};
|
||||
|
||||
// 应用配置
|
||||
window.APP_CONFIG = {
|
||||
name: 'InfoGenie AI工具',
|
||||
version: '1.0.0',
|
||||
debug: false
|
||||
};
|
||||
|
||||
console.log('环境配置已加载');
|
||||
@@ -11,11 +11,18 @@ const translationResultContainer = document.getElementById('translationResult');
|
||||
// 调用后端API
|
||||
async function callBackendAPI(sourceText, targetLanguage) {
|
||||
try {
|
||||
const response = await fetch('http://127.0.0.1:5002/api/aimodelapp/translation', {
|
||||
const token = AUTH_CONFIG.getToken();
|
||||
const headers = {
|
||||
'Content-Type': 'application/json'
|
||||
};
|
||||
|
||||
if (token) {
|
||||
headers['Authorization'] = `Bearer ${token}`;
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_CONFIG.baseUrl}${API_CONFIG.endpoints.translation}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
headers: headers,
|
||||
body: JSON.stringify({
|
||||
source_text: sourceText,
|
||||
target_language: targetLanguage
|
||||
@@ -23,6 +30,9 @@ async function callBackendAPI(sourceText, targetLanguage) {
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
if (response.status === 402) {
|
||||
throw new Error('您的萌芽币余额不足,无法使用此功能');
|
||||
}
|
||||
const errorData = await response.json();
|
||||
throw new Error(errorData.error || `API请求失败: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user