mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-03 11:20:50 +08:00
增加使用统计开关
This commit is contained in:
45
app.js
45
app.js
@@ -494,6 +494,7 @@ class CLIProxyManager {
|
|||||||
const updateRetry = document.getElementById('update-retry');
|
const updateRetry = document.getElementById('update-retry');
|
||||||
const switchProjectToggle = document.getElementById('switch-project-toggle');
|
const switchProjectToggle = document.getElementById('switch-project-toggle');
|
||||||
const switchPreviewToggle = document.getElementById('switch-preview-model-toggle');
|
const switchPreviewToggle = document.getElementById('switch-preview-model-toggle');
|
||||||
|
const usageStatisticsToggle = document.getElementById('usage-statistics-enabled-toggle');
|
||||||
|
|
||||||
if (debugToggle) {
|
if (debugToggle) {
|
||||||
debugToggle.addEventListener('change', (e) => this.updateDebug(e.target.checked));
|
debugToggle.addEventListener('change', (e) => this.updateDebug(e.target.checked));
|
||||||
@@ -513,6 +514,9 @@ class CLIProxyManager {
|
|||||||
if (switchPreviewToggle) {
|
if (switchPreviewToggle) {
|
||||||
switchPreviewToggle.addEventListener('change', (e) => this.updateSwitchPreviewModel(e.target.checked));
|
switchPreviewToggle.addEventListener('change', (e) => this.updateSwitchPreviewModel(e.target.checked));
|
||||||
}
|
}
|
||||||
|
if (usageStatisticsToggle) {
|
||||||
|
usageStatisticsToggle.addEventListener('change', (e) => this.updateUsageStatisticsEnabled(e.target.checked));
|
||||||
|
}
|
||||||
|
|
||||||
// API 密钥管理
|
// API 密钥管理
|
||||||
const addApiKey = document.getElementById('add-api-key');
|
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 密钥
|
// API 密钥
|
||||||
if (config['api-keys']) {
|
if (config['api-keys']) {
|
||||||
@@ -1186,6 +1197,7 @@ class CLIProxyManager {
|
|||||||
this.loadProxySettings(),
|
this.loadProxySettings(),
|
||||||
this.loadRetrySettings(),
|
this.loadRetrySettings(),
|
||||||
this.loadQuotaSettings(),
|
this.loadQuotaSettings(),
|
||||||
|
this.loadUsageStatisticsSettings(),
|
||||||
this.loadApiKeys(),
|
this.loadApiKeys(),
|
||||||
this.loadGeminiKeys(),
|
this.loadGeminiKeys(),
|
||||||
this.loadCodexKeys(),
|
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) {
|
async updateSwitchProject(enabled) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
6
i18n.js
6
i18n.js
@@ -99,6 +99,8 @@ const i18n = {
|
|||||||
'basic_settings.quota_title': '配额超出行为',
|
'basic_settings.quota_title': '配额超出行为',
|
||||||
'basic_settings.quota_switch_project': '自动切换项目',
|
'basic_settings.quota_switch_project': '自动切换项目',
|
||||||
'basic_settings.quota_switch_preview': '切换到预览模型',
|
'basic_settings.quota_switch_preview': '切换到预览模型',
|
||||||
|
'basic_settings.usage_statistics_title': '使用统计',
|
||||||
|
'basic_settings.usage_statistics_enable': '启用使用统计',
|
||||||
|
|
||||||
// API 密钥管理
|
// API 密钥管理
|
||||||
'api_keys.title': 'API 密钥管理',
|
'api_keys.title': 'API 密钥管理',
|
||||||
@@ -321,6 +323,7 @@ const i18n = {
|
|||||||
'notification.retry_updated': '重试设置已更新',
|
'notification.retry_updated': '重试设置已更新',
|
||||||
'notification.quota_switch_project_updated': '项目切换设置已更新',
|
'notification.quota_switch_project_updated': '项目切换设置已更新',
|
||||||
'notification.quota_switch_preview_updated': '预览模型切换设置已更新',
|
'notification.quota_switch_preview_updated': '预览模型切换设置已更新',
|
||||||
|
'notification.usage_statistics_updated': '使用统计设置已更新',
|
||||||
'notification.api_key_added': 'API密钥添加成功',
|
'notification.api_key_added': 'API密钥添加成功',
|
||||||
'notification.api_key_updated': 'API密钥更新成功',
|
'notification.api_key_updated': 'API密钥更新成功',
|
||||||
'notification.api_key_deleted': 'API密钥删除成功',
|
'notification.api_key_deleted': 'API密钥删除成功',
|
||||||
@@ -467,6 +470,8 @@ const i18n = {
|
|||||||
'basic_settings.quota_title': 'Quota Exceeded Behavior',
|
'basic_settings.quota_title': 'Quota Exceeded Behavior',
|
||||||
'basic_settings.quota_switch_project': 'Auto Switch Project',
|
'basic_settings.quota_switch_project': 'Auto Switch Project',
|
||||||
'basic_settings.quota_switch_preview': 'Switch to Preview Model',
|
'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 management
|
||||||
'api_keys.title': 'API Keys Management',
|
'api_keys.title': 'API Keys Management',
|
||||||
@@ -688,6 +693,7 @@ const i18n = {
|
|||||||
'notification.retry_updated': 'Retry settings updated',
|
'notification.retry_updated': 'Retry settings updated',
|
||||||
'notification.quota_switch_project_updated': 'Project switch settings updated',
|
'notification.quota_switch_project_updated': 'Project switch settings updated',
|
||||||
'notification.quota_switch_preview_updated': 'Preview model 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_added': 'API key added successfully',
|
||||||
'notification.api_key_updated': 'API key updated successfully',
|
'notification.api_key_updated': 'API key updated successfully',
|
||||||
'notification.api_key_deleted': 'API key deleted successfully',
|
'notification.api_key_deleted': 'API key deleted successfully',
|
||||||
|
|||||||
18
index.html
18
index.html
@@ -275,6 +275,24 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- 使用统计设置 -->
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h3><i class="fas fa-chart-bar"></i> <span
|
||||||
|
data-i18n="basic_settings.usage_statistics_title">使用统计</span></h3>
|
||||||
|
</div>
|
||||||
|
<div class="card-content">
|
||||||
|
<div class="toggle-group">
|
||||||
|
<label class="toggle-switch">
|
||||||
|
<input type="checkbox" id="usage-statistics-enabled-toggle">
|
||||||
|
<span class="slider"></span>
|
||||||
|
</label>
|
||||||
|
<span class="toggle-label"
|
||||||
|
data-i18n="basic_settings.usage_statistics_enable">启用使用统计</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<!-- API 密钥管理 -->
|
<!-- API 密钥管理 -->
|
||||||
|
|||||||
Reference in New Issue
Block a user