mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 21:17:30 +00:00
feat: 全新的Vue3管理后台(admin-spa)和路由重构
🎨 新增功能: - 使用Vue3 + Vite构建的全新管理后台界面 - 支持Tab切换的API统计页面(统计查询/使用教程) - 优雅的胶囊式Tab切换设计 - 同步了PR #106的会话窗口管理功能 - 完整的响应式设计和骨架屏加载状态 🔧 路由调整: - 新版管理后台部署在 /admin-next/ 路径 - 将根路径 / 重定向到 /admin-next/api-stats - 将 /web 页面路由重定向到新版,保留 /web/auth/* 认证路由 - 将 /apiStats 页面路由重定向到新版,保留API端点 🗑️ 清理工作: - 删除旧版 web/admin/ 静态文件 - 删除旧版 web/apiStats/ 静态文件 - 清理相关的文件服务代码 🐛 修复问题: - 修复重定向循环问题 - 修复环境变量配置 - 修复路由404错误 - 优化构建配置 🚀 生成方式:使用 Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
81
web/admin-spa/src/config/apiStats.js
Normal file
81
web/admin-spa/src/config/apiStats.js
Normal file
@@ -0,0 +1,81 @@
|
||||
// API Stats 专用 API 客户端
|
||||
// 与管理员 API 隔离,不需要认证
|
||||
|
||||
class ApiStatsClient {
|
||||
constructor() {
|
||||
this.baseURL = window.location.origin
|
||||
// 开发环境需要为 admin 路径添加 /webapi 前缀
|
||||
this.isDev = import.meta.env.DEV
|
||||
}
|
||||
|
||||
async request(url, options = {}) {
|
||||
try {
|
||||
// 在开发环境中,为 /admin 路径添加 /webapi 前缀
|
||||
if (this.isDev && url.startsWith('/admin')) {
|
||||
url = '/webapi' + url
|
||||
}
|
||||
|
||||
const response = await fetch(`${this.baseURL}${url}`, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...options.headers
|
||||
},
|
||||
...options
|
||||
})
|
||||
|
||||
const data = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.message || `请求失败: ${response.status}`)
|
||||
}
|
||||
|
||||
return data
|
||||
} catch (error) {
|
||||
console.error('API Stats request error:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// 获取 API Key ID
|
||||
async getKeyId(apiKey) {
|
||||
return this.request('/apiStats/api/get-key-id', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ apiKey })
|
||||
})
|
||||
}
|
||||
|
||||
// 获取用户统计数据
|
||||
async getUserStats(apiId) {
|
||||
return this.request('/apiStats/api/user-stats', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ apiId })
|
||||
})
|
||||
}
|
||||
|
||||
// 获取模型使用统计
|
||||
async getUserModelStats(apiId, period = 'daily') {
|
||||
return this.request('/apiStats/api/user-model-stats', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ apiId, period })
|
||||
})
|
||||
}
|
||||
|
||||
// 获取 OEM 设置(用于网站名称和图标)
|
||||
async getOemSettings() {
|
||||
try {
|
||||
return await this.request('/admin/oem-settings')
|
||||
} catch (error) {
|
||||
console.error('Failed to load OEM settings:', error)
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
siteName: 'Claude Relay Service',
|
||||
siteIcon: '',
|
||||
siteIconData: ''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const apiStatsClient = new ApiStatsClient()
|
||||
Reference in New Issue
Block a user