update: 2026-03-28 20:59
This commit is contained in:
@@ -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">
|
||||
@@ -51,7 +51,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>
|
||||
@@ -187,49 +187,12 @@ async function analyzeName() {
|
||||
existingError.remove();
|
||||
}
|
||||
|
||||
const requestBody = {
|
||||
name: name
|
||||
};
|
||||
|
||||
try {
|
||||
// 调用后端API
|
||||
// 获取JWT token
|
||||
const token = localStorage.getItem('token');
|
||||
|
||||
if (!token) {
|
||||
throw new Error('未登录,请先登录后使用AI功能');
|
||||
}
|
||||
|
||||
const response = await fetch(`${window.API_CONFIG.baseUrl}/api/aimodelapp/name-analysis`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify(requestBody)
|
||||
});
|
||||
|
||||
// 检查HTTP状态码
|
||||
if (response.status === 429) {
|
||||
throw new Error('短时间内请求次数过多,请休息一下!');
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
if (response.status === 402) {
|
||||
throw new Error('您的萌芽币余额不足,无法使用此功能');
|
||||
}
|
||||
const errorData = await response.json();
|
||||
throw new Error(errorData.error || `请求失败: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success && data.analysis) {
|
||||
const analysisResult = parseAnalysisResult(data.analysis.trim());
|
||||
updateResults(analysisResult);
|
||||
} else {
|
||||
throw new Error(data.error || 'AI响应格式异常');
|
||||
}
|
||||
const content = await window.AiChat.complete([
|
||||
{ role: 'user', content: window.AiPrompts.nameAnalysis(name) },
|
||||
]);
|
||||
const analysisResult = parseAnalysisResult(content.trim());
|
||||
updateResults(analysisResult);
|
||||
} catch (error) {
|
||||
console.error('分析姓名时出错:', error);
|
||||
showError(error.message);
|
||||
|
||||
Reference in New Issue
Block a user