mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 00:53:33 +00:00
Merge remote-tracking branch 'f3n9/dev' into dev-um-8
This commit is contained in:
@@ -244,19 +244,47 @@
|
||||
>选择分组 *</label
|
||||
>
|
||||
<div class="flex gap-2">
|
||||
<select
|
||||
v-model="form.groupId"
|
||||
class="form-input flex-1 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-200"
|
||||
required
|
||||
>
|
||||
<option value="">请选择分组</option>
|
||||
<option v-for="group in filteredGroups" :key="group.id" :value="group.id">
|
||||
{{ group.name }} ({{ group.memberCount || 0 }} 个成员)
|
||||
</option>
|
||||
<option value="__new__">+ 新建分组</option>
|
||||
</select>
|
||||
<div class="flex-1">
|
||||
<!-- 多选分组界面 -->
|
||||
<div
|
||||
class="max-h-48 space-y-2 overflow-y-auto rounded-md border p-3 dark:border-gray-600 dark:bg-gray-700"
|
||||
>
|
||||
<div
|
||||
v-if="filteredGroups.length === 0"
|
||||
class="text-sm text-gray-500 dark:text-gray-400"
|
||||
>
|
||||
暂无可用分组
|
||||
</div>
|
||||
<label
|
||||
v-for="group in filteredGroups"
|
||||
:key="group.id"
|
||||
class="flex cursor-pointer items-center gap-2 rounded-md p-2 hover:bg-gray-50 dark:hover:bg-gray-600"
|
||||
>
|
||||
<input
|
||||
v-model="form.groupIds"
|
||||
class="rounded border-gray-300 text-blue-600 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700"
|
||||
type="checkbox"
|
||||
:value="group.id"
|
||||
/>
|
||||
<span class="text-sm text-gray-700 dark:text-gray-200">
|
||||
{{ group.name }} ({{ group.memberCount || 0 }} 个成员)
|
||||
</span>
|
||||
</label>
|
||||
<!-- 新建分组选项 -->
|
||||
<div class="border-t pt-2 dark:border-gray-600">
|
||||
<button
|
||||
class="flex items-center gap-2 text-sm text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300"
|
||||
type="button"
|
||||
@click="handleNewGroup"
|
||||
>
|
||||
<i class="fas fa-plus" />
|
||||
新建分组
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
class="rounded-md border border-gray-300 bg-white px-3 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"
|
||||
class="rounded-md border border-gray-300 bg-white px-3 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-200 dark:hover:bg-gray-600"
|
||||
type="button"
|
||||
@click="refreshGroups"
|
||||
>
|
||||
@@ -1269,19 +1297,47 @@
|
||||
>选择分组 *</label
|
||||
>
|
||||
<div class="flex gap-2">
|
||||
<select
|
||||
v-model="form.groupId"
|
||||
class="form-input flex-1 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-200"
|
||||
required
|
||||
>
|
||||
<option value="">请选择分组</option>
|
||||
<option v-for="group in filteredGroups" :key="group.id" :value="group.id">
|
||||
{{ group.name }} ({{ group.memberCount || 0 }} 个成员)
|
||||
</option>
|
||||
<option value="__new__">+ 新建分组</option>
|
||||
</select>
|
||||
<div class="flex-1">
|
||||
<!-- 多选分组界面 -->
|
||||
<div
|
||||
class="max-h-48 space-y-2 overflow-y-auto rounded-md border p-3 dark:border-gray-600 dark:bg-gray-700"
|
||||
>
|
||||
<div
|
||||
v-if="filteredGroups.length === 0"
|
||||
class="text-sm text-gray-500 dark:text-gray-400"
|
||||
>
|
||||
暂无可用分组
|
||||
</div>
|
||||
<label
|
||||
v-for="group in filteredGroups"
|
||||
:key="group.id"
|
||||
class="flex cursor-pointer items-center gap-2 rounded-md p-2 hover:bg-gray-50 dark:hover:bg-gray-600"
|
||||
>
|
||||
<input
|
||||
v-model="form.groupIds"
|
||||
class="rounded border-gray-300 text-blue-600 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700"
|
||||
type="checkbox"
|
||||
:value="group.id"
|
||||
/>
|
||||
<span class="text-sm text-gray-700 dark:text-gray-200">
|
||||
{{ group.name }} ({{ group.memberCount || 0 }} 个成员)
|
||||
</span>
|
||||
</label>
|
||||
<!-- 新建分组选项 -->
|
||||
<div class="border-t pt-2 dark:border-gray-600">
|
||||
<button
|
||||
class="flex items-center gap-2 text-sm text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300"
|
||||
type="button"
|
||||
@click="handleNewGroup"
|
||||
>
|
||||
<i class="fas fa-plus" />
|
||||
新建分组
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
class="rounded-md border border-gray-300 bg-white px-3 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-300 dark:hover:bg-gray-700"
|
||||
class="rounded-md border border-gray-300 bg-white px-3 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-200 dark:hover:bg-gray-600"
|
||||
type="button"
|
||||
@click="refreshGroups"
|
||||
>
|
||||
@@ -1923,6 +1979,7 @@ const form = ref({
|
||||
subscriptionType: 'claude_max', // 默认为 Claude Max,兼容旧数据
|
||||
autoStopOnWarning: props.account?.autoStopOnWarning || false, // 5小时限制自动停止调度
|
||||
groupId: '',
|
||||
groupIds: [],
|
||||
projectId: props.account?.projectId || '',
|
||||
idToken: '',
|
||||
accessToken: '',
|
||||
@@ -2030,15 +2087,24 @@ const nextStep = async () => {
|
||||
return
|
||||
}
|
||||
|
||||
// 分组类型验证
|
||||
// 分组类型验证 - OAuth流程修复
|
||||
if (
|
||||
form.value.accountType === 'group' &&
|
||||
(!form.value.groupId || form.value.groupId.trim() === '')
|
||||
(!form.value.groupIds || form.value.groupIds.length === 0)
|
||||
) {
|
||||
showToast('请选择一个分组', 'error')
|
||||
return
|
||||
}
|
||||
|
||||
// 数据同步:确保 groupId 和 groupIds 保持一致 - OAuth流程
|
||||
if (form.value.accountType === 'group') {
|
||||
if (form.value.groupIds && form.value.groupIds.length > 0) {
|
||||
form.value.groupId = form.value.groupIds[0]
|
||||
} else {
|
||||
form.value.groupId = ''
|
||||
}
|
||||
}
|
||||
|
||||
// 对于Gemini账户,检查项目 ID
|
||||
if (form.value.platform === 'gemini' && oauthStep.value === 1 && form.value.addType === 'oauth') {
|
||||
if (!form.value.projectId || form.value.projectId.trim() === '') {
|
||||
@@ -2172,6 +2238,7 @@ const handleOAuthSuccess = async (tokenInfo) => {
|
||||
description: form.value.description,
|
||||
accountType: form.value.accountType,
|
||||
groupId: form.value.accountType === 'group' ? form.value.groupId : undefined,
|
||||
groupIds: form.value.accountType === 'group' ? form.value.groupIds : undefined,
|
||||
proxy: form.value.proxy.enabled
|
||||
? {
|
||||
type: form.value.proxy.type,
|
||||
@@ -2295,15 +2362,24 @@ const createAccount = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 分组类型验证
|
||||
// 分组类型验证 - 创建账户流程修复
|
||||
if (
|
||||
form.value.accountType === 'group' &&
|
||||
(!form.value.groupId || form.value.groupId.trim() === '')
|
||||
(!form.value.groupIds || form.value.groupIds.length === 0)
|
||||
) {
|
||||
showToast('请选择一个分组', 'error')
|
||||
hasError = true
|
||||
}
|
||||
|
||||
// 数据同步:确保 groupId 和 groupIds 保持一致 - 创建流程
|
||||
if (form.value.accountType === 'group') {
|
||||
if (form.value.groupIds && form.value.groupIds.length > 0) {
|
||||
form.value.groupId = form.value.groupIds[0]
|
||||
} else {
|
||||
form.value.groupId = ''
|
||||
}
|
||||
}
|
||||
|
||||
if (hasError) {
|
||||
return
|
||||
}
|
||||
@@ -2315,6 +2391,7 @@ const createAccount = async () => {
|
||||
description: form.value.description,
|
||||
accountType: form.value.accountType,
|
||||
groupId: form.value.accountType === 'group' ? form.value.groupId : undefined,
|
||||
groupIds: form.value.accountType === 'group' ? form.value.groupIds : undefined,
|
||||
proxy: form.value.proxy.enabled
|
||||
? {
|
||||
type: form.value.proxy.type,
|
||||
@@ -2450,6 +2527,8 @@ const createAccount = async () => {
|
||||
? form.value.supportedModels
|
||||
: []
|
||||
data.priority = form.value.priority || 50
|
||||
data.isActive = form.value.isActive !== false
|
||||
data.schedulable = form.value.schedulable !== false
|
||||
}
|
||||
|
||||
let result
|
||||
@@ -2463,8 +2542,10 @@ const createAccount = async () => {
|
||||
result = await accountsStore.createOpenAIAccount(data)
|
||||
} else if (form.value.platform === 'azure_openai') {
|
||||
result = await accountsStore.createAzureOpenAIAccount(data)
|
||||
} else {
|
||||
} else if (form.value.platform === 'gemini') {
|
||||
result = await accountsStore.createGeminiAccount(data)
|
||||
} else {
|
||||
throw new Error(`不支持的平台: ${form.value.platform}`)
|
||||
}
|
||||
|
||||
emit('success', result)
|
||||
@@ -2486,15 +2567,24 @@ const updateAccount = async () => {
|
||||
return
|
||||
}
|
||||
|
||||
// 分组类型验证
|
||||
// 分组类型验证 - 更新账户流程修复
|
||||
if (
|
||||
form.value.accountType === 'group' &&
|
||||
(!form.value.groupId || form.value.groupId.trim() === '')
|
||||
(!form.value.groupIds || form.value.groupIds.length === 0)
|
||||
) {
|
||||
showToast('请选择一个分组', 'error')
|
||||
return
|
||||
}
|
||||
|
||||
// 数据同步:确保 groupId 和 groupIds 保持一致 - 更新流程
|
||||
if (form.value.accountType === 'group') {
|
||||
if (form.value.groupIds && form.value.groupIds.length > 0) {
|
||||
form.value.groupId = form.value.groupIds[0]
|
||||
} else {
|
||||
form.value.groupId = ''
|
||||
}
|
||||
}
|
||||
|
||||
// 对于Gemini账户,检查项目 ID
|
||||
if (form.value.platform === 'gemini') {
|
||||
if (!form.value.projectId || form.value.projectId.trim() === '') {
|
||||
@@ -2518,6 +2608,7 @@ const updateAccount = async () => {
|
||||
description: form.value.description,
|
||||
accountType: form.value.accountType,
|
||||
groupId: form.value.accountType === 'group' ? form.value.groupId : undefined,
|
||||
groupIds: form.value.accountType === 'group' ? form.value.groupIds : undefined,
|
||||
proxy: form.value.proxy.enabled
|
||||
? {
|
||||
type: form.value.proxy.type,
|
||||
@@ -2662,8 +2753,10 @@ const updateAccount = async () => {
|
||||
await accountsStore.updateOpenAIAccount(props.account.id, data)
|
||||
} else if (props.account.platform === 'azure_openai') {
|
||||
await accountsStore.updateAzureOpenAIAccount(props.account.id, data)
|
||||
} else {
|
||||
} else if (props.account.platform === 'gemini') {
|
||||
await accountsStore.updateGeminiAccount(props.account.id, data)
|
||||
} else {
|
||||
throw new Error(`不支持的平台: ${props.account.platform}`)
|
||||
}
|
||||
|
||||
emit('success')
|
||||
@@ -2765,6 +2858,11 @@ const refreshGroups = async () => {
|
||||
showToast('分组列表已刷新', 'success')
|
||||
}
|
||||
|
||||
// 处理新建分组
|
||||
const handleNewGroup = () => {
|
||||
showGroupManagement.value = true
|
||||
}
|
||||
|
||||
// 处理分组管理模态框刷新
|
||||
const handleGroupRefresh = async () => {
|
||||
await loadGroups()
|
||||
@@ -2791,10 +2889,28 @@ watch(
|
||||
// 平台变化时,清空分组选择
|
||||
if (form.value.accountType === 'group') {
|
||||
form.value.groupId = ''
|
||||
form.value.groupIds = []
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// 监听分组选择变化,保持 groupId 和 groupIds 同步
|
||||
watch(
|
||||
() => form.value.groupIds,
|
||||
(newGroupIds) => {
|
||||
if (form.value.accountType === 'group') {
|
||||
if (newGroupIds && newGroupIds.length > 0) {
|
||||
// 如果有选中的分组,使用第一个作为主分组
|
||||
form.value.groupId = newGroupIds[0]
|
||||
} else {
|
||||
// 如果没有选中分组,清空主分组
|
||||
form.value.groupId = ''
|
||||
}
|
||||
}
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
// 监听Setup Token授权码输入,自动提取URL中的code参数
|
||||
watch(setupTokenAuthCode, (newValue) => {
|
||||
if (!newValue || typeof newValue !== 'string') return
|
||||
@@ -2956,6 +3072,7 @@ watch(
|
||||
subscriptionType: subscriptionType,
|
||||
autoStopOnWarning: newAccount.autoStopOnWarning || false,
|
||||
groupId: groupId,
|
||||
groupIds: [],
|
||||
projectId: newAccount.projectId || '',
|
||||
accessToken: '',
|
||||
refreshToken: '',
|
||||
@@ -2997,24 +3114,35 @@ watch(
|
||||
// 如果是分组类型,加载分组ID
|
||||
if (newAccount.accountType === 'group') {
|
||||
// 先加载分组列表
|
||||
loadGroups().then(() => {
|
||||
loadGroups().then(async () => {
|
||||
const foundGroupIds = []
|
||||
|
||||
// 如果账户有 groupInfo,直接使用它的 groupId
|
||||
if (newAccount.groupInfo && newAccount.groupInfo.id) {
|
||||
form.value.groupId = newAccount.groupInfo.id
|
||||
foundGroupIds.push(newAccount.groupInfo.id)
|
||||
} else {
|
||||
// 否则查找账户所属的分组
|
||||
groups.value.forEach((group) => {
|
||||
apiClient
|
||||
.get(`/admin/account-groups/${group.id}/members`)
|
||||
.then((response) => {
|
||||
const members = response.data || []
|
||||
if (members.some((m) => m.id === newAccount.id)) {
|
||||
form.value.groupId = group.id
|
||||
const checkPromises = groups.value.map(async (group) => {
|
||||
try {
|
||||
const response = await apiClient.get(`/admin/account-groups/${group.id}/members`)
|
||||
const members = response.data || []
|
||||
if (members.some((m) => m.id === newAccount.id)) {
|
||||
foundGroupIds.push(group.id)
|
||||
if (!form.value.groupId) {
|
||||
form.value.groupId = group.id // 设置第一个找到的分组作为主分组
|
||||
}
|
||||
})
|
||||
.catch(() => {})
|
||||
}
|
||||
} catch (error) {
|
||||
// 忽略错误
|
||||
}
|
||||
})
|
||||
|
||||
await Promise.all(checkPromises)
|
||||
}
|
||||
|
||||
// 设置多选分组
|
||||
form.value.groupIds = foundGroupIds
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,12 +188,14 @@
|
||||
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-medium text-gray-700 dark:text-gray-300"
|
||||
>Token 限制</label
|
||||
>费用限制 (美元)</label
|
||||
>
|
||||
<input
|
||||
v-model="form.tokenLimit"
|
||||
v-model="form.rateLimitCost"
|
||||
class="form-input w-full text-sm dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200"
|
||||
min="0"
|
||||
placeholder="不修改"
|
||||
step="0.01"
|
||||
type="number"
|
||||
/>
|
||||
</div>
|
||||
@@ -216,6 +218,24 @@
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Opus 模型周费用限制 -->
|
||||
<div>
|
||||
<label class="mb-3 block text-sm font-semibold text-gray-700 dark:text-gray-300">
|
||||
Opus 模型周费用限制 (美元)
|
||||
</label>
|
||||
<input
|
||||
v-model="form.weeklyOpusCostLimit"
|
||||
class="form-input w-full dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200"
|
||||
min="0"
|
||||
placeholder="不修改 (0 表示无限制)"
|
||||
step="0.01"
|
||||
type="number"
|
||||
/>
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">
|
||||
设置 Opus 模型的周费用限制(周一到周日),仅限 Claude 官方账户
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- 并发限制 -->
|
||||
<div>
|
||||
<label class="mb-3 block text-sm font-semibold text-gray-700 dark:text-gray-300"
|
||||
@@ -496,11 +516,12 @@ const unselectedTags = computed(() => {
|
||||
|
||||
// 表单数据
|
||||
const form = reactive({
|
||||
tokenLimit: '',
|
||||
rateLimitCost: '', // 费用限制替代token限制
|
||||
rateLimitWindow: '',
|
||||
rateLimitRequests: '',
|
||||
concurrencyLimit: '',
|
||||
dailyCostLimit: '',
|
||||
weeklyOpusCostLimit: '', // 新增Opus周费用限制
|
||||
permissions: '', // 空字符串表示不修改
|
||||
claudeAccountId: '',
|
||||
geminiAccountId: '',
|
||||
@@ -616,8 +637,8 @@ const batchUpdateApiKeys = async () => {
|
||||
const updates = {}
|
||||
|
||||
// 只有非空值才添加到更新对象中
|
||||
if (form.tokenLimit !== '' && form.tokenLimit !== null) {
|
||||
updates.tokenLimit = parseInt(form.tokenLimit)
|
||||
if (form.rateLimitCost !== '' && form.rateLimitCost !== null) {
|
||||
updates.rateLimitCost = parseFloat(form.rateLimitCost)
|
||||
}
|
||||
if (form.rateLimitWindow !== '' && form.rateLimitWindow !== null) {
|
||||
updates.rateLimitWindow = parseInt(form.rateLimitWindow)
|
||||
@@ -631,6 +652,9 @@ const batchUpdateApiKeys = async () => {
|
||||
if (form.dailyCostLimit !== '' && form.dailyCostLimit !== null) {
|
||||
updates.dailyCostLimit = parseFloat(form.dailyCostLimit)
|
||||
}
|
||||
if (form.weeklyOpusCostLimit !== '' && form.weeklyOpusCostLimit !== null) {
|
||||
updates.weeklyOpusCostLimit = parseFloat(form.weeklyOpusCostLimit)
|
||||
}
|
||||
|
||||
// 权限设置
|
||||
if (form.permissions !== '') {
|
||||
|
||||
@@ -1,24 +1,64 @@
|
||||
<template>
|
||||
<div class="api-input-wide-card mb-8 rounded-3xl p-6 shadow-xl">
|
||||
<!-- 标题区域 -->
|
||||
<div class="wide-card-title mb-6 text-center">
|
||||
<h2 class="mb-2 text-2xl font-bold text-gray-900 dark:text-white">
|
||||
<div class="wide-card-title mb-6">
|
||||
<h2 class="mb-2 text-2xl font-bold text-gray-900 dark:text-gray-200">
|
||||
<i class="fas fa-chart-line mr-3" />
|
||||
使用统计查询
|
||||
</h2>
|
||||
<p class="text-base text-gray-600 dark:text-gray-300">查询您的 API Key 使用情况和统计数据</p>
|
||||
<p class="text-base text-gray-600 dark:text-gray-400">查询您的 API Key 使用情况和统计数据</p>
|
||||
</div>
|
||||
|
||||
<!-- 输入区域 -->
|
||||
<div class="mx-auto max-w-4xl">
|
||||
<div class="api-input-grid grid grid-cols-1 lg:grid-cols-4">
|
||||
<!-- 控制栏 -->
|
||||
<div class="control-bar mb-4 flex flex-wrap items-center justify-between gap-3">
|
||||
<!-- API Key 标签 -->
|
||||
<label class="text-sm font-medium text-gray-700 dark:text-gray-300">
|
||||
<i class="fas fa-key mr-2" />
|
||||
{{ multiKeyMode ? '输入您的 API Keys(每行一个或用逗号分隔)' : '输入您的 API Key' }}
|
||||
</label>
|
||||
|
||||
<!-- 模式切换和查询按钮组 -->
|
||||
<div class="button-group flex items-center gap-2">
|
||||
<!-- 模式切换 -->
|
||||
<div
|
||||
class="mode-switch-group flex items-center rounded-lg bg-gray-100 p-1 dark:bg-gray-800"
|
||||
>
|
||||
<button
|
||||
class="mode-switch-btn"
|
||||
:class="{ active: !multiKeyMode }"
|
||||
title="单一模式"
|
||||
@click="multiKeyMode = false"
|
||||
>
|
||||
<i class="fas fa-key" />
|
||||
<span class="ml-2 hidden sm:inline">单一</span>
|
||||
</button>
|
||||
<button
|
||||
class="mode-switch-btn"
|
||||
:class="{ active: multiKeyMode }"
|
||||
title="聚合模式"
|
||||
@click="multiKeyMode = true"
|
||||
>
|
||||
<i class="fas fa-layer-group" />
|
||||
<span class="ml-2 hidden sm:inline">聚合</span>
|
||||
<span
|
||||
v-if="multiKeyMode && parsedApiKeys.length > 0"
|
||||
class="ml-1 rounded-full bg-white/20 px-1.5 py-0.5 text-xs font-semibold"
|
||||
>
|
||||
{{ parsedApiKeys.length }}
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="api-input-grid grid grid-cols-1 gap-4 lg:grid-cols-4">
|
||||
<!-- API Key 输入 -->
|
||||
<div class="lg:col-span-3">
|
||||
<label class="mb-2 block text-sm font-medium text-gray-700 dark:text-gray-200">
|
||||
<i class="fas fa-key mr-2" />
|
||||
输入您的 API Key
|
||||
</label>
|
||||
<!-- 单 Key 模式输入框 -->
|
||||
<input
|
||||
v-if="!multiKeyMode"
|
||||
v-model="apiKey"
|
||||
class="wide-card-input w-full"
|
||||
:disabled="loading"
|
||||
@@ -26,16 +66,33 @@
|
||||
type="password"
|
||||
@keyup.enter="queryStats"
|
||||
/>
|
||||
|
||||
<!-- 多 Key 模式输入框 -->
|
||||
<div v-else class="relative">
|
||||
<textarea
|
||||
v-model="apiKey"
|
||||
class="wide-card-input w-full resize-y"
|
||||
:disabled="loading"
|
||||
placeholder="请输入您的 API Keys,支持以下格式: cr_xxx cr_yyy 或 cr_xxx, cr_yyy"
|
||||
rows="4"
|
||||
@keyup.ctrl.enter="queryStats"
|
||||
/>
|
||||
<button
|
||||
v-if="apiKey && !loading"
|
||||
class="absolute right-2 top-2 text-gray-400 hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-300"
|
||||
title="清空输入"
|
||||
@click="clearInput"
|
||||
>
|
||||
<i class="fas fa-times-circle" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 查询按钮 -->
|
||||
<div class="lg:col-span-1">
|
||||
<label class="mb-2 hidden text-sm font-medium text-gray-700 dark:text-gray-200 lg:block">
|
||||
|
||||
</label>
|
||||
<button
|
||||
class="btn btn-primary btn-query flex h-full w-full items-center justify-center gap-2"
|
||||
:disabled="loading || !apiKey.trim()"
|
||||
:disabled="loading || !hasValidInput"
|
||||
@click="queryStats"
|
||||
>
|
||||
<i v-if="loading" class="fas fa-spinner loading-spinner" />
|
||||
@@ -48,19 +105,56 @@
|
||||
<!-- 安全提示 -->
|
||||
<div class="security-notice mt-4">
|
||||
<i class="fas fa-shield-alt mr-2" />
|
||||
您的 API Key 仅用于查询自己的统计数据,不会被存储或用于其他用途
|
||||
{{
|
||||
multiKeyMode
|
||||
? '您的 API Keys 仅用于查询统计数据,不会被存储。聚合模式下部分个体化信息将不显示。'
|
||||
: '您的 API Key 仅用于查询自己的统计数据,不会被存储或用于其他用途'
|
||||
}}
|
||||
</div>
|
||||
|
||||
<!-- 多 Key 模式额外提示 -->
|
||||
<div
|
||||
v-if="multiKeyMode"
|
||||
class="mt-2 rounded-lg bg-blue-50 p-3 text-sm text-blue-700 dark:bg-blue-900/20 dark:text-blue-400"
|
||||
>
|
||||
<i class="fas fa-lightbulb mr-2" />
|
||||
<span>提示:最多支持同时查询 30 个 API Keys。使用 Ctrl+Enter 快速查询。</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { useApiStatsStore } from '@/stores/apistats'
|
||||
|
||||
const apiStatsStore = useApiStatsStore()
|
||||
const { apiKey, loading } = storeToRefs(apiStatsStore)
|
||||
const { queryStats } = apiStatsStore
|
||||
const { apiKey, loading, multiKeyMode } = storeToRefs(apiStatsStore)
|
||||
const { queryStats, clearInput } = apiStatsStore
|
||||
|
||||
// 解析输入的 API Keys
|
||||
const parsedApiKeys = computed(() => {
|
||||
if (!multiKeyMode.value || !apiKey.value) return []
|
||||
|
||||
// 支持逗号和换行符分隔
|
||||
const keys = apiKey.value
|
||||
.split(/[,\n]+/)
|
||||
.map((key) => key.trim())
|
||||
.filter((key) => key.length > 0)
|
||||
|
||||
// 去重并限制最多30个
|
||||
const uniqueKeys = [...new Set(keys)]
|
||||
return uniqueKeys.slice(0, 30)
|
||||
})
|
||||
|
||||
// 判断是否有有效输入
|
||||
const hasValidInput = computed(() => {
|
||||
if (multiKeyMode.value) {
|
||||
return parsedApiKeys.value.length > 0
|
||||
}
|
||||
return apiKey.value && apiKey.value.trim().length > 0
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -101,7 +195,6 @@ const { queryStats } = apiStatsStore
|
||||
|
||||
/* 标题样式 */
|
||||
.wide-card-title h2 {
|
||||
color: #1f2937;
|
||||
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
|
||||
font-weight: 700;
|
||||
}
|
||||
@@ -112,12 +205,12 @@ const { queryStats } = apiStatsStore
|
||||
}
|
||||
|
||||
.wide-card-title p {
|
||||
color: #4b5563;
|
||||
color: #6b7280;
|
||||
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
:global(.dark) .wide-card-title p {
|
||||
color: #d1d5db;
|
||||
color: #9ca3af;
|
||||
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
@@ -251,6 +344,93 @@ const { queryStats } = apiStatsStore
|
||||
text-shadow: 0 1px 2px rgba(16, 185, 129, 0.2);
|
||||
}
|
||||
|
||||
/* 控制栏 */
|
||||
.control-bar {
|
||||
padding-bottom: 0.5rem;
|
||||
border-bottom: 1px solid rgba(229, 231, 235, 0.3);
|
||||
}
|
||||
|
||||
:global(.dark) .control-bar {
|
||||
border-bottom-color: rgba(75, 85, 99, 0.3);
|
||||
}
|
||||
|
||||
/* 按钮组 */
|
||||
.button-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
/* 模式切换组 */
|
||||
.mode-switch-group {
|
||||
display: inline-flex;
|
||||
padding: 4px;
|
||||
background: #f3f4f6;
|
||||
border-radius: 0.5rem;
|
||||
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
:global(.dark) .mode-switch-group {
|
||||
background: #1f2937;
|
||||
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
/* 模式切换按钮 */
|
||||
.mode-switch-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 6px 12px;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
color: #6b7280;
|
||||
background: transparent;
|
||||
border: none;
|
||||
border-radius: 0.375rem;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
:global(.dark) .mode-switch-btn {
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.mode-switch-btn:hover:not(.active) {
|
||||
color: #374151;
|
||||
background: rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
:global(.dark) .mode-switch-btn:hover:not(.active) {
|
||||
color: #d1d5db;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
|
||||
.mode-switch-btn.active {
|
||||
color: white;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
box-shadow: 0 2px 4px rgba(102, 126, 234, 0.2);
|
||||
}
|
||||
|
||||
.mode-switch-btn.active:hover {
|
||||
box-shadow: 0 4px 6px rgba(102, 126, 234, 0.3);
|
||||
}
|
||||
|
||||
.mode-switch-btn i {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
/* 淡入淡出动画 */
|
||||
.fade-enter-active,
|
||||
.fade-leave-active {
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.fade-enter-from,
|
||||
.fade-leave-to {
|
||||
opacity: 0;
|
||||
transform: translateX(-10px);
|
||||
}
|
||||
|
||||
/* 加载动画 */
|
||||
.loading-spinner {
|
||||
animation: spin 1s linear infinite;
|
||||
@@ -267,6 +447,18 @@ const { queryStats } = apiStatsStore
|
||||
}
|
||||
|
||||
/* 响应式优化 */
|
||||
@media (max-width: 768px) {
|
||||
.control-bar {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.button-group {
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.api-input-wide-card {
|
||||
padding: 1.25rem;
|
||||
@@ -304,6 +496,22 @@ const { queryStats } = apiStatsStore
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.mode-toggle-btn {
|
||||
padding: 5px 8px;
|
||||
}
|
||||
|
||||
.toggle-icon {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
}
|
||||
|
||||
.hint-text {
|
||||
font-size: 0.7rem;
|
||||
padding: 4px 8px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.api-input-wide-card {
|
||||
padding: 1rem;
|
||||
|
||||
@@ -1,14 +1,108 @@
|
||||
<template>
|
||||
<div>
|
||||
<!-- 限制配置 -->
|
||||
<!-- 限制配置 / 聚合模式提示 -->
|
||||
<div class="card p-4 md:p-6">
|
||||
<h3
|
||||
class="mb-3 flex items-center text-lg font-bold text-gray-900 dark:text-gray-100 md:mb-4 md:text-xl"
|
||||
>
|
||||
<i class="fas fa-shield-alt mr-2 text-sm text-red-500 md:mr-3 md:text-base" />
|
||||
限制配置
|
||||
{{ multiKeyMode ? '限制配置(聚合查询模式)' : '限制配置' }}
|
||||
</h3>
|
||||
<div class="space-y-4 md:space-y-5">
|
||||
|
||||
<!-- 多 Key 模式下的聚合统计信息 -->
|
||||
<div v-if="multiKeyMode && aggregatedStats" class="space-y-4">
|
||||
<!-- API Keys 概况 -->
|
||||
<div
|
||||
class="rounded-lg bg-gradient-to-r from-blue-50 to-indigo-50 p-4 dark:from-blue-900/20 dark:to-indigo-900/20"
|
||||
>
|
||||
<div class="mb-3 flex items-center justify-between">
|
||||
<span class="text-sm font-medium text-gray-700 dark:text-gray-300">
|
||||
<i class="fas fa-layer-group mr-2 text-blue-500" />
|
||||
API Keys 概况
|
||||
</span>
|
||||
<span
|
||||
class="rounded-full bg-blue-100 px-2 py-1 text-xs font-semibold text-blue-700 dark:bg-blue-800 dark:text-blue-200"
|
||||
>
|
||||
{{ aggregatedStats.activeKeys }}/{{ aggregatedStats.totalKeys }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<div class="text-center">
|
||||
<div class="text-lg font-bold text-gray-900 dark:text-gray-100">
|
||||
{{ aggregatedStats.totalKeys }}
|
||||
</div>
|
||||
<div class="text-xs text-gray-600 dark:text-gray-400">总计 Keys</div>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<div class="text-lg font-bold text-green-600">
|
||||
{{ aggregatedStats.activeKeys }}
|
||||
</div>
|
||||
<div class="text-xs text-gray-600 dark:text-gray-400">激活 Keys</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 聚合统计数据 -->
|
||||
<div
|
||||
class="rounded-lg bg-gradient-to-r from-purple-50 to-pink-50 p-4 dark:from-purple-900/20 dark:to-pink-900/20"
|
||||
>
|
||||
<div class="mb-3 flex items-center">
|
||||
<i class="fas fa-chart-pie mr-2 text-purple-500" />
|
||||
<span class="text-sm font-medium text-gray-700 dark:text-gray-300">聚合统计摘要</span>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-xs text-gray-600 dark:text-gray-400">
|
||||
<i class="fas fa-database mr-1 text-gray-400" />
|
||||
总请求数
|
||||
</span>
|
||||
<span class="text-sm font-medium text-gray-900 dark:text-gray-100">
|
||||
{{ formatNumber(aggregatedStats.usage.requests) }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-xs text-gray-600 dark:text-gray-400">
|
||||
<i class="fas fa-coins mr-1 text-yellow-500" />
|
||||
总 Tokens
|
||||
</span>
|
||||
<span class="text-sm font-medium text-gray-900 dark:text-gray-100">
|
||||
{{ formatNumber(aggregatedStats.usage.allTokens) }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-xs text-gray-600 dark:text-gray-400">
|
||||
<i class="fas fa-dollar-sign mr-1 text-green-500" />
|
||||
总费用
|
||||
</span>
|
||||
<span class="text-sm font-medium text-gray-900 dark:text-gray-100">
|
||||
{{ aggregatedStats.usage.formattedCost }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 无效 Keys 提示 -->
|
||||
<div
|
||||
v-if="invalidKeys && invalidKeys.length > 0"
|
||||
class="rounded-lg bg-red-50 p-3 text-sm dark:bg-red-900/20"
|
||||
>
|
||||
<i class="fas fa-exclamation-triangle mr-2 text-red-600 dark:text-red-400" />
|
||||
<span class="text-red-700 dark:text-red-300">
|
||||
{{ invalidKeys.length }} 个无效的 API Key
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- 提示信息 -->
|
||||
<div
|
||||
class="rounded-lg bg-gray-50 p-3 text-xs text-gray-600 dark:bg-gray-800 dark:text-gray-400"
|
||||
>
|
||||
<i class="fas fa-info-circle mr-1" />
|
||||
每个 API Key 有独立的限制设置,聚合模式下不显示单个限制配置
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 仅在单 Key 模式下显示限制配置 -->
|
||||
<div v-if="!multiKeyMode" class="space-y-4 md:space-y-5">
|
||||
<!-- 每日费用限制 -->
|
||||
<div>
|
||||
<div class="mb-2 flex items-center justify-between">
|
||||
@@ -221,7 +315,7 @@ import { useApiStatsStore } from '@/stores/apistats'
|
||||
import WindowCountdown from '@/components/apikeys/WindowCountdown.vue'
|
||||
|
||||
const apiStatsStore = useApiStatsStore()
|
||||
const { statsData } = storeToRefs(apiStatsStore)
|
||||
const { statsData, multiKeyMode, aggregatedStats, invalidKeys } = storeToRefs(apiStatsStore)
|
||||
|
||||
// 获取每日费用进度
|
||||
const getDailyCostProgress = () => {
|
||||
@@ -239,6 +333,24 @@ const getDailyCostProgressColor = () => {
|
||||
if (progress >= 80) return 'bg-yellow-500'
|
||||
return 'bg-green-500'
|
||||
}
|
||||
|
||||
// 格式化数字
|
||||
const formatNumber = (num) => {
|
||||
if (typeof num !== 'number') {
|
||||
num = parseInt(num) || 0
|
||||
}
|
||||
|
||||
if (num === 0) return '0'
|
||||
|
||||
// 大数字使用简化格式
|
||||
if (num >= 1000000) {
|
||||
return (num / 1000000).toFixed(1) + 'M'
|
||||
} else if (num >= 1000) {
|
||||
return (num / 1000).toFixed(1) + 'K'
|
||||
} else {
|
||||
return num.toLocaleString()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
@@ -1,14 +1,83 @@
|
||||
<template>
|
||||
<div class="mb-6 grid grid-cols-1 gap-4 md:mb-8 md:gap-6 lg:grid-cols-2">
|
||||
<!-- API Key 基本信息 -->
|
||||
<!-- API Key 基本信息 / 批量查询概要 -->
|
||||
<div class="card p-4 md:p-6">
|
||||
<h3
|
||||
class="mb-3 flex items-center text-lg font-bold text-gray-900 dark:text-gray-100 md:mb-4 md:text-xl"
|
||||
>
|
||||
<i class="fas fa-info-circle mr-2 text-sm text-blue-500 md:mr-3 md:text-base" />
|
||||
API Key 信息
|
||||
<i
|
||||
class="mr-2 text-sm md:mr-3 md:text-base"
|
||||
:class="
|
||||
multiKeyMode ? 'fas fa-layer-group text-purple-500' : 'fas fa-info-circle text-blue-500'
|
||||
"
|
||||
/>
|
||||
{{ multiKeyMode ? '批量查询概要' : 'API Key 信息' }}
|
||||
</h3>
|
||||
<div class="space-y-2 md:space-y-3">
|
||||
|
||||
<!-- 多 Key 模式下的概要信息 -->
|
||||
<div v-if="multiKeyMode && aggregatedStats" class="space-y-2 md:space-y-3">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-sm text-gray-600 dark:text-gray-400 md:text-base">查询 Keys 数</span>
|
||||
<span class="text-sm font-medium text-gray-900 dark:text-gray-100 md:text-base">
|
||||
{{ aggregatedStats.totalKeys }} 个
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-sm text-gray-600 dark:text-gray-400 md:text-base">有效 Keys 数</span>
|
||||
<span class="text-sm font-medium text-green-600 md:text-base">
|
||||
<i class="fas fa-check-circle mr-1 text-xs md:text-sm" />
|
||||
{{ aggregatedStats.activeKeys }} 个
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="invalidKeys.length > 0" class="flex items-center justify-between">
|
||||
<span class="text-sm text-gray-600 dark:text-gray-400 md:text-base">无效 Keys 数</span>
|
||||
<span class="text-sm font-medium text-red-600 md:text-base">
|
||||
<i class="fas fa-times-circle mr-1 text-xs md:text-sm" />
|
||||
{{ invalidKeys.length }} 个
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-sm text-gray-600 dark:text-gray-400 md:text-base">总请求数</span>
|
||||
<span class="text-sm font-medium text-gray-900 dark:text-gray-100 md:text-base">
|
||||
{{ formatNumber(aggregatedStats.usage.requests) }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-sm text-gray-600 dark:text-gray-400 md:text-base">总 Token 数</span>
|
||||
<span class="text-sm font-medium text-gray-900 dark:text-gray-100 md:text-base">
|
||||
{{ formatNumber(aggregatedStats.usage.allTokens) }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-sm text-gray-600 dark:text-gray-400 md:text-base">总费用</span>
|
||||
<span class="text-sm font-medium text-indigo-600 md:text-base">
|
||||
{{ aggregatedStats.usage.formattedCost }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- 各 Key 贡献占比(可选) -->
|
||||
<div
|
||||
v-if="individualStats.length > 1"
|
||||
class="border-t border-gray-200 pt-2 dark:border-gray-700"
|
||||
>
|
||||
<div class="mb-2 text-xs text-gray-500 dark:text-gray-400">各 Key 贡献占比</div>
|
||||
<div class="space-y-1">
|
||||
<div
|
||||
v-for="stat in topContributors"
|
||||
:key="stat.apiId"
|
||||
class="flex items-center justify-between text-xs"
|
||||
>
|
||||
<span class="truncate text-gray-600 dark:text-gray-400">{{ stat.name }}</span>
|
||||
<span class="text-gray-900 dark:text-gray-100"
|
||||
>{{ calculateContribution(stat) }}%</span
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 单 Key 模式下的详细信息 -->
|
||||
<div v-else class="space-y-2 md:space-y-3">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-sm text-gray-600 dark:text-gray-400 md:text-base">名称</span>
|
||||
<span
|
||||
@@ -128,12 +197,38 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
/* eslint-disable no-unused-vars */
|
||||
import { computed } from 'vue'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { useApiStatsStore } from '@/stores/apistats'
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
const apiStatsStore = useApiStatsStore()
|
||||
const { statsData, statsPeriod, currentPeriodData } = storeToRefs(apiStatsStore)
|
||||
const {
|
||||
statsData,
|
||||
statsPeriod,
|
||||
currentPeriodData,
|
||||
multiKeyMode,
|
||||
aggregatedStats,
|
||||
individualStats,
|
||||
invalidKeys
|
||||
} = storeToRefs(apiStatsStore)
|
||||
|
||||
// 计算前3个贡献最大的 Key
|
||||
const topContributors = computed(() => {
|
||||
if (!individualStats.value || individualStats.value.length === 0) return []
|
||||
|
||||
return [...individualStats.value]
|
||||
.sort((a, b) => (b.usage?.allTokens || 0) - (a.usage?.allTokens || 0))
|
||||
.slice(0, 3)
|
||||
})
|
||||
|
||||
// 计算单个 Key 的贡献占比
|
||||
const calculateContribution = (stat) => {
|
||||
if (!aggregatedStats.value || !aggregatedStats.value.usage.allTokens) return 0
|
||||
const percentage = ((stat.usage?.allTokens || 0) / aggregatedStats.value.usage.allTokens) * 100
|
||||
return percentage.toFixed(1)
|
||||
}
|
||||
|
||||
// 格式化日期
|
||||
const formatDate = (dateString) => {
|
||||
|
||||
@@ -98,9 +98,18 @@ class ApiClient {
|
||||
|
||||
// GET 请求
|
||||
async get(url, options = {}) {
|
||||
const fullUrl = createApiUrl(url)
|
||||
// 处理查询参数
|
||||
let fullUrl = createApiUrl(url)
|
||||
if (options.params) {
|
||||
const params = new URLSearchParams(options.params)
|
||||
fullUrl += '?' + params.toString()
|
||||
}
|
||||
|
||||
// 移除 params 避免传递给 fetch
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const { params, ...configOptions } = options
|
||||
const config = this.buildConfig({
|
||||
...options,
|
||||
...configOptions,
|
||||
method: 'GET'
|
||||
})
|
||||
|
||||
|
||||
@@ -76,6 +76,22 @@ class ApiStatsClient {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 批量查询统计数据
|
||||
async getBatchStats(apiIds) {
|
||||
return this.request('/apiStats/api/batch-stats', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ apiIds })
|
||||
})
|
||||
}
|
||||
|
||||
// 批量查询模型统计
|
||||
async getBatchModelStats(apiIds, period = 'daily') {
|
||||
return this.request('/apiStats/api/batch-model-stats', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ apiIds, period })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const apiStatsClient = new ApiStatsClient()
|
||||
|
||||
@@ -21,6 +21,14 @@ export const useApiStatsStore = defineStore('apistats', () => {
|
||||
siteIconData: ''
|
||||
})
|
||||
|
||||
// 多 Key 模式相关状态
|
||||
const multiKeyMode = ref(false)
|
||||
const apiKeys = ref([]) // 多个 API Key 数组
|
||||
const apiIds = ref([]) // 对应的 ID 数组
|
||||
const aggregatedStats = ref(null) // 聚合后的统计数据
|
||||
const individualStats = ref([]) // 各个 Key 的独立数据
|
||||
const invalidKeys = ref([]) // 无效的 Keys 列表
|
||||
|
||||
// 计算属性
|
||||
const currentPeriodData = computed(() => {
|
||||
const defaultData = {
|
||||
@@ -34,6 +42,16 @@ export const useApiStatsStore = defineStore('apistats', () => {
|
||||
formattedCost: '$0.000000'
|
||||
}
|
||||
|
||||
// 聚合模式下使用聚合数据
|
||||
if (multiKeyMode.value && aggregatedStats.value) {
|
||||
if (statsPeriod.value === 'daily') {
|
||||
return aggregatedStats.value.dailyUsage || defaultData
|
||||
} else {
|
||||
return aggregatedStats.value.monthlyUsage || defaultData
|
||||
}
|
||||
}
|
||||
|
||||
// 单个 Key 模式下使用原有逻辑
|
||||
if (statsPeriod.value === 'daily') {
|
||||
return dailyStats.value || defaultData
|
||||
} else {
|
||||
@@ -69,6 +87,11 @@ export const useApiStatsStore = defineStore('apistats', () => {
|
||||
|
||||
// 查询统计数据
|
||||
async function queryStats() {
|
||||
// 多 Key 模式处理
|
||||
if (multiKeyMode.value) {
|
||||
return queryBatchStats()
|
||||
}
|
||||
|
||||
if (!apiKey.value.trim()) {
|
||||
error.value = '请输入 API Key'
|
||||
return
|
||||
@@ -204,6 +227,12 @@ export const useApiStatsStore = defineStore('apistats', () => {
|
||||
|
||||
statsPeriod.value = period
|
||||
|
||||
// 多 Key 模式下加载批量模型统计
|
||||
if (multiKeyMode.value && apiIds.value.length > 0) {
|
||||
await loadBatchModelStats(period)
|
||||
return
|
||||
}
|
||||
|
||||
// 如果对应时间段的数据还没有加载,则加载它
|
||||
if (
|
||||
(period === 'daily' && !dailyStats.value) ||
|
||||
@@ -297,6 +326,127 @@ export const useApiStatsStore = defineStore('apistats', () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 批量查询统计数据
|
||||
async function queryBatchStats() {
|
||||
const keys = parseApiKeys()
|
||||
if (keys.length === 0) {
|
||||
error.value = '请输入至少一个有效的 API Key'
|
||||
return
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
aggregatedStats.value = null
|
||||
individualStats.value = []
|
||||
invalidKeys.value = []
|
||||
modelStats.value = []
|
||||
apiKeys.value = keys
|
||||
apiIds.value = []
|
||||
|
||||
try {
|
||||
// 批量获取 API Key IDs
|
||||
const idResults = await Promise.allSettled(keys.map((key) => apiStatsClient.getKeyId(key)))
|
||||
|
||||
const validIds = []
|
||||
const validKeys = []
|
||||
|
||||
idResults.forEach((result, index) => {
|
||||
if (result.status === 'fulfilled' && result.value.success) {
|
||||
validIds.push(result.value.data.id)
|
||||
validKeys.push(keys[index])
|
||||
} else {
|
||||
invalidKeys.value.push(keys[index])
|
||||
}
|
||||
})
|
||||
|
||||
if (validIds.length === 0) {
|
||||
throw new Error('所有 API Key 都无效')
|
||||
}
|
||||
|
||||
apiIds.value = validIds
|
||||
apiKeys.value = validKeys
|
||||
|
||||
// 批量查询统计数据
|
||||
const batchResult = await apiStatsClient.getBatchStats(validIds)
|
||||
|
||||
if (batchResult.success) {
|
||||
aggregatedStats.value = batchResult.data.aggregated
|
||||
individualStats.value = batchResult.data.individual
|
||||
statsData.value = batchResult.data.aggregated // 兼容现有组件
|
||||
|
||||
// 设置聚合模式下的日期统计数据,以保证现有组件的兼容性
|
||||
dailyStats.value = batchResult.data.aggregated.dailyUsage || null
|
||||
monthlyStats.value = batchResult.data.aggregated.monthlyUsage || null
|
||||
|
||||
// 加载聚合的模型统计
|
||||
await loadBatchModelStats(statsPeriod.value)
|
||||
|
||||
// 更新 URL
|
||||
updateBatchURL()
|
||||
} else {
|
||||
throw new Error(batchResult.message || '批量查询失败')
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Batch query error:', err)
|
||||
error.value = err.message || '批量查询统计数据失败'
|
||||
aggregatedStats.value = null
|
||||
individualStats.value = []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 加载批量模型统计
|
||||
async function loadBatchModelStats(period = 'daily') {
|
||||
if (apiIds.value.length === 0) return
|
||||
|
||||
modelStatsLoading.value = true
|
||||
|
||||
try {
|
||||
const result = await apiStatsClient.getBatchModelStats(apiIds.value, period)
|
||||
|
||||
if (result.success) {
|
||||
modelStats.value = result.data || []
|
||||
} else {
|
||||
throw new Error(result.message || '加载批量模型统计失败')
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Load batch model stats error:', err)
|
||||
modelStats.value = []
|
||||
} finally {
|
||||
modelStatsLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 解析 API Keys
|
||||
function parseApiKeys() {
|
||||
if (!apiKey.value) return []
|
||||
|
||||
const keys = apiKey.value
|
||||
.split(/[,\n]+/)
|
||||
.map((key) => key.trim())
|
||||
.filter((key) => key.length > 0)
|
||||
|
||||
// 去重并限制最多30个
|
||||
const uniqueKeys = [...new Set(keys)]
|
||||
return uniqueKeys.slice(0, 30)
|
||||
}
|
||||
|
||||
// 更新批量查询 URL
|
||||
function updateBatchURL() {
|
||||
if (apiIds.value.length > 0) {
|
||||
const url = new URL(window.location)
|
||||
url.searchParams.set('apiIds', apiIds.value.join(','))
|
||||
url.searchParams.set('batch', 'true')
|
||||
window.history.pushState({}, '', url)
|
||||
}
|
||||
}
|
||||
|
||||
// 清空输入
|
||||
function clearInput() {
|
||||
apiKey.value = ''
|
||||
}
|
||||
|
||||
// 清除数据
|
||||
function clearData() {
|
||||
statsData.value = null
|
||||
@@ -306,11 +456,18 @@ export const useApiStatsStore = defineStore('apistats', () => {
|
||||
error.value = ''
|
||||
statsPeriod.value = 'daily'
|
||||
apiId.value = null
|
||||
// 清除多 Key 模式数据
|
||||
apiKeys.value = []
|
||||
apiIds.value = []
|
||||
aggregatedStats.value = null
|
||||
individualStats.value = []
|
||||
invalidKeys.value = []
|
||||
}
|
||||
|
||||
// 重置
|
||||
function reset() {
|
||||
apiKey.value = ''
|
||||
multiKeyMode.value = false
|
||||
clearData()
|
||||
}
|
||||
|
||||
@@ -328,6 +485,13 @@ export const useApiStatsStore = defineStore('apistats', () => {
|
||||
dailyStats,
|
||||
monthlyStats,
|
||||
oemSettings,
|
||||
// 多 Key 模式状态
|
||||
multiKeyMode,
|
||||
apiKeys,
|
||||
apiIds,
|
||||
aggregatedStats,
|
||||
individualStats,
|
||||
invalidKeys,
|
||||
|
||||
// Computed
|
||||
currentPeriodData,
|
||||
@@ -335,13 +499,16 @@ export const useApiStatsStore = defineStore('apistats', () => {
|
||||
|
||||
// Actions
|
||||
queryStats,
|
||||
queryBatchStats,
|
||||
loadAllPeriodStats,
|
||||
loadPeriodStats,
|
||||
loadModelStats,
|
||||
loadBatchModelStats,
|
||||
switchPeriod,
|
||||
loadStatsWithApiId,
|
||||
loadOemSettings,
|
||||
clearData,
|
||||
clearInput,
|
||||
reset
|
||||
}
|
||||
})
|
||||
|
||||
@@ -458,7 +458,8 @@
|
||||
account.platform === 'claude-console' ||
|
||||
account.platform === 'bedrock' ||
|
||||
account.platform === 'gemini' ||
|
||||
account.platform === 'openai'
|
||||
account.platform === 'openai' ||
|
||||
account.platform === 'azure_openai'
|
||||
"
|
||||
class="flex items-center gap-2"
|
||||
>
|
||||
@@ -1024,11 +1025,26 @@ const sortedAccounts = computed(() => {
|
||||
const loadAccounts = async (forceReload = false) => {
|
||||
accountsLoading.value = true
|
||||
try {
|
||||
// 构建查询参数(移除分组参数,因为在前端处理)
|
||||
// 检查是否选择了特定分组
|
||||
if (groupFilter.value && groupFilter.value !== 'all' && groupFilter.value !== 'ungrouped') {
|
||||
// 直接调用分组成员接口
|
||||
const response = await apiClient.get(`/admin/account-groups/${groupFilter.value}/members`)
|
||||
if (response.success) {
|
||||
// 分组成员接口已经包含了完整的账户信息,直接使用
|
||||
accounts.value = response.data
|
||||
accountsLoading.value = false
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 构建查询参数(用于其他筛选情况)
|
||||
const params = {}
|
||||
if (platformFilter.value !== 'all') {
|
||||
params.platform = platformFilter.value
|
||||
}
|
||||
if (groupFilter.value === 'ungrouped') {
|
||||
params.groupId = groupFilter.value
|
||||
}
|
||||
|
||||
// 根据平台筛选决定需要请求哪些接口
|
||||
const requests = []
|
||||
@@ -1106,6 +1122,17 @@ const loadAccounts = async (forceReload = false) => {
|
||||
apiClient.get('/admin/azure-openai-accounts', { params })
|
||||
)
|
||||
break
|
||||
default:
|
||||
// 默认情况下返回空数组
|
||||
requests.push(
|
||||
Promise.resolve({ success: true, data: [] }),
|
||||
Promise.resolve({ success: true, data: [] }),
|
||||
Promise.resolve({ success: true, data: [] }),
|
||||
Promise.resolve({ success: true, data: [] }),
|
||||
Promise.resolve({ success: true, data: [] }),
|
||||
Promise.resolve({ success: true, data: [] })
|
||||
)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1178,8 +1205,8 @@ const loadAccounts = async (forceReload = false) => {
|
||||
const boundApiKeysCount = apiKeys.value.filter(
|
||||
(key) => key.azureOpenaiAccountId === acc.id
|
||||
).length
|
||||
const groupInfo = accountGroupMap.value.get(acc.id) || null
|
||||
return { ...acc, platform: 'azure_openai', boundApiKeysCount, groupInfo }
|
||||
// 后端已经包含了groupInfos,直接使用
|
||||
return { ...acc, platform: 'azure_openai', boundApiKeysCount }
|
||||
})
|
||||
allAccounts.push(...azureOpenaiAccounts)
|
||||
}
|
||||
|
||||
@@ -54,7 +54,8 @@
|
||||
<!-- Tab Content -->
|
||||
<!-- 活跃 API Keys Tab Panel -->
|
||||
<div v-if="activeTab === 'active'" class="tab-panel">
|
||||
<div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<!-- 工具栏区域 - 添加 mb-4 增加与表格的间距 -->
|
||||
<div class="mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<!-- 筛选器组 -->
|
||||
<div class="flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center sm:gap-3">
|
||||
<!-- 时间范围筛选 -->
|
||||
@@ -136,8 +137,35 @@
|
||||
/>
|
||||
<span class="relative">刷新</span>
|
||||
</button>
|
||||
|
||||
<!-- 批量编辑按钮 - 移到刷新按钮旁边 -->
|
||||
<button
|
||||
v-if="selectedApiKeys.length > 0"
|
||||
class="group relative flex items-center justify-center gap-2 rounded-lg border border-blue-200 bg-blue-50 px-4 py-2 text-sm font-medium text-blue-700 shadow-sm transition-all duration-200 hover:border-blue-300 hover:bg-blue-100 hover:shadow-md dark:border-blue-700 dark:bg-blue-900/30 dark:text-blue-300 dark:hover:bg-blue-900/50 sm:w-auto"
|
||||
@click="openBatchEditModal()"
|
||||
>
|
||||
<div
|
||||
class="absolute -inset-0.5 rounded-lg bg-gradient-to-r from-blue-500 to-indigo-500 opacity-0 blur transition duration-300 group-hover:opacity-20"
|
||||
></div>
|
||||
<i class="fas fa-edit relative text-blue-600 dark:text-blue-400" />
|
||||
<span class="relative">编辑选中 ({{ selectedApiKeys.length }})</span>
|
||||
</button>
|
||||
|
||||
<!-- 批量删除按钮 - 移到刷新按钮旁边 -->
|
||||
<button
|
||||
v-if="selectedApiKeys.length > 0"
|
||||
class="group relative flex items-center justify-center gap-2 rounded-lg border border-red-200 bg-red-50 px-4 py-2 text-sm font-medium text-red-700 shadow-sm transition-all duration-200 hover:border-red-300 hover:bg-red-100 hover:shadow-md dark:border-red-700 dark:bg-red-900/30 dark:text-red-300 dark:hover:bg-red-900/50 sm:w-auto"
|
||||
@click="batchDeleteApiKeys()"
|
||||
>
|
||||
<div
|
||||
class="absolute -inset-0.5 rounded-lg bg-gradient-to-r from-red-500 to-pink-500 opacity-0 blur transition duration-300 group-hover:opacity-20"
|
||||
></div>
|
||||
<i class="fas fa-trash relative text-red-600 dark:text-red-400" />
|
||||
<span class="relative">删除选中 ({{ selectedApiKeys.length }})</span>
|
||||
</button>
|
||||
</div>
|
||||
<!-- 创建按钮 -->
|
||||
|
||||
<!-- 创建按钮 - 独立在右侧 -->
|
||||
<button
|
||||
class="flex w-full items-center justify-center gap-2 rounded-lg bg-gradient-to-r from-blue-500 to-blue-600 px-5 py-2.5 text-sm font-medium text-white shadow-md transition-all duration-200 hover:from-blue-600 hover:to-blue-700 hover:shadow-lg sm:w-auto"
|
||||
@click.stop="openCreateApiKeyModal"
|
||||
@@ -145,32 +173,6 @@
|
||||
<i class="fas fa-plus"></i>
|
||||
<span>创建新 Key</span>
|
||||
</button>
|
||||
|
||||
<!-- 批量编辑按钮 -->
|
||||
<button
|
||||
v-if="selectedApiKeys.length > 0"
|
||||
class="group relative flex items-center justify-center gap-2 rounded-lg border border-blue-200 bg-blue-50 px-4 py-2 text-sm font-medium text-blue-700 shadow-sm transition-all duration-200 hover:border-blue-300 hover:bg-blue-100 hover:shadow-md dark:border-blue-700 dark:bg-blue-900/30 dark:text-blue-300 dark:hover:bg-blue-900/50 sm:w-auto"
|
||||
@click="openBatchEditModal()"
|
||||
>
|
||||
<div
|
||||
class="absolute -inset-0.5 rounded-lg bg-gradient-to-r from-blue-500 to-indigo-500 opacity-0 blur transition duration-300 group-hover:opacity-20"
|
||||
></div>
|
||||
<i class="fas fa-edit relative text-blue-600 dark:text-blue-400" />
|
||||
<span class="relative">编辑选中 ({{ selectedApiKeys.length }})</span>
|
||||
</button>
|
||||
|
||||
<!-- 批量删除按钮 -->
|
||||
<button
|
||||
v-if="selectedApiKeys.length > 0"
|
||||
class="group relative flex items-center justify-center gap-2 rounded-lg border border-red-200 bg-red-50 px-4 py-2 text-sm font-medium text-red-700 shadow-sm transition-all duration-200 hover:border-red-300 hover:bg-red-100 hover:shadow-md dark:border-red-700 dark:bg-red-900/30 dark:text-red-300 dark:hover:bg-red-900/50 sm:w-auto"
|
||||
@click="batchDeleteApiKeys()"
|
||||
>
|
||||
<div
|
||||
class="absolute -inset-0.5 rounded-lg bg-gradient-to-r from-red-500 to-pink-500 opacity-0 blur transition duration-300 group-hover:opacity-20"
|
||||
></div>
|
||||
<i class="fas fa-trash relative text-red-600 dark:text-red-400" />
|
||||
<span class="relative">删除选中 ({{ selectedApiKeys.length }})</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="apiKeysLoading" class="py-12 text-center">
|
||||
@@ -1312,131 +1314,175 @@
|
||||
</div>
|
||||
|
||||
<!-- 已删除的 API Keys 表格 -->
|
||||
<div v-else class="table-container">
|
||||
<table class="w-full table-fixed">
|
||||
<thead class="bg-gray-50/80 backdrop-blur-sm dark:bg-gray-700/80">
|
||||
<tr>
|
||||
<th
|
||||
class="w-[20%] min-w-[150px] px-3 py-4 text-left text-xs font-bold uppercase tracking-wider text-gray-700 dark:text-gray-300"
|
||||
>
|
||||
名称
|
||||
</th>
|
||||
<th
|
||||
class="w-[15%] min-w-[120px] px-3 py-4 text-left text-xs font-bold uppercase tracking-wider text-gray-700 dark:text-gray-300"
|
||||
>
|
||||
创建者
|
||||
</th>
|
||||
<th
|
||||
class="w-[15%] min-w-[120px] px-3 py-4 text-left text-xs font-bold uppercase tracking-wider text-gray-700 dark:text-gray-300"
|
||||
>
|
||||
创建时间
|
||||
</th>
|
||||
<th
|
||||
class="w-[15%] min-w-[120px] px-3 py-4 text-left text-xs font-bold uppercase tracking-wider text-gray-700 dark:text-gray-300"
|
||||
>
|
||||
删除者
|
||||
</th>
|
||||
<th
|
||||
class="w-[15%] min-w-[120px] px-3 py-4 text-left text-xs font-bold uppercase tracking-wider text-gray-700 dark:text-gray-300"
|
||||
>
|
||||
删除时间
|
||||
</th>
|
||||
<th
|
||||
class="w-[20%] min-w-[150px] px-3 py-4 text-left text-xs font-bold uppercase tracking-wider text-gray-700 dark:text-gray-300"
|
||||
>
|
||||
使用统计
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-200/50 dark:divide-gray-600/50">
|
||||
<tr v-for="key in deletedApiKeys" :key="key.id" class="table-row">
|
||||
<td class="px-3 py-4">
|
||||
<div class="flex items-center">
|
||||
<div
|
||||
class="mr-2 flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg bg-gradient-to-br from-red-500 to-red-600"
|
||||
>
|
||||
<i class="fas fa-trash text-xs text-white" />
|
||||
</div>
|
||||
<div class="min-w-0">
|
||||
<div v-else>
|
||||
<!-- 工具栏 -->
|
||||
<div class="mb-4 flex justify-end">
|
||||
<button
|
||||
v-if="deletedApiKeys.length > 0"
|
||||
class="rounded-lg bg-red-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-red-700 dark:bg-red-600 dark:hover:bg-red-700"
|
||||
@click="clearAllDeletedApiKeys"
|
||||
>
|
||||
<i class="fas fa-trash-alt mr-2" />
|
||||
清空所有已删除 ({{ deletedApiKeys.length }})
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="table-container">
|
||||
<table class="w-full table-fixed">
|
||||
<thead class="bg-gray-50/80 backdrop-blur-sm dark:bg-gray-700/80">
|
||||
<tr>
|
||||
<th
|
||||
class="w-[20%] min-w-[150px] px-3 py-4 text-left text-xs font-bold uppercase tracking-wider text-gray-700 dark:text-gray-300"
|
||||
>
|
||||
名称
|
||||
</th>
|
||||
<th
|
||||
class="w-[15%] min-w-[120px] px-3 py-4 text-left text-xs font-bold uppercase tracking-wider text-gray-700 dark:text-gray-300"
|
||||
>
|
||||
创建者
|
||||
</th>
|
||||
<th
|
||||
class="w-[15%] min-w-[120px] px-3 py-4 text-left text-xs font-bold uppercase tracking-wider text-gray-700 dark:text-gray-300"
|
||||
>
|
||||
创建时间
|
||||
</th>
|
||||
<th
|
||||
class="w-[15%] min-w-[120px] px-3 py-4 text-left text-xs font-bold uppercase tracking-wider text-gray-700 dark:text-gray-300"
|
||||
>
|
||||
删除者
|
||||
</th>
|
||||
<th
|
||||
class="w-[15%] min-w-[120px] px-3 py-4 text-left text-xs font-bold uppercase tracking-wider text-gray-700 dark:text-gray-300"
|
||||
>
|
||||
删除时间
|
||||
</th>
|
||||
<th
|
||||
class="w-[20%] min-w-[150px] px-3 py-4 text-left text-xs font-bold uppercase tracking-wider text-gray-700 dark:text-gray-300"
|
||||
>
|
||||
使用统计
|
||||
</th>
|
||||
<th
|
||||
class="w-[10%] min-w-[100px] px-3 py-4 text-left text-xs font-bold uppercase tracking-wider text-gray-700 dark:text-gray-300"
|
||||
>
|
||||
操作
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-200/50 dark:divide-gray-600/50">
|
||||
<tr v-for="key in deletedApiKeys" :key="key.id" class="table-row">
|
||||
<td class="px-3 py-4">
|
||||
<div class="flex items-center">
|
||||
<div
|
||||
class="truncate text-sm font-semibold text-gray-900 dark:text-gray-100"
|
||||
:title="key.name"
|
||||
class="mr-2 flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg bg-gradient-to-br from-red-500 to-red-600"
|
||||
>
|
||||
{{ key.name }}
|
||||
<i class="fas fa-trash text-xs text-white" />
|
||||
</div>
|
||||
<div
|
||||
class="truncate text-xs text-gray-500 dark:text-gray-400"
|
||||
:title="key.id"
|
||||
>
|
||||
{{ key.id }}
|
||||
<div class="min-w-0">
|
||||
<div
|
||||
class="truncate text-sm font-semibold text-gray-900 dark:text-gray-100"
|
||||
:title="key.name"
|
||||
>
|
||||
{{ key.name }}
|
||||
</div>
|
||||
<div
|
||||
class="truncate text-xs text-gray-500 dark:text-gray-400"
|
||||
:title="key.id"
|
||||
>
|
||||
{{ key.id }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-3 py-4">
|
||||
<div class="text-sm">
|
||||
<span v-if="key.createdBy === 'admin'" class="text-blue-600">
|
||||
<i class="fas fa-user-shield mr-1" />
|
||||
管理员
|
||||
</span>
|
||||
<span v-else-if="key.userUsername" class="text-green-600">
|
||||
<i class="fas fa-user mr-1" />
|
||||
{{ key.userUsername }}
|
||||
</span>
|
||||
<span v-else class="text-gray-500 dark:text-gray-400">
|
||||
<i class="fas fa-question-circle mr-1" />
|
||||
未知
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500 dark:text-gray-400">
|
||||
{{ formatDate(key.createdAt) }}
|
||||
</td>
|
||||
<td class="px-3 py-4">
|
||||
<div class="text-sm">
|
||||
<span v-if="key.deletedByType === 'admin'" class="text-blue-600">
|
||||
<i class="fas fa-user-shield mr-1" />
|
||||
{{ key.deletedBy }}
|
||||
</span>
|
||||
<span v-else-if="key.deletedByType === 'user'" class="text-green-600">
|
||||
<i class="fas fa-user mr-1" />
|
||||
{{ key.deletedBy }}
|
||||
</span>
|
||||
<span v-else class="text-gray-500 dark:text-gray-400">
|
||||
<i class="fas fa-cog mr-1" />
|
||||
{{ key.deletedBy }}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500 dark:text-gray-400">
|
||||
{{ formatDate(key.deletedAt) }}
|
||||
</td>
|
||||
<td class="px-3 py-4">
|
||||
<div class="text-sm">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-gray-600 dark:text-gray-400">请求</span>
|
||||
<span class="font-semibold text-gray-900 dark:text-gray-100">
|
||||
{{ formatNumber(key.usage?.total?.requests || 0) }}次
|
||||
</td>
|
||||
<td class="px-3 py-4">
|
||||
<div class="text-sm">
|
||||
<span v-if="key.createdBy === 'admin'" class="text-blue-600">
|
||||
<i class="fas fa-user-shield mr-1" />
|
||||
管理员
|
||||
</span>
|
||||
<span v-else-if="key.userUsername" class="text-green-600">
|
||||
<i class="fas fa-user mr-1" />
|
||||
{{ key.userUsername }}
|
||||
</span>
|
||||
<span v-else class="text-gray-500 dark:text-gray-400">
|
||||
<i class="fas fa-question-circle mr-1" />
|
||||
未知
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-gray-600 dark:text-gray-400">费用</span>
|
||||
<span class="font-semibold text-green-600">
|
||||
${{ (key.usage?.total?.cost || 0).toFixed(4) }}
|
||||
</td>
|
||||
<td
|
||||
class="whitespace-nowrap px-3 py-4 text-sm text-gray-500 dark:text-gray-400"
|
||||
>
|
||||
{{ formatDate(key.createdAt) }}
|
||||
</td>
|
||||
<td class="px-3 py-4">
|
||||
<div class="text-sm">
|
||||
<span v-if="key.deletedByType === 'admin'" class="text-blue-600">
|
||||
<i class="fas fa-user-shield mr-1" />
|
||||
{{ key.deletedBy }}
|
||||
</span>
|
||||
<span v-else-if="key.deletedByType === 'user'" class="text-green-600">
|
||||
<i class="fas fa-user mr-1" />
|
||||
{{ key.deletedBy }}
|
||||
</span>
|
||||
<span v-else class="text-gray-500 dark:text-gray-400">
|
||||
<i class="fas fa-cog mr-1" />
|
||||
{{ key.deletedBy }}
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="key.lastUsedAt" class="flex items-center justify-between">
|
||||
<span class="text-gray-600 dark:text-gray-400">最后使用</span>
|
||||
<span class="font-medium text-gray-700 dark:text-gray-300">
|
||||
{{ formatLastUsed(key.lastUsedAt) }}
|
||||
</span>
|
||||
</td>
|
||||
<td
|
||||
class="whitespace-nowrap px-3 py-4 text-sm text-gray-500 dark:text-gray-400"
|
||||
>
|
||||
{{ formatDate(key.deletedAt) }}
|
||||
</td>
|
||||
<td class="px-3 py-4">
|
||||
<div class="text-sm">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-gray-600 dark:text-gray-400">请求</span>
|
||||
<span class="font-semibold text-gray-900 dark:text-gray-100">
|
||||
{{ formatNumber(key.usage?.total?.requests || 0) }}次
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-gray-600 dark:text-gray-400">费用</span>
|
||||
<span class="font-semibold text-green-600">
|
||||
${{ (key.usage?.total?.cost || 0).toFixed(4) }}
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="key.lastUsedAt" class="flex items-center justify-between">
|
||||
<span class="text-gray-600 dark:text-gray-400">最后使用</span>
|
||||
<span class="font-medium text-gray-700 dark:text-gray-300">
|
||||
{{ formatLastUsed(key.lastUsedAt) }}
|
||||
</span>
|
||||
</div>
|
||||
<div v-else class="text-xs text-gray-400">从未使用</div>
|
||||
</div>
|
||||
<div v-else class="text-xs text-gray-400">从未使用</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</td>
|
||||
<td class="px-3 py-4">
|
||||
<div class="flex items-center gap-2">
|
||||
<button
|
||||
v-if="key.canRestore"
|
||||
class="rounded-lg bg-green-50 px-3 py-1.5 text-xs font-medium text-green-600 transition-colors hover:bg-green-100 dark:bg-green-900/30 dark:text-green-400 dark:hover:bg-green-900/50"
|
||||
title="恢复 API Key"
|
||||
@click="restoreApiKey(key.id)"
|
||||
>
|
||||
<i class="fas fa-undo mr-1" />
|
||||
恢复
|
||||
</button>
|
||||
<button
|
||||
class="rounded-lg bg-red-50 px-3 py-1.5 text-xs font-medium text-red-600 transition-colors hover:bg-red-100 dark:bg-red-900/30 dark:text-red-400 dark:hover:bg-red-900/50"
|
||||
title="彻底删除 API Key"
|
||||
@click="permanentDeleteApiKey(key.id)"
|
||||
>
|
||||
<i class="fas fa-times mr-1" />
|
||||
彻底删除
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -2325,6 +2371,118 @@ const deleteApiKey = async (keyId) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 恢复API Key
|
||||
const restoreApiKey = async (keyId) => {
|
||||
let confirmed = false
|
||||
|
||||
if (window.showConfirm) {
|
||||
confirmed = await window.showConfirm(
|
||||
'恢复 API Key',
|
||||
'确定要恢复这个 API Key 吗?恢复后可以重新使用。',
|
||||
'确定恢复',
|
||||
'取消'
|
||||
)
|
||||
} else {
|
||||
// 降级方案
|
||||
confirmed = confirm('确定要恢复这个 API Key 吗?恢复后可以重新使用。')
|
||||
}
|
||||
|
||||
if (!confirmed) return
|
||||
|
||||
try {
|
||||
const data = await apiClient.post(`/admin/api-keys/${keyId}/restore`)
|
||||
if (data.success) {
|
||||
showToast('API Key 已成功恢复', 'success')
|
||||
// 刷新已删除列表
|
||||
await loadDeletedApiKeys()
|
||||
// 同时刷新活跃列表
|
||||
await loadApiKeys()
|
||||
} else {
|
||||
showToast(data.error || '恢复失败', 'error')
|
||||
}
|
||||
} catch (error) {
|
||||
showToast(error.response?.data?.error || '恢复失败', 'error')
|
||||
}
|
||||
}
|
||||
|
||||
// 彻底删除API Key
|
||||
const permanentDeleteApiKey = async (keyId) => {
|
||||
let confirmed = false
|
||||
|
||||
if (window.showConfirm) {
|
||||
confirmed = await window.showConfirm(
|
||||
'彻底删除 API Key',
|
||||
'确定要彻底删除这个 API Key 吗?此操作不可恢复,所有相关数据将被永久删除。',
|
||||
'确定彻底删除',
|
||||
'取消'
|
||||
)
|
||||
} else {
|
||||
// 降级方案
|
||||
confirmed = confirm('确定要彻底删除这个 API Key 吗?此操作不可恢复,所有相关数据将被永久删除。')
|
||||
}
|
||||
|
||||
if (!confirmed) return
|
||||
|
||||
try {
|
||||
const data = await apiClient.delete(`/admin/api-keys/${keyId}/permanent`)
|
||||
if (data.success) {
|
||||
showToast('API Key 已彻底删除', 'success')
|
||||
// 刷新已删除列表
|
||||
loadDeletedApiKeys()
|
||||
} else {
|
||||
showToast(data.error || '彻底删除失败', 'error')
|
||||
}
|
||||
} catch (error) {
|
||||
showToast(error.response?.data?.error || '彻底删除失败', 'error')
|
||||
}
|
||||
}
|
||||
|
||||
// 清空所有已删除的API Keys
|
||||
const clearAllDeletedApiKeys = async () => {
|
||||
const count = deletedApiKeys.value.length
|
||||
if (count === 0) {
|
||||
showToast('没有需要清空的 API Keys', 'info')
|
||||
return
|
||||
}
|
||||
|
||||
let confirmed = false
|
||||
|
||||
if (window.showConfirm) {
|
||||
confirmed = await window.showConfirm(
|
||||
'清空所有已删除的 API Keys',
|
||||
`确定要彻底删除全部 ${count} 个已删除的 API Keys 吗?此操作不可恢复,所有相关数据将被永久删除。`,
|
||||
'确定清空全部',
|
||||
'取消'
|
||||
)
|
||||
} else {
|
||||
// 降级方案
|
||||
confirmed = confirm(`确定要彻底删除全部 ${count} 个已删除的 API Keys 吗?此操作不可恢复。`)
|
||||
}
|
||||
|
||||
if (!confirmed) return
|
||||
|
||||
try {
|
||||
const data = await apiClient.delete('/admin/api-keys/deleted/clear-all')
|
||||
if (data.success) {
|
||||
showToast(data.message || '已清空所有已删除的 API Keys', 'success')
|
||||
|
||||
// 如果有失败的,显示详细信息
|
||||
if (data.details && data.details.failedCount > 0) {
|
||||
const errors = data.details.errors
|
||||
console.error('部分API Keys清空失败:', errors)
|
||||
showToast(`${data.details.failedCount} 个清空失败,请查看控制台`, 'warning')
|
||||
}
|
||||
|
||||
// 刷新已删除列表
|
||||
loadDeletedApiKeys()
|
||||
} else {
|
||||
showToast(data.error || '清空失败', 'error')
|
||||
}
|
||||
} catch (error) {
|
||||
showToast(error.response?.data?.error || '清空失败', 'error')
|
||||
}
|
||||
}
|
||||
|
||||
// 批量删除API Keys
|
||||
const batchDeleteApiKeys = async () => {
|
||||
const selectedCount = selectedApiKeys.value.length
|
||||
|
||||
@@ -1639,7 +1639,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue'
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
// 当前系统选择
|
||||
const activeTutorialSystem = ref('windows')
|
||||
@@ -1653,6 +1653,14 @@ const tutorialSystems = [
|
||||
|
||||
// 获取基础URL前缀
|
||||
const getBaseUrlPrefix = () => {
|
||||
// 优先使用环境变量配置的自定义前缀
|
||||
const customPrefix = import.meta.env.VITE_API_BASE_PREFIX
|
||||
if (customPrefix) {
|
||||
// 去除末尾的斜杠
|
||||
return customPrefix.replace(/\/$/, '')
|
||||
}
|
||||
|
||||
// 否则使用当前浏览器访问地址
|
||||
// 更健壮的获取 origin 的方法,兼容旧版浏览器和特殊环境
|
||||
let origin = ''
|
||||
|
||||
|
||||
Reference in New Issue
Block a user