File size: 10,896 Bytes
69b897d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
<template>
<Teleport to="body">
<div class="modal fixed inset-0 z-50 flex items-center justify-center p-4">
<div
class="modal-content custom-scrollbar mx-auto max-h-[90vh] w-full max-w-2xl overflow-y-auto p-8"
>
<div class="mb-6 flex items-center justify-between">
<div class="flex items-center gap-3">
<div
class="flex h-12 w-12 items-center justify-center rounded-xl bg-gradient-to-br from-green-500 to-green-600"
>
<i class="fas fa-layer-group text-lg text-white" />
</div>
<div>
<h3 class="text-xl font-bold text-gray-900">批量创建成功</h3>
<p class="text-sm text-gray-600">成功创建 {{ apiKeys.length }} 个 API Key</p>
</div>
</div>
<button
class="text-gray-400 transition-colors hover:text-gray-600"
title="直接关闭(不推荐)"
@click="handleDirectClose"
>
<i class="fas fa-times text-xl" />
</button>
</div>
<!-- 警告提示 -->
<div class="mb-6 border-l-4 border-amber-400 bg-amber-50 p-4">
<div class="flex items-start">
<div
class="mt-0.5 flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-lg bg-amber-400"
>
<i class="fas fa-exclamation-triangle text-sm text-white" />
</div>
<div class="ml-3">
<h5 class="mb-1 font-semibold text-amber-900">重要提醒</h5>
<p class="text-sm text-amber-800">
这是您唯一能看到所有 API Key 的机会。关闭此窗口后,系统将不再显示完整的 API
Key。请立即下载并妥善保存。
</p>
</div>
</div>
</div>
<!-- 统计信息 -->
<div class="mb-6 grid grid-cols-2 gap-4 md:grid-cols-4">
<div
class="rounded-lg border border-blue-200 bg-gradient-to-br from-blue-50 to-blue-100 p-4"
>
<div class="flex items-center justify-between">
<div>
<p class="text-xs font-medium text-blue-600">创建数量</p>
<p class="mt-1 text-2xl font-bold text-blue-900">
{{ apiKeys.length }}
</p>
</div>
<div
class="flex h-10 w-10 items-center justify-center rounded-lg bg-blue-500 bg-opacity-20"
>
<i class="fas fa-key text-blue-600" />
</div>
</div>
</div>
<div
class="rounded-lg border border-green-200 bg-gradient-to-br from-green-50 to-green-100 p-4"
>
<div class="flex items-center justify-between">
<div>
<p class="text-xs font-medium text-green-600">基础名称</p>
<p class="mt-1 truncate text-lg font-bold text-green-900">
{{ baseName }}
</p>
</div>
<div
class="flex h-10 w-10 items-center justify-center rounded-lg bg-green-500 bg-opacity-20"
>
<i class="fas fa-tag text-green-600" />
</div>
</div>
</div>
<div
class="rounded-lg border border-purple-200 bg-gradient-to-br from-purple-50 to-purple-100 p-4"
>
<div class="flex items-center justify-between">
<div>
<p class="text-xs font-medium text-purple-600">权限范围</p>
<p class="mt-1 text-lg font-bold text-purple-900">
{{ getPermissionText() }}
</p>
</div>
<div
class="flex h-10 w-10 items-center justify-center rounded-lg bg-purple-500 bg-opacity-20"
>
<i class="fas fa-shield-alt text-purple-600" />
</div>
</div>
</div>
<div
class="rounded-lg border border-orange-200 bg-gradient-to-br from-orange-50 to-orange-100 p-4"
>
<div class="flex items-center justify-between">
<div>
<p class="text-xs font-medium text-orange-600">过期时间</p>
<p class="mt-1 text-lg font-bold text-orange-900">
{{ getExpiryText() }}
</p>
</div>
<div
class="flex h-10 w-10 items-center justify-center rounded-lg bg-orange-500 bg-opacity-20"
>
<i class="fas fa-clock text-orange-600" />
</div>
</div>
</div>
</div>
<!-- API Keys 预览 -->
<div class="mb-6">
<div class="mb-3 flex items-center justify-between">
<label class="text-sm font-semibold text-gray-700">API Keys 预览</label>
<div class="flex items-center gap-2">
<button
class="flex items-center gap-1 text-xs text-blue-600 hover:text-blue-800"
type="button"
@click="togglePreview"
>
<i :class="['fas', showPreview ? 'fa-eye-slash' : 'fa-eye']" />
{{ showPreview ? '隐藏' : '显示' }}预览
</button>
<span class="text-xs text-gray-500">(最多显示前10个)</span>
</div>
</div>
<div
v-if="showPreview"
class="custom-scrollbar max-h-48 overflow-y-auto rounded-lg bg-gray-900 p-4"
>
<pre class="font-mono text-xs text-gray-300">{{ getPreviewText() }}</pre>
</div>
</div>
<!-- 操作按钮 -->
<div class="flex gap-3">
<button
class="btn btn-primary flex flex-1 items-center justify-center gap-2 px-6 py-3 font-semibold"
@click="downloadApiKeys"
>
<i class="fas fa-download" />
下载所有 API Keys
</button>
<button
class="rounded-xl border border-gray-300 bg-gray-200 px-6 py-3 font-semibold text-gray-800 transition-colors hover:bg-gray-300"
@click="handleClose"
>
我已保存
</button>
</div>
<!-- 额外提示 -->
<div class="mt-4 rounded-lg border border-blue-200 bg-blue-50 p-3">
<p class="flex items-start text-xs text-blue-700">
<i class="fas fa-info-circle mr-2 mt-0.5 flex-shrink-0" />
<span>
下载的文件格式为文本文件(.txt),每行包含一个 API Key。
请将文件保存在安全的位置,避免泄露。
</span>
</p>
</div>
</div>
</div>
</Teleport>
</template>
<script setup>
import { ref, computed } from 'vue'
import { showToast } from '@/utils/toast'
const props = defineProps({
apiKeys: {
type: Array,
required: true
}
})
const emit = defineEmits(['close'])
const showPreview = ref(false)
// 获取基础名称
const baseName = computed(() => {
if (props.apiKeys.length > 0) {
const firstKey = props.apiKeys[0]
// 提取基础名称(去掉 _1, _2 等后缀)
const match = firstKey.name.match(/^(.+)_\d+$/)
return match ? match[1] : firstKey.name
}
return ''
})
// 获取权限文本
const getPermissionText = () => {
if (props.apiKeys.length === 0) return '未知'
const permissions = props.apiKeys[0].permissions
const permissionMap = {
all: '全部服务',
claude: '仅 Claude',
gemini: '仅 Gemini'
}
return permissionMap[permissions] || permissions
}
// 获取过期时间文本
const getExpiryText = () => {
if (props.apiKeys.length === 0) return '未知'
const expiresAt = props.apiKeys[0].expiresAt
if (!expiresAt) return '永不过期'
const expiryDate = new Date(expiresAt)
const now = new Date()
const diffDays = Math.ceil((expiryDate - now) / (1000 * 60 * 60 * 24))
if (diffDays <= 7) return `${diffDays}天`
if (diffDays <= 30) return `${Math.ceil(diffDays / 7)}周`
if (diffDays <= 365) return `${Math.ceil(diffDays / 30)}个月`
return `${Math.ceil(diffDays / 365)}年`
}
// 切换预览显示
const togglePreview = () => {
showPreview.value = !showPreview.value
}
// 获取预览文本
const getPreviewText = () => {
const previewKeys = props.apiKeys.slice(0, 10)
const lines = previewKeys.map((key) => {
return `${key.name}: ${key.apiKey || key.key || ''}`
})
if (props.apiKeys.length > 10) {
lines.push(`... 还有 ${props.apiKeys.length - 10} 个 API Key`)
}
return lines.join('\n')
}
// 下载 API Keys
const downloadApiKeys = () => {
// 生成文件内容
const content = props.apiKeys
.map((key) => {
return `${key.name}: ${key.apiKey || key.key || ''}`
})
.join('\n')
// 创建 Blob 对象
const blob = new Blob([content], { type: 'text/plain;charset=utf-8' })
// 创建下载链接
const url = URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
// 生成文件名(包含时间戳)
const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, -5)
link.download = `api-keys-${baseName.value}-${timestamp}.txt`
// 触发下载
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
// 释放 URL 对象
URL.revokeObjectURL(url)
showToast('API Keys 文件已下载', 'success')
}
// 关闭弹窗(带确认)
const handleClose = async () => {
if (window.showConfirm) {
const confirmed = await window.showConfirm(
'关闭提醒',
'关闭后将无法再次查看这些 API Key,请确保已经下载并妥善保存。\n\n确定要关闭吗?',
'确定关闭',
'返回下载'
)
if (confirmed) {
emit('close')
}
} else {
// 降级方案
const confirmed = confirm(
'关闭后将无法再次查看这些 API Key,请确保已经下载并妥善保存。\n\n确定要关闭吗?'
)
if (confirmed) {
emit('close')
}
}
}
// 直接关闭(不带确认)
const handleDirectClose = async () => {
if (window.showConfirm) {
const confirmed = await window.showConfirm(
'确定要关闭吗?',
'您还没有下载 API Keys,关闭后将无法再次查看。\n\n强烈建议您先下载保存。',
'仍然关闭',
'返回下载'
)
if (confirmed) {
emit('close')
}
} else {
// 降级方案
const confirmed = confirm('您还没有下载 API Keys,关闭后将无法再次查看。\n\n确定要关闭吗?')
if (confirmed) {
emit('close')
}
}
}
</script>
<style scoped>
pre {
white-space: pre-wrap;
word-wrap: break-word;
}
</style>
|