优化结果

This commit is contained in:
2025-09-15 19:08:47 +08:00
parent 72084a8782
commit dcfa89e63c
357 changed files with 16156 additions and 1589 deletions

View File

@@ -0,0 +1,57 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>AI姓名评测</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<div class="header">
<h1 class="title">AI姓名评测</h1>
<p class="subtitle">智能分析姓名的稀有度、音韵美感与寓意内涵</p>
</div>
<div class="form-group">
<label class="form-label" for="nameInput">请输入姓名:</label>
<input
type="text"
id="nameInput"
class="form-input"
placeholder="请输入要分析的姓名,例如:张三、李雅婷、王子轩等..."
maxlength="10"
/>
</div>
<button id="analyzeBtn" class="btn">开始分析</button>
<div class="result-section">
<h3 class="result-title">分析结果</h3>
<div id="loading" class="loading">正在分析中,请稍候...</div>
<div id="resultContainer" class="result-container">
<div class="result-card">
<h4 class="card-title">稀有度评分</h4>
<div id="rarityScore" class="score-display">--%</div>
<div id="rarityDesc" class="score-desc">点击"开始分析"查看结果</div>
</div>
<div class="result-card">
<h4 class="card-title">音韵评价</h4>
<div id="phoneticScore" class="score-display">--%</div>
<div id="phoneticDesc" class="score-desc">点击"开始分析"查看结果</div>
</div>
<div class="result-card">
<h4 class="card-title">含义解读</h4>
<div id="meaningAnalysis" class="meaning-content">点击"开始分析"查看姓名的深层寓意</div>
</div>
</div>
</div>
</div>
<script src="env.js"></script>
<script src="script.js"></script>
</body>
</html>

View File

@@ -0,0 +1,251 @@
// 从配置文件导入设置
// 配置在 env.js 文件中定义
// DOM 元素
const nameInput = document.getElementById('nameInput');
const analyzeBtn = document.getElementById('analyzeBtn');
const loading = document.getElementById('loading');
const rarityScore = document.getElementById('rarityScore');
const rarityDesc = document.getElementById('rarityDesc');
const phoneticScore = document.getElementById('phoneticScore');
const phoneticDesc = document.getElementById('phoneticDesc');
const meaningAnalysis = document.getElementById('meaningAnalysis');
// 解析AI返回的分析结果
function parseAnalysisResult(content) {
const result = {
rarityScore: '--%',
rarityDesc: '解析失败',
phoneticScore: '--%',
phoneticDesc: '解析失败',
meaningAnalysis: '解析失败'
};
try {
// 过滤掉DeepSeek的思考标签内容
let cleanContent = content.replace(/<think>[\s\S]*?<\/think>/gi, '');
cleanContent = cleanContent.replace(/<think>[\s\S]*$/gi, ''); // 处理未闭合的think标签
cleanContent = cleanContent.trim();
console.log('清理后的内容:', cleanContent);
// 提取稀有度评分(百分比格式)
const rarityMatch = cleanContent.match(/【稀有度评分】[\s\S]*?评分:(\d+)%[\s\S]*?评价:([\s\S]*?)(?=【|$)/);
if (rarityMatch) {
result.rarityScore = rarityMatch[1] + '%';
result.rarityDesc = rarityMatch[2].trim();
}
// 提取音韵评价(百分比格式)
const phoneticMatch = cleanContent.match(/【音韵评价】[\s\S]*?评分:(\d+)%[\s\S]*?评价:([\s\S]*?)(?=【|$)/);
if (phoneticMatch) {
result.phoneticScore = phoneticMatch[1] + '%';
result.phoneticDesc = phoneticMatch[2].trim();
}
// 提取含义解读
const meaningMatch = cleanContent.match(/【含义解读】[\s\S]*?\n([\s\S]+)$/);
if (meaningMatch) {
result.meaningAnalysis = meaningMatch[1].trim();
}
} catch (error) {
console.error('解析结果时出错:', error);
}
return result;
}
// 简单的markdown解析函数
function parseMarkdown(text) {
if (!text || typeof text !== 'string') return text;
// 处理加粗 **text** 或 __text__
let parsed = text.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>');
parsed = parsed.replace(/__(.*?)__/g, '<strong>$1</strong>');
// 处理斜体 *text* 或 _text_
parsed = parsed.replace(/\*(.*?)\*/g, '<em>$1</em>');
parsed = parsed.replace(/_(.*?)_/g, '<em>$1</em>');
// 处理无序列表
const lines = parsed.split('\n');
let inList = false;
let result = [];
for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();
// 检查是否是列表项(以 - 开头,后面跟空格)
if (line.match(/^-\s+/)) {
if (!inList) {
result.push('<ul>');
inList = true;
}
// 移除开头的 "- " 并包装为 <li>
const listContent = line.replace(/^-\s+/, '');
result.push(`<li>${listContent}</li>`);
} else {
if (inList) {
result.push('</ul>');
inList = false;
}
if (line) {
result.push(line);
}
}
}
// 如果最后还在列表中,需要关闭列表
if (inList) {
result.push('</ul>');
}
// 重新组合,用 <br> 连接非列表行
parsed = result.join('<br>');
// 清理多余的 <br> 标签(在列表前后)
parsed = parsed.replace(/<br><ul>/g, '<ul>');
parsed = parsed.replace(/<\/ul><br>/g, '</ul>');
parsed = parsed.replace(/<br><li>/g, '<li>');
parsed = parsed.replace(/<\/li><br>/g, '</li>');
return parsed;
}
// 更新显示结果
function updateResults(result) {
rarityScore.textContent = result.rarityScore;
rarityDesc.innerHTML = parseMarkdown(result.rarityDesc);
phoneticScore.textContent = result.phoneticScore;
phoneticDesc.innerHTML = parseMarkdown(result.phoneticDesc);
meaningAnalysis.innerHTML = parseMarkdown(result.meaningAnalysis);
}
// 重置结果显示
function resetResults() {
rarityScore.textContent = '--%';
rarityDesc.innerHTML = '点击"开始分析"查看结果';
phoneticScore.textContent = '--%';
phoneticDesc.innerHTML = '点击"开始分析"查看结果';
meaningAnalysis.innerHTML = '点击"开始分析"查看姓名的深层寓意';
}
// 显示错误信息
function showError(message) {
// 清除之前的错误信息
const existingError = document.querySelector('.error');
if (existingError) {
existingError.remove();
}
// 创建新的错误信息
const errorDiv = document.createElement('div');
errorDiv.className = 'error';
errorDiv.textContent = `分析失败:${message}`;
document.querySelector('.result-section').appendChild(errorDiv);
}
// 姓名验证
function validateName(name) {
if (!name) {
return '请输入姓名';
}
if (name.length < 2) {
return '姓名至少需要2个字符';
}
if (name.length > 10) {
return '姓名不能超过10个字符';
}
if (!/^[\u4e00-\u9fa5a-zA-Z]+$/.test(name)) {
return '姓名只能包含中文或英文字符';
}
return null;
}
// 主要分析函数
async function analyzeName() {
const name = nameInput.value.trim();
// 验证输入
const validationError = validateName(name);
if (validationError) {
alert(validationError);
return;
}
// 显示加载状态
analyzeBtn.disabled = true;
analyzeBtn.textContent = '分析中...';
loading.style.display = 'block';
resetResults();
// 清除之前的错误信息
const existingError = document.querySelector('.error');
if (existingError) {
existingError.remove();
}
const requestBody = {
name: name
};
try {
// 调用后端API
const response = await fetch('http://127.0.0.1:5002/api/aimodelapp/name-analysis', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestBody)
});
// 检查HTTP状态码
if (response.status === 429) {
throw new Error('短时间内请求次数过多,请休息一下!');
}
if (!response.ok) {
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响应格式异常');
}
} catch (error) {
console.error('分析姓名时出错:', error);
showError(error.message);
resetResults();
} finally {
// 恢复按钮状态
analyzeBtn.disabled = false;
analyzeBtn.textContent = '开始分析';
loading.style.display = 'none';
}
}
// 事件监听器
analyzeBtn.addEventListener('click', analyzeName);
// 回车键快捷分析
nameInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
e.preventDefault();
analyzeName();
}
});
// 输入框内容变化时清除错误信息
nameInput.addEventListener('input', () => {
const existingError = document.querySelector('.error');
if (existingError) {
existingError.remove();
}
});

View File

@@ -0,0 +1,265 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', Arial, sans-serif;
background: linear-gradient(135deg, #87CEEB 0%, #98FB98 100%);
min-height: 100vh;
padding: 20px;
color: #1D1D1F;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.container {
max-width: 700px;
margin: 0 auto;
background: rgba(255, 255, 255, 0.85);
border-radius: 24px;
padding: 32px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
backdrop-filter: blur(20px) saturate(180%);
border: 1px solid rgba(255, 255, 255, 0.2);
}
.header {
text-align: center;
margin-bottom: 32px;
}
.title {
font-size: 2.25rem;
color: #1D1D1F;
margin-bottom: 8px;
font-weight: 600;
letter-spacing: -0.02em;
}
.subtitle {
color: #86868B;
font-size: 1.0625rem;
margin-bottom: 24px;
font-weight: 400;
}
.form-group {
margin-bottom: 24px;
}
.form-label {
display: block;
margin-bottom: 8px;
font-weight: 600;
color: #1D1D1F;
font-size: 1rem;
}
.form-input {
width: 100%;
padding: 16px;
border: 1px solid rgba(0, 0, 0, 0.1);
border-radius: 12px;
font-size: 1rem;
transition: all 0.2s ease;
background: rgba(255, 255, 255, 0.8);
text-align: center;
backdrop-filter: blur(10px);
}
.form-input:focus {
outline: none;
border-color: #007AFF;
background: rgba(255, 255, 255, 0.95);
box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.1);
}
.btn {
width: 100%;
padding: 16px;
background: #007AFF;
color: white;
border: none;
border-radius: 12px;
font-size: 1.0625rem;
font-weight: 600;
cursor: pointer;
transition: all 0.2s ease;
margin-bottom: 24px;
box-shadow: 0 2px 8px rgba(0, 122, 255, 0.25);
}
.btn:hover {
background: #0056CC;
transform: translateY(-1px);
box-shadow: 0 4px 16px rgba(0, 122, 255, 0.35);
}
.btn:active {
transform: translateY(0);
background: #004499;
}
.btn:disabled {
opacity: 0.5;
cursor: not-allowed;
transform: none;
background: #86868B;
}
.result-section {
margin-top: 32px;
}
.result-title {
font-size: 1.25rem;
color: #1D1D1F;
margin-bottom: 20px;
text-align: center;
font-weight: 600;
}
.loading {
display: none;
text-align: center;
color: #007AFF;
font-style: normal;
margin-bottom: 20px;
font-weight: 500;
}
.result-container {
display: grid;
gap: 16px;
grid-template-columns: 1fr;
}
.result-card {
background: rgba(255, 255, 255, 0.6);
border: 1px solid rgba(0, 0, 0, 0.08);
border-radius: 16px;
padding: 24px;
transition: all 0.2s ease;
backdrop-filter: blur(10px);
}
.result-card:hover {
border-color: rgba(0, 122, 255, 0.3);
box-shadow: 0 4px 16px rgba(0, 122, 255, 0.1);
background: rgba(255, 255, 255, 0.8);
}
.card-title {
font-size: 1.0625rem;
color: #1D1D1F;
margin-bottom: 16px;
text-align: center;
font-weight: 600;
}
.score-display {
font-size: 2.25rem;
font-weight: 700;
text-align: center;
margin-bottom: 12px;
background: linear-gradient(135deg, #007AFF 0%, #5856D6 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.score-desc {
text-align: center;
color: #86868B;
font-size: 0.9375rem;
line-height: 1.47;
font-weight: 400;
}
.meaning-content {
color: #1D1D1F;
line-height: 1.6;
font-size: 1rem;
text-align: left;
white-space: pre-wrap;
font-weight: 400;
}
.error {
color: #FF3B30;
background: rgba(255, 59, 48, 0.1);
border: 1px solid rgba(255, 59, 48, 0.2);
padding: 16px;
border-radius: 12px;
margin-top: 16px;
font-weight: 500;
backdrop-filter: blur(10px);
}
/* 平板和桌面端优化 */
@media (min-width: 768px) {
.result-container {
grid-template-columns: 1fr 1fr;
}
.result-card:last-child {
grid-column: 1 / -1;
}
}
/* 手机端优化 */
@media (max-width: 768px) {
body {
padding: 10px;
}
.container {
padding: 20px;
margin: 10px;
}
.title {
font-size: 2rem;
}
.form-input {
padding: 12px;
}
.btn {
padding: 12px;
}
.result-card {
padding: 15px;
}
.score-display {
font-size: 2rem;
}
}
@media (max-width: 480px) {
.title {
font-size: 1.8rem;
letter-spacing: 1px;
}
.container {
padding: 15px;
}
.result-card {
padding: 12px;
}
.score-display {
font-size: 1.8rem;
}
.meaning-content {
font-size: 0.9rem;
}
}