update: 2026-03-28 20:59

This commit is contained in:
2026-03-28 20:59:52 +08:00
parent e21d58e603
commit 1c81d4e6ea
611 changed files with 27847 additions and 65061 deletions

View File

@@ -4,7 +4,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>AI变量命名助手</title>
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="/aimodelapp/shared/compact-styles.css">
</head>
<body>
<div class="container">
@@ -37,7 +37,9 @@
</div>
</div>
<script src="/aimodelapp/shared/ai-prompts.js"></script>
<script src="env.js"></script>
<script src="/aimodelapp/shared/ai-chat.js"></script>
<script src="script.js"></script>
</body>
</html>

View File

@@ -37,45 +37,12 @@ const namingConventions = {
// 调用后端API
// 调用后端统一 chat提示词在前端
async function callBackendAPI(description) {
try {
// 获取JWT token
const token = localStorage.getItem('token');
if (!token) {
throw new Error('未登录请先登录后使用AI功能');
}
const response = await fetch(`${window.API_CONFIG.baseUrl}/api/aimodelapp/variable-naming`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({
description: description
})
});
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}`);
}
const data = await response.json();
if (data.success) {
return data.suggestions;
} else {
throw new Error(data.error || 'API响应格式异常');
}
} catch (error) {
console.error('API调用错误:', error);
throw error;
}
const content = await window.AiChat.complete(
[{ role: 'user', content: window.AiPrompts.variableNaming(description) }]
);
return parseAIResponse(content);
}
// 解析AI响应
@@ -227,12 +194,7 @@ async function generateSuggestions() {
displaySuggestions(suggestions);
} catch (error) {
console.error('生成建议失败:', error);
// 检查是否是萌芽币不足导致的错误
if (error.message && error.message.includes('萌芽币余额不足')) {
showErrorMessage(`萌芽币不足: 每次使用AI功能需要消耗100萌芽币请通过每日签到获取更多萌芽币`);
} else {
showErrorMessage(`生成失败: ${error.message}`);
}
showErrorMessage(`生成失败: ${error.message}`);
} finally {
showLoading(false);
}