From 86d60aad77c6d606f25d3760fefc52fc43997c8c Mon Sep 17 00:00:00 2001 From: hkfires <10558748+hkfires@users.noreply.github.com> Date: Mon, 13 Oct 2025 15:56:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BD=BF=E7=94=A8=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ i18n.js | 6 ++++++ index.html | 18 ++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/app.js b/app.js index f07660a..d52f472 100644 --- a/app.js +++ b/app.js @@ -494,6 +494,7 @@ class CLIProxyManager { const updateRetry = document.getElementById('update-retry'); const switchProjectToggle = document.getElementById('switch-project-toggle'); const switchPreviewToggle = document.getElementById('switch-preview-model-toggle'); + const usageStatisticsToggle = document.getElementById('usage-statistics-enabled-toggle'); if (debugToggle) { debugToggle.addEventListener('change', (e) => this.updateDebug(e.target.checked)); @@ -513,6 +514,9 @@ class CLIProxyManager { if (switchPreviewToggle) { switchPreviewToggle.addEventListener('change', (e) => this.updateSwitchPreviewModel(e.target.checked)); } + if (usageStatisticsToggle) { + usageStatisticsToggle.addEventListener('change', (e) => this.updateUsageStatisticsEnabled(e.target.checked)); + } // API 密钥管理 const addApiKey = document.getElementById('add-api-key'); @@ -1152,6 +1156,13 @@ class CLIProxyManager { } } + if (config['usage-statistics-enabled'] !== undefined) { + const usageToggle = document.getElementById('usage-statistics-enabled-toggle'); + if (usageToggle) { + usageToggle.checked = config['usage-statistics-enabled']; + } + } + // API 密钥 if (config['api-keys']) { @@ -1186,6 +1197,7 @@ class CLIProxyManager { this.loadProxySettings(), this.loadRetrySettings(), this.loadQuotaSettings(), + this.loadUsageStatisticsSettings(), this.loadApiKeys(), this.loadGeminiKeys(), this.loadCodexKeys(), @@ -1308,6 +1320,39 @@ class CLIProxyManager { } } + // 加载使用统计设置 + async loadUsageStatisticsSettings() { + try { + const config = await this.getConfig(); + if (config['usage-statistics-enabled'] !== undefined) { + const usageToggle = document.getElementById('usage-statistics-enabled-toggle'); + if (usageToggle) { + usageToggle.checked = config['usage-statistics-enabled']; + } + } + } catch (error) { + console.error('加载使用统计设置失败:', error); + } + } + + // 更新使用统计设置 + async updateUsageStatisticsEnabled(enabled) { + try { + await this.makeRequest('/usage-statistics-enabled', { + method: 'PUT', + body: JSON.stringify({ value: enabled }) + }); + this.clearCache(); + this.showNotification(i18n.t('notification.usage_statistics_updated'), 'success'); + } catch (error) { + this.showNotification(`${i18n.t('notification.update_failed')}: ${error.message}`, 'error'); + const usageToggle = document.getElementById('usage-statistics-enabled-toggle'); + if (usageToggle) { + usageToggle.checked = !enabled; + } + } + } + // 更新项目切换设置 async updateSwitchProject(enabled) { try { diff --git a/i18n.js b/i18n.js index b57919d..9adf7ba 100644 --- a/i18n.js +++ b/i18n.js @@ -99,6 +99,8 @@ const i18n = { 'basic_settings.quota_title': '配额超出行为', 'basic_settings.quota_switch_project': '自动切换项目', 'basic_settings.quota_switch_preview': '切换到预览模型', + 'basic_settings.usage_statistics_title': '使用统计', + 'basic_settings.usage_statistics_enable': '启用使用统计', // API 密钥管理 'api_keys.title': 'API 密钥管理', @@ -321,6 +323,7 @@ const i18n = { 'notification.retry_updated': '重试设置已更新', 'notification.quota_switch_project_updated': '项目切换设置已更新', 'notification.quota_switch_preview_updated': '预览模型切换设置已更新', + 'notification.usage_statistics_updated': '使用统计设置已更新', 'notification.api_key_added': 'API密钥添加成功', 'notification.api_key_updated': 'API密钥更新成功', 'notification.api_key_deleted': 'API密钥删除成功', @@ -467,6 +470,8 @@ const i18n = { 'basic_settings.quota_title': 'Quota Exceeded Behavior', 'basic_settings.quota_switch_project': 'Auto Switch Project', 'basic_settings.quota_switch_preview': 'Switch to Preview Model', + 'basic_settings.usage_statistics_title': 'Usage Statistics', + 'basic_settings.usage_statistics_enable': 'Enable usage statistics', // API Keys management 'api_keys.title': 'API Keys Management', @@ -688,6 +693,7 @@ const i18n = { 'notification.retry_updated': 'Retry settings updated', 'notification.quota_switch_project_updated': 'Project switch settings updated', 'notification.quota_switch_preview_updated': 'Preview model switch settings updated', + 'notification.usage_statistics_updated': 'Usage statistics settings updated', 'notification.api_key_added': 'API key added successfully', 'notification.api_key_updated': 'API key updated successfully', 'notification.api_key_deleted': 'API key deleted successfully', diff --git a/index.html b/index.html index e42bc17..ae644c1 100644 --- a/index.html +++ b/index.html @@ -275,6 +275,24 @@ + +