mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 09:38:02 +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) => {
|
||||
|
||||
Reference in New Issue
Block a user