mirror of
https://github.com/Zippland/Snap-Solver.git
synced 2026-02-27 08:01:10 +08:00
添加百度OCR支持,更新OCR源选择和设置界面
This commit is contained in:
@@ -1053,10 +1053,33 @@ class SnapSolver {
|
||||
this.extractTextBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i><span>提取中...</span>';
|
||||
|
||||
const settings = window.settingsManager.getSettings();
|
||||
|
||||
// 根据用户设置的OCR源进行选择
|
||||
const ocrSource = settings.ocrSource || 'auto';
|
||||
const baiduApiKey = window.settingsManager.apiKeyValues.BaiduApiKey;
|
||||
const baiduSecretKey = window.settingsManager.apiKeyValues.BaiduSecretKey;
|
||||
const mathpixApiKey = settings.mathpixApiKey;
|
||||
|
||||
if (!mathpixApiKey || mathpixApiKey === ':') {
|
||||
window.uiManager.showToast('请在设置中输入Mathpix API凭据', 'error');
|
||||
const hasBaiduOCR = baiduApiKey && baiduSecretKey;
|
||||
const hasMathpix = mathpixApiKey && mathpixApiKey !== ':';
|
||||
|
||||
// 根据OCR源配置检查可用性
|
||||
let canProceed = false;
|
||||
let missingOCRMessage = '';
|
||||
|
||||
if (ocrSource === 'baidu') {
|
||||
canProceed = hasBaiduOCR;
|
||||
missingOCRMessage = '请在设置中配置百度OCR API密钥';
|
||||
} else if (ocrSource === 'mathpix') {
|
||||
canProceed = hasMathpix;
|
||||
missingOCRMessage = '请在设置中配置Mathpix API密钥';
|
||||
} else { // auto
|
||||
canProceed = hasBaiduOCR || hasMathpix;
|
||||
missingOCRMessage = '请在设置中配置OCR API密钥:百度OCR(推荐)或Mathpix';
|
||||
}
|
||||
|
||||
if (!canProceed) {
|
||||
window.uiManager.showToast(missingOCRMessage, 'error');
|
||||
document.getElementById('settingsPanel').classList.add('active');
|
||||
this.extractTextBtn.disabled = false;
|
||||
this.extractTextBtn.innerHTML = '<i class="fas fa-font"></i><span>提取文本</span>';
|
||||
@@ -1076,7 +1099,7 @@ class SnapSolver {
|
||||
this.socket.emit('extract_text', {
|
||||
image: this.croppedImage.split(',')[1],
|
||||
settings: {
|
||||
mathpixApiKey: mathpixApiKey
|
||||
ocrSource: settings.ocrSource || 'auto'
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -374,6 +374,9 @@ class SettingsManager {
|
||||
// 模型选择器对象
|
||||
this.modelSelector = null;
|
||||
|
||||
// OCR源配置
|
||||
this.ocrSource = 'auto'; // 默认自动选择
|
||||
|
||||
// 存储API密钥的对象
|
||||
this.apiKeyValues = {
|
||||
'AnthropicApiKey': '',
|
||||
@@ -382,6 +385,8 @@ class SettingsManager {
|
||||
'AlibabaApiKey': '',
|
||||
'GoogleApiKey': '',
|
||||
'DoubaoApiKey': '',
|
||||
'BaiduApiKey': '',
|
||||
'BaiduSecretKey': '',
|
||||
'MathpixAppId': '',
|
||||
'MathpixAppKey': ''
|
||||
};
|
||||
@@ -626,6 +631,14 @@ class SettingsManager {
|
||||
this.proxyPortInput.value = settings.proxyPort;
|
||||
}
|
||||
|
||||
// Load OCR source setting
|
||||
if (settings.ocrSource) {
|
||||
this.ocrSource = settings.ocrSource;
|
||||
if (this.ocrSourceSelect) {
|
||||
this.ocrSourceSelect.value = settings.ocrSource;
|
||||
}
|
||||
}
|
||||
|
||||
// Update UI based on model type
|
||||
this.updateUIBasedOnModelType();
|
||||
|
||||
@@ -786,7 +799,8 @@ class SettingsManager {
|
||||
currentPromptId: this.currentPromptId,
|
||||
proxyEnabled: this.proxyEnabledInput.checked,
|
||||
proxyHost: this.proxyHostInput.value,
|
||||
proxyPort: this.proxyPortInput.value
|
||||
proxyPort: this.proxyPortInput.value,
|
||||
ocrSource: this.ocrSource // 添加OCR源配置保存
|
||||
};
|
||||
|
||||
// 保存设置到localStorage
|
||||
@@ -888,6 +902,7 @@ class SettingsManager {
|
||||
proxyHost: this.proxyHostInput.value,
|
||||
proxyPort: this.proxyPortInput.value,
|
||||
mathpixApiKey: mathpixApiKey,
|
||||
ocrSource: this.ocrSource, // 添加OCR源配置
|
||||
modelInfo: {
|
||||
supportsMultimodal: modelInfo.supportsMultimodal || false,
|
||||
isReasoning: modelInfo.isReasoning || false,
|
||||
@@ -1128,6 +1143,20 @@ class SettingsManager {
|
||||
this.saveSettings();
|
||||
});
|
||||
|
||||
// OCR源选择器事件监听
|
||||
if (this.ocrSourceSelect) {
|
||||
this.ocrSourceSelect.addEventListener('change', (e) => {
|
||||
// 阻止事件冒泡
|
||||
e.stopPropagation();
|
||||
|
||||
// 更新OCR源配置
|
||||
this.ocrSource = e.target.value;
|
||||
this.saveSettings();
|
||||
|
||||
console.log('OCR源已切换为:', this.ocrSource);
|
||||
});
|
||||
}
|
||||
|
||||
// Panel visibility
|
||||
if (this.settingsToggle) {
|
||||
this.settingsToggle.addEventListener('click', () => {
|
||||
@@ -2219,6 +2248,9 @@ class SettingsManager {
|
||||
this.mathpixAppIdInput = document.getElementById('mathpixAppId');
|
||||
this.mathpixAppKeyInput = document.getElementById('mathpixAppKey');
|
||||
|
||||
// OCR源选择器
|
||||
this.ocrSourceSelect = document.getElementById('ocrSourceSelect');
|
||||
|
||||
// API Key elements - 所有的密钥输入框
|
||||
this.apiKeyInputs = {
|
||||
'AnthropicApiKey': document.getElementById('AnthropicApiKey'),
|
||||
@@ -2268,6 +2300,8 @@ class SettingsManager {
|
||||
'AlibabaApiKey': '',
|
||||
'GoogleApiKey': '',
|
||||
'DoubaoApiKey': '',
|
||||
'BaiduApiKey': '',
|
||||
'BaiduSecretKey': '',
|
||||
'MathpixAppId': '',
|
||||
'MathpixAppKey': ''
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user