mirror of
https://github.com/Zippland/Snap-Solver.git
synced 2026-03-03 00:25:09 +08:00
移除API密钥验证相关的代码和样式,删除无用的图片文件,优化进度指示器的样式和动画效果,调整设置面板的布局,简化API密钥管理功能,提升用户体验。
This commit is contained in:
@@ -136,51 +136,62 @@ class SnapSolver {
|
||||
}
|
||||
|
||||
updateStatusLight(status) {
|
||||
const statusLight = document.querySelector('.status-light');
|
||||
// 获取进度指示器元素
|
||||
const progressLine = document.querySelector('.progress-line');
|
||||
const statusText = document.querySelector('.status-text');
|
||||
const analysisIndicator = document.querySelector('.analysis-indicator');
|
||||
|
||||
if (!statusLight || !progressLine || !statusText || !analysisIndicator) {
|
||||
if (!progressLine || !statusText || !analysisIndicator) {
|
||||
console.error('状态指示器元素未找到:', {
|
||||
progressLine: !!progressLine,
|
||||
statusText: !!statusText,
|
||||
analysisIndicator: !!analysisIndicator
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 确保指示器可见
|
||||
analysisIndicator.style.display = 'flex';
|
||||
statusLight.classList.remove('completed', 'error', 'working');
|
||||
|
||||
// 先移除所有可能的状态类
|
||||
analysisIndicator.classList.remove('processing', 'completed', 'error');
|
||||
progressLine.classList.remove('processing', 'completed', 'error');
|
||||
|
||||
switch (status) {
|
||||
case 'started':
|
||||
case 'thinking':
|
||||
case 'reasoning':
|
||||
case 'streaming':
|
||||
statusLight.classList.add('working');
|
||||
progressLine.style.animation = 'progress-animation 2s linear infinite';
|
||||
// 添加处理中状态类
|
||||
analysisIndicator.classList.add('processing');
|
||||
progressLine.classList.add('processing');
|
||||
statusText.textContent = '生成中';
|
||||
break;
|
||||
|
||||
case 'completed':
|
||||
statusLight.classList.add('completed');
|
||||
progressLine.style.animation = 'none';
|
||||
progressLine.style.width = '100%';
|
||||
// 添加完成状态类
|
||||
analysisIndicator.classList.add('completed');
|
||||
progressLine.classList.add('completed');
|
||||
statusText.textContent = '完成';
|
||||
break;
|
||||
|
||||
case 'error':
|
||||
statusLight.classList.add('error');
|
||||
progressLine.style.animation = 'none';
|
||||
progressLine.style.width = '100%';
|
||||
// 添加错误状态类
|
||||
analysisIndicator.classList.add('error');
|
||||
progressLine.classList.add('error');
|
||||
statusText.textContent = '出错';
|
||||
break;
|
||||
|
||||
case 'stopped':
|
||||
statusLight.classList.add('error');
|
||||
progressLine.style.animation = 'none';
|
||||
progressLine.style.width = '100%';
|
||||
// 添加错误状态类(用于停止状态)
|
||||
analysisIndicator.classList.add('error');
|
||||
progressLine.classList.add('error');
|
||||
statusText.textContent = '已停止';
|
||||
break;
|
||||
|
||||
default:
|
||||
analysisIndicator.style.display = 'none';
|
||||
// 对于未知状态,显示准备中
|
||||
statusText.textContent = '准备中';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,45 +230,6 @@ class SettingsManager {
|
||||
});
|
||||
});
|
||||
|
||||
// Initialize API key validate buttons
|
||||
document.querySelectorAll('.validate-api-key').forEach(button => {
|
||||
button.addEventListener('click', (e) => {
|
||||
const keyType = e.currentTarget.getAttribute('data-key-type');
|
||||
const input = e.currentTarget.closest('.input-group').querySelector('input');
|
||||
const keyValue = input.value;
|
||||
|
||||
if (keyValue.trim() === '') {
|
||||
window.uiManager?.showToast('请先输入API密钥', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
// 显示验证中状态
|
||||
const icon = e.currentTarget.querySelector('i');
|
||||
const originalClass = icon.className;
|
||||
icon.className = 'fas fa-spinner fa-spin';
|
||||
e.currentTarget.disabled = true;
|
||||
|
||||
this.validateApiKey(keyType, keyValue)
|
||||
.then(result => {
|
||||
if (result.success) {
|
||||
window.uiManager?.showToast(result.message, 'success');
|
||||
// 更新状态显示
|
||||
this.saveSettings();
|
||||
} else {
|
||||
window.uiManager?.showToast(result.message, 'error');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
window.uiManager?.showToast(`验证失败: ${error.message}`, 'error');
|
||||
})
|
||||
.finally(() => {
|
||||
// 恢复按钮状态
|
||||
icon.className = originalClass;
|
||||
e.currentTarget.disabled = false;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// 存储API密钥的对象
|
||||
this.apiKeyValues = {
|
||||
'AnthropicApiKey': '',
|
||||
@@ -1005,36 +966,6 @@ class SettingsManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证API密钥
|
||||
* @param {string} keyType 密钥类型
|
||||
* @param {string} keyValue 密钥值
|
||||
* @returns {Promise<Object>} 验证结果
|
||||
*/
|
||||
async validateApiKey(keyType, keyValue) {
|
||||
try {
|
||||
const response = await fetch('/api/keys/validate', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
key_type: keyType,
|
||||
key_value: keyValue
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`服务器响应错误: ${response.status}`);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error('验证API密钥时出错:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个Toast提示消息
|
||||
* @param {string} message 提示消息内容
|
||||
|
||||
Reference in New Issue
Block a user