Spaces:
Sleeping
Sleeping
github-actions[bot] commited on
Commit ·
f91fed0
1
Parent(s): 9c4cea4
Sync from GitHub Viciy2023/Qwen2API-A@72fd99becfe162580b4156779601adcd284bcba9
Browse files- public/src/views/dashboard.vue +420 -244
- src/routes/settings.js +64 -1
- src/utils/logger.js +50 -1
public/src/views/dashboard.vue
CHANGED
|
@@ -1,74 +1,53 @@
|
|
| 1 |
<template>
|
| 2 |
<div class="w-100vw h-100vh p-4 overflow-y-auto">
|
| 3 |
-
<div class="container mx-auto">
|
| 4 |
-
<div class="
|
| 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 |
-
</button>
|
| 49 |
-
<button @click="openModelsPanel"
|
| 50 |
-
class="action-button font-bold border border-violet-200 bg-violet-50 text-violet-900 px-4 py-2 rounded-xl shadow-sm hover:bg-violet-100 hover:border-violet-400 transition-all duration-300 transform hover:-translate-y-1 active:translate-y-0 text-center">
|
| 51 |
-
可用模型
|
| 52 |
-
</button>
|
| 53 |
-
<router-link to="/settings"
|
| 54 |
-
class="action-button col-span-2 sm:col-span-1 font-bold border border-blue-200 bg-blue-50 text-blue-900 px-4 py-2 rounded-xl shadow-sm hover:bg-blue-100 hover:border-blue-400 transition-all duration-300 transform hover:-translate-y-1 active:translate-y-0 text-center">
|
| 55 |
-
系统设置
|
| 56 |
-
</router-link>
|
| 57 |
-
</div>
|
| 58 |
-
</div>
|
| 59 |
|
| 60 |
<!-- 分页控制区 -->
|
| 61 |
-
<div class="flex justify-between
|
| 62 |
-
<div class="flex items-center space-x-2">
|
| 63 |
-
<span class="text-gray-700">每页显示:</span>
|
| 64 |
-
<select v-model="pageSize" @change="changePageSize" class="rounded-lg border-gray-300 bg-white/50 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 transition-all duration-300">
|
| 65 |
-
<option :value="10">10</option>
|
| 66 |
-
<option :value="20">20</option>
|
| 67 |
-
<option :value="50">50</option>
|
| 68 |
-
<option :value="100">100</option>
|
| 69 |
-
<option :value="200">200</option>
|
| 70 |
-
</select>
|
| 71 |
-
</div>
|
| 72 |
<div class="flex space-x-2 items-center">
|
| 73 |
<span class="text-gray-700">共 {{ totalItems }} 项</span>
|
| 74 |
<button
|
|
@@ -96,7 +75,7 @@
|
|
| 96 |
</div>
|
| 97 |
|
| 98 |
<!-- 多选操作区 -->
|
| 99 |
-
<div class="flex justify-between
|
| 100 |
<div class="flex items-center space-x-3">
|
| 101 |
<label class="inline-flex items-center cursor-pointer group">
|
| 102 |
<div class="relative">
|
|
@@ -139,10 +118,10 @@
|
|
| 139 |
|
| 140 |
<!-- Token列表 -->
|
| 141 |
<div class="max-h-[calc(75vh)] overflow-y-auto pr-2 scrollbar-hidden">
|
| 142 |
-
<div class="grid grid-cols-1 md:grid-cols-2
|
| 143 |
<div v-for="token in displayedTokens"
|
| 144 |
:key="token.email"
|
| 145 |
-
class="token-card group relative overflow-hidden rounded-2xl transition-all duration-300 hover:shadow-2xl pt-
|
| 146 |
:class="{'ring-2 ring-indigo-500 ring-opacity-75': isSelected(token.email)}">
|
| 147 |
<div class="absolute top-3 left-3 z-10">
|
| 148 |
<label class="custom-checkbox cursor-pointer">
|
|
@@ -158,43 +137,43 @@
|
|
| 158 |
</label>
|
| 159 |
</div>
|
| 160 |
<div class="absolute inset-0 bg-white/30 backdrop-blur-md border border-white/30"></div>
|
| 161 |
-
<div class="relative p-
|
| 162 |
-
<div class="flex flex-col space-y-
|
| 163 |
-
<div class="relative flex items-center bg-blue-50/80 rounded-lg px-2 py-1">
|
| 164 |
<div class="overflow-x-auto scrollbar-hide flex-1 flex items-center space-x-2">
|
| 165 |
-
<span class="text-gray-700 min-w-[
|
| 166 |
<span class="font-medium whitespace-nowrap text-left">{{ token.email }}</span>
|
| 167 |
</div>
|
| 168 |
<button @click="copyToClipboard(token.email)" class="absolute right-2 opacity-0 hover:opacity-100 transition-opacity bg-blue-200 hover:bg-blue-300 rounded px-2 py-1 text-base">📋</button>
|
| 169 |
</div>
|
| 170 |
-
<div class="relative flex items-center bg-blue-50/80 rounded-lg px-2 py-1">
|
| 171 |
<div class="overflow-x-auto scrollbar-hide flex-1 flex items-center space-x-2">
|
| 172 |
-
<span class="text-gray-700 min-w-[
|
| 173 |
<span class="font-medium whitespace-nowrap text-left">{{ token.password }}</span>
|
| 174 |
</div>
|
| 175 |
<button @click="copyToClipboard(token.password)" class="absolute right-2 opacity-0 hover:opacity-100 transition-opacity bg-blue-200 hover:bg-blue-300 rounded px-2 py-1 text-base">📋</button>
|
| 176 |
</div>
|
| 177 |
-
<div class="relative flex items-center bg-blue-50/80 rounded-lg px-2 py-1">
|
| 178 |
<div class="overflow-x-auto scrollbar-hide flex-1 flex items-center space-x-2">
|
| 179 |
-
<span class="text-gray-700 min-w-[
|
| 180 |
<span class="font-medium whitespace-nowrap text-left text-sm">{{ token.token }}</span>
|
| 181 |
</div>
|
| 182 |
<button @click="copyToClipboard(token.token)" class="absolute right-2 opacity-0 hover:opacity-100 transition-opacity bg-blue-200 hover:bg-blue-300 rounded px-2 py-1 text-base">📋</button>
|
| 183 |
</div>
|
| 184 |
-
<div class="relative flex items-center bg-blue-50/80 rounded-lg px-2 py-1">
|
| 185 |
<div class="overflow-x-auto scrollbar-hide flex-1 flex items-center space-x-2">
|
| 186 |
-
<span class="text-gray-700 min-w-[
|
| 187 |
-
<span class="font-medium whitespace-nowrap text-left">{{ new Date(token.expires * 1000).toLocaleString() }}</span>
|
| 188 |
</div>
|
| 189 |
<button @click="copyToClipboard(new Date(token.expires * 1000).toLocaleString())" class="absolute right-2 opacity-0 hover:opacity-100 transition-opacity bg-blue-200 hover:bg-blue-300 rounded px-2 py-1 text-base">📋</button>
|
| 190 |
</div>
|
| 191 |
</div>
|
| 192 |
|
| 193 |
-
<div class="pt-
|
| 194 |
<button @click="refreshToken(token.email)"
|
| 195 |
:disabled="refreshingTokens.includes(token.email)"
|
| 196 |
:class="[
|
| 197 |
-
'w-full py-2 rounded-lg transition-all duration-300 flex items-center justify-center space-x-2',
|
| 198 |
refreshingTokens.includes(token.email)
|
| 199 |
? 'bg-green-400 text-white refreshing-button-green cursor-not-allowed'
|
| 200 |
: 'macaron-green-button text-green-600 hover:bg-green-100 border border-green-200'
|
|
@@ -209,13 +188,175 @@
|
|
| 209 |
<span v-else>刷新令牌</span>
|
| 210 |
</button>
|
| 211 |
<button @click="deleteToken(token.email)"
|
| 212 |
-
class="w-full group-hover:bg-red-50 text-red-600 py-2 rounded-lg transition-all duration-300 hover:bg-red-100">
|
| 213 |
删除账号
|
| 214 |
</button>
|
| 215 |
</div>
|
| 216 |
</div>
|
| 217 |
</div>
|
| 218 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
</div>
|
| 220 |
</div>
|
| 221 |
|
|
@@ -314,170 +455,15 @@
|
|
| 314 |
</div>
|
| 315 |
</div>
|
| 316 |
|
| 317 |
-
<!-- 可用模型面板 -->
|
| 318 |
-
<div v-if="showModelsPanel"
|
| 319 |
-
class="fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50"
|
| 320 |
-
@click.self="showModelsPanel = false">
|
| 321 |
-
<div class="relative bg-white/90 backdrop-blur-lg rounded-2xl p-6 w-11/12 max-w-5xl max-h-[85vh] overflow-hidden transform transition-all duration-300 scale-100 opacity-100">
|
| 322 |
-
<div class="flex items-center justify-between mb-4">
|
| 323 |
-
<div>
|
| 324 |
-
<h2 class="text-2xl font-bold text-slate-800">可用模型</h2>
|
| 325 |
-
<p class="text-sm text-slate-500 mt-1">展示当前实例可直接调用的全部模型</p>
|
| 326 |
-
</div>
|
| 327 |
-
<button @click="showModelsPanel = false"
|
| 328 |
-
class="px-3 py-2 rounded-xl bg-slate-100 text-slate-600 hover:bg-slate-200 transition-all duration-300">
|
| 329 |
-
关闭
|
| 330 |
-
</button>
|
| 331 |
-
</div>
|
| 332 |
-
|
| 333 |
-
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 mb-4">
|
| 334 |
-
<div class="flex flex-wrap items-center gap-2 text-sm text-slate-600">
|
| 335 |
-
<span>共 {{ availableModels.length }} 个模型</span>
|
| 336 |
-
<button @click="setActiveModelFilter('all')"
|
| 337 |
-
:class="[
|
| 338 |
-
'rounded-full px-3 py-1 text-xs font-semibold transition-all duration-300',
|
| 339 |
-
activeModelFilter === 'all'
|
| 340 |
-
? 'bg-slate-800 text-white'
|
| 341 |
-
: 'bg-slate-100 text-slate-600 hover:bg-slate-200'
|
| 342 |
-
]">
|
| 343 |
-
全部 {{ availableModels.length }}
|
| 344 |
-
</button>
|
| 345 |
-
<button @click="setActiveModelFilter('base')"
|
| 346 |
-
:class="getFilterBadgeClass('base', 'bg-slate-100', 'text-slate-600', 'hover:bg-slate-200', 'bg-slate-700')">
|
| 347 |
-
基础 {{ allModelGroups.base.length }}
|
| 348 |
-
</button>
|
| 349 |
-
<button @click="setActiveModelFilter('thinking')"
|
| 350 |
-
:class="getFilterBadgeClass('thinking', 'bg-amber-100', 'text-amber-700', 'hover:bg-amber-200', 'bg-amber-500')">
|
| 351 |
-
Thinking {{ allModelGroups.thinking.length }}
|
| 352 |
-
</button>
|
| 353 |
-
<button @click="setActiveModelFilter('search')"
|
| 354 |
-
:class="getFilterBadgeClass('search', 'bg-cyan-100', 'text-cyan-700', 'hover:bg-cyan-200', 'bg-cyan-500')">
|
| 355 |
-
Search {{ allModelGroups.search.length }}
|
| 356 |
-
</button>
|
| 357 |
-
<button @click="setActiveModelFilter('image')"
|
| 358 |
-
:class="getFilterBadgeClass('image', 'bg-rose-100', 'text-rose-700', 'hover:bg-rose-200', 'bg-rose-500')">
|
| 359 |
-
Image {{ allModelGroups.image.length }}
|
| 360 |
-
</button>
|
| 361 |
-
<button @click="setActiveModelFilter('video')"
|
| 362 |
-
:class="getFilterBadgeClass('video', 'bg-indigo-100', 'text-indigo-700', 'hover:bg-indigo-200', 'bg-indigo-500')">
|
| 363 |
-
Video {{ allModelGroups.video.length }}
|
| 364 |
-
</button>
|
| 365 |
-
<button @click="setActiveModelFilter('imageEdit')"
|
| 366 |
-
:class="getFilterBadgeClass('imageEdit', 'bg-emerald-100', 'text-emerald-700', 'hover:bg-emerald-200', 'bg-emerald-500')">
|
| 367 |
-
Image Edit {{ allModelGroups.imageEdit.length }}
|
| 368 |
-
</button>
|
| 369 |
-
</div>
|
| 370 |
-
<div class="flex w-full sm:w-auto gap-2">
|
| 371 |
-
<div class="relative w-full sm:w-72">
|
| 372 |
-
<input v-model="modelKeyword"
|
| 373 |
-
type="text"
|
| 374 |
-
placeholder="搜索模型 ID"
|
| 375 |
-
class="w-full rounded-xl border border-slate-200 bg-white px-4 py-2 shadow-sm focus:border-violet-400 focus:ring-violet-400 transition-all duration-300">
|
| 376 |
-
</div>
|
| 377 |
-
<button @click="refreshModels"
|
| 378 |
-
:disabled="isLoadingModels"
|
| 379 |
-
:class="[
|
| 380 |
-
'rounded-xl px-4 py-2 text-sm font-semibold transition-all duration-300 border',
|
| 381 |
-
isLoadingModels
|
| 382 |
-
? 'bg-violet-200 text-violet-600 border-violet-200 cursor-not-allowed'
|
| 383 |
-
: 'bg-violet-600 text-white border-violet-600 hover:bg-violet-700'
|
| 384 |
-
]">
|
| 385 |
-
{{ isLoadingModels ? '刷新中...' : '刷新模型列表' }}
|
| 386 |
-
</button>
|
| 387 |
-
</div>
|
| 388 |
-
</div>
|
| 389 |
-
|
| 390 |
-
<div v-if="isLoadingModels" class="py-12 text-center text-slate-500">
|
| 391 |
-
正在加载模型列表...
|
| 392 |
-
</div>
|
| 393 |
-
|
| 394 |
-
<div v-else-if="modelsError" class="rounded-2xl border border-red-200 bg-red-50 px-4 py-8 text-center text-red-600">
|
| 395 |
-
<div class="text-lg font-semibold">模型列表加载失败</div>
|
| 396 |
-
<div class="mt-2 text-sm whitespace-pre-line">{{ modelsError }}</div>
|
| 397 |
-
<button @click="refreshModels"
|
| 398 |
-
class="mt-4 rounded-xl bg-red-600 px-4 py-2 text-sm font-semibold text-white hover:bg-red-700 transition-all duration-300">
|
| 399 |
-
重新加载
|
| 400 |
-
</button>
|
| 401 |
-
</div>
|
| 402 |
-
|
| 403 |
-
<div v-else ref="modelsScrollContainer" class="max-h-[60vh] overflow-y-auto pr-2">
|
| 404 |
-
<div class="space-y-5">
|
| 405 |
-
<div v-for="group in groupedModelSections"
|
| 406 |
-
:key="group.key"
|
| 407 |
-
v-show="group.models.length"
|
| 408 |
-
class="rounded-2xl border border-slate-200 bg-white/70 p-4 shadow-sm">
|
| 409 |
-
<div class="mb-3 flex items-center justify-between gap-3">
|
| 410 |
-
<div>
|
| 411 |
-
<h3 class="text-lg font-semibold text-slate-800">{{ group.title }}</h3>
|
| 412 |
-
<p class="text-xs text-slate-500 mt-1">{{ group.description }}</p>
|
| 413 |
-
<p class="mt-2 text-xs text-slate-400">当前分类已按模型强度从高到低排序</p>
|
| 414 |
-
</div>
|
| 415 |
-
<span :class="group.badgeClass" class="rounded-full px-3 py-1 text-xs font-semibold">
|
| 416 |
-
{{ group.models.length }} 个
|
| 417 |
-
</span>
|
| 418 |
-
</div>
|
| 419 |
-
|
| 420 |
-
<div class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-3">
|
| 421 |
-
<div v-for="model in group.models"
|
| 422 |
-
:key="model.id"
|
| 423 |
-
class="rounded-2xl border border-slate-200 bg-white/80 px-4 py-4 shadow-sm hover:shadow-md transition-all duration-300">
|
| 424 |
-
<div class="flex items-start justify-between gap-3">
|
| 425 |
-
<div class="min-w-0 flex-1">
|
| 426 |
-
<div class="font-semibold text-slate-800 break-all">{{ model.id }}</div>
|
| 427 |
-
<div class="mt-2 text-xs text-slate-500 break-all">模型名称:{{ getModelDisplayName(model) }}</div>
|
| 428 |
-
<div class="mt-2 flex flex-wrap gap-2">
|
| 429 |
-
<span class="rounded-full bg-slate-100 px-2 py-1 text-xs text-slate-600">{{ model.owned_by || 'unknown' }}</span>
|
| 430 |
-
<span v-if="modelTagSummary(model).length"
|
| 431 |
-
class="rounded-full bg-violet-100 px-2 py-1 text-xs text-violet-700">
|
| 432 |
-
{{ modelTagSummary(model).join(' / ') }}
|
| 433 |
-
</span>
|
| 434 |
-
<span class="rounded-full bg-emerald-100 px-2 py-1 text-xs text-emerald-700">
|
| 435 |
-
推荐:{{ getModelUseCase(model) }}
|
| 436 |
-
</span>
|
| 437 |
-
<div class="relative group/tooltip inline-flex">
|
| 438 |
-
<span class="cursor-help rounded-full bg-amber-100 px-2 py-1 text-xs text-amber-700">
|
| 439 |
-
强度:{{ getModelPriorityLabel(model, group.key) }}
|
| 440 |
-
</span>
|
| 441 |
-
<div class="pointer-events-none absolute left-0 top-full z-20 mt-2 hidden w-64 rounded-2xl border border-amber-200 bg-white/95 p-3 text-xs text-slate-600 shadow-xl backdrop-blur-sm group-hover/tooltip:block">
|
| 442 |
-
<div class="font-semibold text-amber-700">强度说明</div>
|
| 443 |
-
<div class="mt-2 leading-5 whitespace-pre-line">{{ getModelPriorityTooltip(model, group.key) }}</div>
|
| 444 |
-
</div>
|
| 445 |
-
</div>
|
| 446 |
-
</div>
|
| 447 |
-
</div>
|
| 448 |
-
</div>
|
| 449 |
-
|
| 450 |
-
<div class="mt-4 grid grid-cols-2 gap-2 sm:grid-cols-3">
|
| 451 |
-
<button @click="copyToClipboard(model.id)"
|
| 452 |
-
class="rounded-lg bg-violet-100 px-2 py-2 text-sm text-violet-700 hover:bg-violet-200 transition-all duration-300">
|
| 453 |
-
复制 ID
|
| 454 |
-
</button>
|
| 455 |
-
<button @click="copyToClipboard(getModelDisplayName(model))"
|
| 456 |
-
class="rounded-lg bg-sky-100 px-2 py-2 text-sm text-sky-700 hover:bg-sky-200 transition-all duration-300">
|
| 457 |
-
复制名字
|
| 458 |
-
</button>
|
| 459 |
-
<button @click="copyModelRequestExample(model)"
|
| 460 |
-
class="col-span-2 sm:col-span-1 rounded-lg bg-amber-100 px-2 py-2 text-sm text-amber-700 hover:bg-amber-200 transition-all duration-300">
|
| 461 |
-
复制示例
|
| 462 |
-
</button>
|
| 463 |
-
</div>
|
| 464 |
-
</div>
|
| 465 |
-
</div>
|
| 466 |
-
</div>
|
| 467 |
-
</div>
|
| 468 |
-
|
| 469 |
-
<div v-if="!filteredModelsByCategory.length" class="py-12 text-center text-slate-500">
|
| 470 |
-
没有匹配的模型
|
| 471 |
-
</div>
|
| 472 |
-
</div>
|
| 473 |
-
</div>
|
| 474 |
-
</div>
|
| 475 |
</div>
|
| 476 |
</template>
|
| 477 |
|
| 478 |
<script setup>
|
| 479 |
import { ref, onMounted, computed } from 'vue'
|
| 480 |
import axios from 'axios'
|
|
|
|
|
|
|
|
|
|
| 481 |
|
| 482 |
const tokens = ref([])
|
| 483 |
const showAddModal = ref(false)
|
|
@@ -505,13 +491,26 @@ const showDeleteAllConfirm = ref(false)
|
|
| 505 |
const isRefreshingAll = ref(false)
|
| 506 |
const isForceRefreshingAll = ref(false)
|
| 507 |
const refreshingTokens = ref([])
|
| 508 |
-
const
|
| 509 |
const availableModels = ref([])
|
| 510 |
const isLoadingModels = ref(false)
|
| 511 |
const modelsError = ref('')
|
| 512 |
const modelKeyword = ref('')
|
| 513 |
const activeModelFilter = ref('all')
|
| 514 |
const modelsScrollContainer = ref(null)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 515 |
|
| 516 |
// Toast 通知
|
| 517 |
const toast = ref({
|
|
@@ -520,6 +519,32 @@ const toast = ref({
|
|
| 520 |
type: 'success'
|
| 521 |
})
|
| 522 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 523 |
const filteredModels = computed(() => {
|
| 524 |
const keyword = modelKeyword.value.trim().toLowerCase()
|
| 525 |
if (!keyword) {
|
|
@@ -692,6 +717,157 @@ const getModelDisplayName = (model) => {
|
|
| 692 |
return model.id
|
| 693 |
}
|
| 694 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 695 |
const setActiveModelFilter = (filterKey) => {
|
| 696 |
activeModelFilter.value = filterKey
|
| 697 |
|
|
@@ -1178,7 +1354,7 @@ const refreshModels = async () => {
|
|
| 1178 |
}
|
| 1179 |
|
| 1180 |
const openModelsPanel = async () => {
|
| 1181 |
-
|
| 1182 |
modelKeyword.value = ''
|
| 1183 |
activeModelFilter.value = 'all'
|
| 1184 |
|
|
|
|
| 1 |
<template>
|
| 2 |
<div class="w-100vw h-100vh p-4 overflow-y-auto">
|
| 3 |
+
<div class="container mx-auto pt-5">
|
| 4 |
+
<div class="grid gap-6 lg:grid-cols-[240px_minmax(0,1fr)]">
|
| 5 |
+
<aside class="rounded-3xl border border-white/50 bg-white/70 p-5 shadow-xl backdrop-blur-lg h-fit lg:sticky lg:top-4">
|
| 6 |
+
<div class="mb-6">
|
| 7 |
+
<h1 class="text-3xl font-bold text-slate-800">Token Manager</h1>
|
| 8 |
+
<p class="mt-2 text-sm text-slate-500">左侧切换菜单,右侧查看对应内容</p>
|
| 9 |
+
</div>
|
| 10 |
+
|
| 11 |
+
<div class="space-y-3">
|
| 12 |
+
<button @click="setDashboardTab('accounts')" :class="getSidebarItemClass('accounts', 'emerald')">账号列表</button>
|
| 13 |
+
<button @click="showAddModal = true" :class="getActionSidebarClass('green')">添加账号</button>
|
| 14 |
+
<button @click="refreshAllAccounts" :disabled="isRefreshingAll" :class="getActionSidebarClass('purple', isRefreshingAll)">
|
| 15 |
+
{{ isRefreshingAll ? '一键刷新中...' : '一键刷新' }}
|
| 16 |
+
</button>
|
| 17 |
+
<button @click="forceRefreshAllAccounts" :disabled="isForceRefreshingAll" :class="getActionSidebarClass('pink', isForceRefreshingAll)">
|
| 18 |
+
{{ isForceRefreshingAll ? '强制刷新中...' : '强制刷新' }}
|
| 19 |
+
</button>
|
| 20 |
+
<button @click="exportAccounts" :class="getActionSidebarClass('yellow')">导出账号</button>
|
| 21 |
+
<button @click="openModelsPanel" :class="getSidebarItemClass('models', 'violet')">可用模型</button>
|
| 22 |
+
<button @click="openLogsPanel" :class="getSidebarItemClass('logs', 'slate')">日志查看</button>
|
| 23 |
+
<button @click="setDashboardTab('settings')" :class="getSidebarItemClass('settings', 'blue')">系统设置</button>
|
| 24 |
+
</div>
|
| 25 |
+
</aside>
|
| 26 |
+
|
| 27 |
+
<section class="rounded-3xl border border-white/50 bg-white/65 p-4 shadow-xl backdrop-blur-lg md:p-6">
|
| 28 |
+
<div v-if="activeDashboardTab === 'accounts'">
|
| 29 |
+
<div class="mb-6 flex flex-col gap-3 md:flex-row md:items-end md:justify-between">
|
| 30 |
+
<div>
|
| 31 |
+
<h2 class="text-2xl font-bold text-slate-800">账号列表</h2>
|
| 32 |
+
<p class="mt-2 text-sm text-slate-500">集中管理邮箱账号、令牌与批量操作</p>
|
| 33 |
+
</div>
|
| 34 |
+
<div class="flex flex-wrap items-center gap-3 text-sm text-slate-600">
|
| 35 |
+
<span>共 {{ totalItems }} 个账号</span>
|
| 36 |
+
<div class="flex items-center gap-2">
|
| 37 |
+
<span>每页显示</span>
|
| 38 |
+
<select v-model="pageSize" @change="changePageSize" class="rounded-lg border-gray-300 bg-white/70 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 transition-all duration-300">
|
| 39 |
+
<option :value="10">10</option>
|
| 40 |
+
<option :value="20">20</option>
|
| 41 |
+
<option :value="50">50</option>
|
| 42 |
+
<option :value="100">100</option>
|
| 43 |
+
<option :value="200">200</option>
|
| 44 |
+
</select>
|
| 45 |
+
</div>
|
| 46 |
+
</div>
|
| 47 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
<!-- 分页控制区 -->
|
| 50 |
+
<div class="mb-4 flex flex-wrap justify-between gap-3 px-1">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
<div class="flex space-x-2 items-center">
|
| 52 |
<span class="text-gray-700">共 {{ totalItems }} 项</span>
|
| 53 |
<button
|
|
|
|
| 75 |
</div>
|
| 76 |
|
| 77 |
<!-- 多选操作区 -->
|
| 78 |
+
<div class="mb-4 flex flex-wrap justify-between gap-3 px-1">
|
| 79 |
<div class="flex items-center space-x-3">
|
| 80 |
<label class="inline-flex items-center cursor-pointer group">
|
| 81 |
<div class="relative">
|
|
|
|
| 118 |
|
| 119 |
<!-- Token列表 -->
|
| 120 |
<div class="max-h-[calc(75vh)] overflow-y-auto pr-2 scrollbar-hidden">
|
| 121 |
+
<div class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 gap-4 p-1">
|
| 122 |
<div v-for="token in displayedTokens"
|
| 123 |
:key="token.email"
|
| 124 |
+
class="token-card group relative overflow-hidden rounded-2xl transition-all duration-300 hover:shadow-2xl pt-3"
|
| 125 |
:class="{'ring-2 ring-indigo-500 ring-opacity-75': isSelected(token.email)}">
|
| 126 |
<div class="absolute top-3 left-3 z-10">
|
| 127 |
<label class="custom-checkbox cursor-pointer">
|
|
|
|
| 137 |
</label>
|
| 138 |
</div>
|
| 139 |
<div class="absolute inset-0 bg-white/30 backdrop-blur-md border border-white/30"></div>
|
| 140 |
+
<div class="relative p-4 flex flex-col gap-3">
|
| 141 |
+
<div class="flex flex-col space-y-2">
|
| 142 |
+
<div class="relative flex items-center bg-blue-50/80 rounded-lg px-2 py-1.5">
|
| 143 |
<div class="overflow-x-auto scrollbar-hide flex-1 flex items-center space-x-2">
|
| 144 |
+
<span class="text-gray-700 min-w-[74px] text-left text-sm font-semibold">📧 Email:</span>
|
| 145 |
<span class="font-medium whitespace-nowrap text-left">{{ token.email }}</span>
|
| 146 |
</div>
|
| 147 |
<button @click="copyToClipboard(token.email)" class="absolute right-2 opacity-0 hover:opacity-100 transition-opacity bg-blue-200 hover:bg-blue-300 rounded px-2 py-1 text-base">📋</button>
|
| 148 |
</div>
|
| 149 |
+
<div class="relative flex items-center bg-blue-50/80 rounded-lg px-2 py-1.5">
|
| 150 |
<div class="overflow-x-auto scrollbar-hide flex-1 flex items-center space-x-2">
|
| 151 |
+
<span class="text-gray-700 min-w-[74px] text-left text-sm font-semibold">🔑 Passwd:</span>
|
| 152 |
<span class="font-medium whitespace-nowrap text-left">{{ token.password }}</span>
|
| 153 |
</div>
|
| 154 |
<button @click="copyToClipboard(token.password)" class="absolute right-2 opacity-0 hover:opacity-100 transition-opacity bg-blue-200 hover:bg-blue-300 rounded px-2 py-1 text-base">📋</button>
|
| 155 |
</div>
|
| 156 |
+
<div class="relative flex items-center bg-blue-50/80 rounded-lg px-2 py-1.5">
|
| 157 |
<div class="overflow-x-auto scrollbar-hide flex-1 flex items-center space-x-2">
|
| 158 |
+
<span class="text-gray-700 min-w-[74px] text-left text-sm font-semibold">🔐 Token:</span>
|
| 159 |
<span class="font-medium whitespace-nowrap text-left text-sm">{{ token.token }}</span>
|
| 160 |
</div>
|
| 161 |
<button @click="copyToClipboard(token.token)" class="absolute right-2 opacity-0 hover:opacity-100 transition-opacity bg-blue-200 hover:bg-blue-300 rounded px-2 py-1 text-base">📋</button>
|
| 162 |
</div>
|
| 163 |
+
<div class="relative flex items-center bg-blue-50/80 rounded-lg px-2 py-1.5">
|
| 164 |
<div class="overflow-x-auto scrollbar-hide flex-1 flex items-center space-x-2">
|
| 165 |
+
<span class="text-gray-700 min-w-[74px] text-left text-sm font-semibold">⏰ Expire:</span>
|
| 166 |
+
<span class="font-medium whitespace-nowrap text-left text-sm">{{ new Date(token.expires * 1000).toLocaleString() }}</span>
|
| 167 |
</div>
|
| 168 |
<button @click="copyToClipboard(new Date(token.expires * 1000).toLocaleString())" class="absolute right-2 opacity-0 hover:opacity-100 transition-opacity bg-blue-200 hover:bg-blue-300 rounded px-2 py-1 text-base">📋</button>
|
| 169 |
</div>
|
| 170 |
</div>
|
| 171 |
|
| 172 |
+
<div class="pt-3 mt-auto border-t border-gray-200/50 grid grid-cols-2 gap-2">
|
| 173 |
<button @click="refreshToken(token.email)"
|
| 174 |
:disabled="refreshingTokens.includes(token.email)"
|
| 175 |
:class="[
|
| 176 |
+
'w-full py-2 rounded-lg transition-all duration-300 flex items-center justify-center space-x-2 text-sm',
|
| 177 |
refreshingTokens.includes(token.email)
|
| 178 |
? 'bg-green-400 text-white refreshing-button-green cursor-not-allowed'
|
| 179 |
: 'macaron-green-button text-green-600 hover:bg-green-100 border border-green-200'
|
|
|
|
| 188 |
<span v-else>刷新令牌</span>
|
| 189 |
</button>
|
| 190 |
<button @click="deleteToken(token.email)"
|
| 191 |
+
class="w-full group-hover:bg-red-50 text-red-600 py-2 rounded-lg transition-all duration-300 hover:bg-red-100 text-sm">
|
| 192 |
删除账号
|
| 193 |
</button>
|
| 194 |
</div>
|
| 195 |
</div>
|
| 196 |
</div>
|
| 197 |
</div>
|
| 198 |
+
</div>
|
| 199 |
+
</div>
|
| 200 |
+
|
| 201 |
+
<div v-else-if="activeDashboardTab === 'models'">
|
| 202 |
+
<div class="mb-6">
|
| 203 |
+
<h2 class="text-2xl font-bold text-slate-800">可用模型</h2>
|
| 204 |
+
<p class="mt-2 text-sm text-slate-500">查看当前实例全部模型,并按分类与强度筛选</p>
|
| 205 |
+
</div>
|
| 206 |
+
|
| 207 |
+
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 mb-4">
|
| 208 |
+
<div class="flex flex-wrap items-center gap-2 text-sm text-slate-600">
|
| 209 |
+
<span>共 {{ availableModels.length }} 个模型</span>
|
| 210 |
+
<button @click="setActiveModelFilter('all')" :class="['rounded-full px-3 py-1 text-xs font-semibold transition-all duration-300', activeModelFilter === 'all' ? 'bg-slate-800 text-white' : 'bg-slate-100 text-slate-600 hover:bg-slate-200']">全部 {{ availableModels.length }}</button>
|
| 211 |
+
<button @click="setActiveModelFilter('base')" :class="getFilterBadgeClass('base', 'bg-slate-100', 'text-slate-600', 'hover:bg-slate-200', 'bg-slate-700')">基础 {{ allModelGroups.base.length }}</button>
|
| 212 |
+
<button @click="setActiveModelFilter('thinking')" :class="getFilterBadgeClass('thinking', 'bg-amber-100', 'text-amber-700', 'hover:bg-amber-200', 'bg-amber-500')">Thinking {{ allModelGroups.thinking.length }}</button>
|
| 213 |
+
<button @click="setActiveModelFilter('search')" :class="getFilterBadgeClass('search', 'bg-cyan-100', 'text-cyan-700', 'hover:bg-cyan-200', 'bg-cyan-500')">Search {{ allModelGroups.search.length }}</button>
|
| 214 |
+
<button @click="setActiveModelFilter('image')" :class="getFilterBadgeClass('image', 'bg-rose-100', 'text-rose-700', 'hover:bg-rose-200', 'bg-rose-500')">Image {{ allModelGroups.image.length }}</button>
|
| 215 |
+
<button @click="setActiveModelFilter('video')" :class="getFilterBadgeClass('video', 'bg-indigo-100', 'text-indigo-700', 'hover:bg-indigo-200', 'bg-indigo-500')">Video {{ allModelGroups.video.length }}</button>
|
| 216 |
+
<button @click="setActiveModelFilter('imageEdit')" :class="getFilterBadgeClass('imageEdit', 'bg-emerald-100', 'text-emerald-700', 'hover:bg-emerald-200', 'bg-emerald-500')">Image Edit {{ allModelGroups.imageEdit.length }}</button>
|
| 217 |
+
</div>
|
| 218 |
+
<div class="flex w-full sm:w-auto gap-2">
|
| 219 |
+
<div class="relative w-full sm:w-72">
|
| 220 |
+
<input v-model="modelKeyword" type="text" placeholder="搜索模型 ID" class="w-full rounded-xl border border-slate-200 bg-white px-4 py-2 shadow-sm focus:border-violet-400 focus:ring-violet-400 transition-all duration-300">
|
| 221 |
+
</div>
|
| 222 |
+
<button @click="refreshModels" :disabled="isLoadingModels" :class="['rounded-xl px-4 py-2 text-sm font-semibold transition-all duration-300 border', isLoadingModels ? 'bg-violet-200 text-violet-600 border-violet-200 cursor-not-allowed' : 'bg-violet-600 text-white border-violet-600 hover:bg-violet-700']">{{ isLoadingModels ? '刷新中...' : '刷新模型列表' }}</button>
|
| 223 |
+
</div>
|
| 224 |
+
</div>
|
| 225 |
+
|
| 226 |
+
<div v-if="isLoadingModels" class="py-12 text-center text-slate-500">正在加载模型列表...</div>
|
| 227 |
+
<div v-else-if="modelsError" class="rounded-2xl border border-red-200 bg-red-50 px-4 py-8 text-center text-red-600">
|
| 228 |
+
<div class="text-lg font-semibold">模型列表加载失败</div>
|
| 229 |
+
<div class="mt-2 text-sm whitespace-pre-line">{{ modelsError }}</div>
|
| 230 |
+
<button @click="refreshModels" class="mt-4 rounded-xl bg-red-600 px-4 py-2 text-sm font-semibold text-white hover:bg-red-700 transition-all duration-300">重新加载</button>
|
| 231 |
+
</div>
|
| 232 |
+
<div v-else ref="modelsScrollContainer" class="max-h-[70vh] overflow-y-auto pr-2">
|
| 233 |
+
<div class="space-y-5">
|
| 234 |
+
<div v-for="group in groupedModelSections" :key="group.key" v-show="group.models.length" class="rounded-2xl border border-slate-200 bg-white/70 p-4 shadow-sm">
|
| 235 |
+
<div class="mb-3 flex items-center justify-between gap-3">
|
| 236 |
+
<div>
|
| 237 |
+
<h3 class="text-lg font-semibold text-slate-800">{{ group.title }}</h3>
|
| 238 |
+
<p class="text-xs text-slate-500 mt-1">{{ group.description }}</p>
|
| 239 |
+
<p class="mt-2 text-xs text-slate-400">当前分类已按模型强度从高到低排序</p>
|
| 240 |
+
</div>
|
| 241 |
+
<span :class="group.badgeClass" class="rounded-full px-3 py-1 text-xs font-semibold">{{ group.models.length }} 个</span>
|
| 242 |
+
</div>
|
| 243 |
+
<div class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-3">
|
| 244 |
+
<div v-for="model in group.models" :key="model.id" class="rounded-2xl border border-slate-200 bg-white/80 px-4 py-4 shadow-sm hover:shadow-md transition-all duration-300">
|
| 245 |
+
<div class="flex items-start justify-between gap-3">
|
| 246 |
+
<div class="min-w-0 flex-1">
|
| 247 |
+
<div class="font-semibold text-slate-800 break-all">{{ model.id }}</div>
|
| 248 |
+
<div class="mt-2 text-xs text-slate-500 break-all">模型名称:{{ getModelDisplayName(model) }}</div>
|
| 249 |
+
<div class="mt-2 flex flex-wrap gap-2">
|
| 250 |
+
<span class="rounded-full bg-slate-100 px-2 py-1 text-xs text-slate-600">{{ model.owned_by || 'unknown' }}</span>
|
| 251 |
+
<span v-if="modelTagSummary(model).length" class="rounded-full bg-violet-100 px-2 py-1 text-xs text-violet-700">{{ modelTagSummary(model).join(' / ') }}</span>
|
| 252 |
+
<span class="rounded-full bg-emerald-100 px-2 py-1 text-xs text-emerald-700">推荐:{{ getModelUseCase(model) }}</span>
|
| 253 |
+
<div class="relative group/tooltip inline-flex">
|
| 254 |
+
<span class="cursor-help rounded-full bg-amber-100 px-2 py-1 text-xs text-amber-700">强度:{{ getModelPriorityLabel(model, group.key) }}</span>
|
| 255 |
+
<div class="pointer-events-none absolute left-0 top-full z-20 mt-2 hidden w-64 rounded-2xl border border-amber-200 bg-white/95 p-3 text-xs text-slate-600 shadow-xl backdrop-blur-sm group-hover/tooltip:block">
|
| 256 |
+
<div class="font-semibold text-amber-700">强度说明</div>
|
| 257 |
+
<div class="mt-2 leading-5 whitespace-pre-line">{{ getModelPriorityTooltip(model, group.key) }}</div>
|
| 258 |
+
</div>
|
| 259 |
+
</div>
|
| 260 |
+
</div>
|
| 261 |
+
</div>
|
| 262 |
+
</div>
|
| 263 |
+
<div class="mt-4 grid grid-cols-2 gap-2 sm:grid-cols-3">
|
| 264 |
+
<button @click="copyToClipboard(model.id)" class="rounded-lg bg-violet-100 px-2 py-2 text-sm text-violet-700 hover:bg-violet-200 transition-all duration-300">复制 ID</button>
|
| 265 |
+
<button @click="copyToClipboard(getModelDisplayName(model))" class="rounded-lg bg-sky-100 px-2 py-2 text-sm text-sky-700 hover:bg-sky-200 transition-all duration-300">复制名字</button>
|
| 266 |
+
<button @click="copyModelRequestExample(model)" class="col-span-2 sm:col-span-1 rounded-lg bg-amber-100 px-2 py-2 text-sm text-amber-700 hover:bg-amber-200 transition-all duration-300">复制示例</button>
|
| 267 |
+
</div>
|
| 268 |
+
</div>
|
| 269 |
+
</div>
|
| 270 |
+
</div>
|
| 271 |
+
</div>
|
| 272 |
+
<div v-if="!filteredModelsByCategory.length" class="py-12 text-center text-slate-500">没有匹配的模型</div>
|
| 273 |
+
</div>
|
| 274 |
+
</div>
|
| 275 |
+
|
| 276 |
+
<div v-else-if="activeDashboardTab === 'logs'">
|
| 277 |
+
<div class="mb-6 flex flex-col gap-3 md:flex-row md:items-end md:justify-between">
|
| 278 |
+
<div>
|
| 279 |
+
<h2 class="text-2xl font-bold text-slate-800">运行日志</h2>
|
| 280 |
+
<p class="mt-2 text-sm text-slate-500">查看服务内存日志,支持手动刷新、自动刷新、复制、下载和清空</p>
|
| 281 |
+
</div>
|
| 282 |
+
<div class="flex flex-wrap items-center gap-2">
|
| 283 |
+
<button @click="fetchLogs" class="rounded-xl bg-slate-800 px-4 py-2 text-sm font-semibold text-white hover:bg-slate-900 transition-all duration-300">刷新日志</button>
|
| 284 |
+
<button @click="toggleAutoRefreshLogs" :class="['rounded-xl px-4 py-2 text-sm font-semibold transition-all duration-300', logsAutoRefresh ? 'bg-emerald-600 text-white hover:bg-emerald-700' : 'bg-emerald-100 text-emerald-700 hover:bg-emerald-200']">
|
| 285 |
+
{{ logsAutoRefresh ? '停止自动刷新' : '自动刷新' }}
|
| 286 |
+
</button>
|
| 287 |
+
<button @click="downloadLogs" class="rounded-xl bg-blue-100 px-4 py-2 text-sm font-semibold text-blue-700 hover:bg-blue-200 transition-all duration-300">下载日志</button>
|
| 288 |
+
<button @click="copyLogs" class="rounded-xl bg-violet-100 px-4 py-2 text-sm font-semibold text-violet-700 hover:bg-violet-200 transition-all duration-300">复制日志</button>
|
| 289 |
+
<button @click="clearLogs" class="rounded-xl bg-red-100 px-4 py-2 text-sm font-semibold text-red-700 hover:bg-red-200 transition-all duration-300">清空日志</button>
|
| 290 |
+
</div>
|
| 291 |
+
</div>
|
| 292 |
+
|
| 293 |
+
<div class="mb-4 grid gap-3 lg:grid-cols-[1fr_auto]">
|
| 294 |
+
<div class="flex flex-wrap items-center gap-3">
|
| 295 |
+
<select v-model="logsLevelFilter" class="rounded-xl border border-slate-200 bg-white px-4 py-2 text-sm text-slate-700 shadow-sm focus:border-slate-400 focus:ring-slate-400 transition-all duration-300">
|
| 296 |
+
<option value="ALL">全部级别</option>
|
| 297 |
+
<option value="DEBUG">DEBUG</option>
|
| 298 |
+
<option value="INFO">INFO</option>
|
| 299 |
+
<option value="WARN">WARN</option>
|
| 300 |
+
<option value="ERROR">ERROR</option>
|
| 301 |
+
</select>
|
| 302 |
+
<select v-model="logsModuleFilter" class="rounded-xl border border-slate-200 bg-white px-4 py-2 text-sm text-slate-700 shadow-sm focus:border-slate-400 focus:ring-slate-400 transition-all duration-300">
|
| 303 |
+
<option value="ALL">全部模块</option>
|
| 304 |
+
<option value="SERVER">SERVER</option>
|
| 305 |
+
<option value="ACCOUNT">ACCOUNT</option>
|
| 306 |
+
<option value="CHAT">CHAT</option>
|
| 307 |
+
<option value="CONFIG">CONFIG</option>
|
| 308 |
+
<option value="CLI">CLI</option>
|
| 309 |
+
<option value="SSXMOD">SSXMOD</option>
|
| 310 |
+
<option value="INFO">INFO</option>
|
| 311 |
+
</select>
|
| 312 |
+
<select v-model="logsLimit" class="rounded-xl border border-slate-200 bg-white px-4 py-2 text-sm text-slate-700 shadow-sm focus:border-slate-400 focus:ring-slate-400 transition-all duration-300">
|
| 313 |
+
<option value="100">最近 100 条</option>
|
| 314 |
+
<option value="200">最近 200 条</option>
|
| 315 |
+
<option value="500">最近 500 条</option>
|
| 316 |
+
<option value="ALL">全部</option>
|
| 317 |
+
</select>
|
| 318 |
+
<input v-model="logsKeyword" type="text" placeholder="搜索日志关键词" class="w-full max-w-md rounded-xl border border-slate-200 bg-white px-4 py-2 text-sm text-slate-700 shadow-sm focus:border-slate-400 focus:ring-slate-400 transition-all duration-300">
|
| 319 |
+
</div>
|
| 320 |
+
<div class="flex flex-wrap items-center gap-3">
|
| 321 |
+
<div class="inline-flex items-center gap-3 rounded-2xl border border-slate-200 bg-white px-4 py-2 text-sm text-slate-700 shadow-sm">
|
| 322 |
+
<span>运行日志</span>
|
| 323 |
+
<button @click="toggleRuntimeLog" :class="['rounded-full px-3 py-1 text-xs font-semibold transition-all duration-300', runtimeLogEnabled ? 'bg-emerald-600 text-white hover:bg-emerald-700' : 'bg-slate-200 text-slate-700 hover:bg-slate-300']">
|
| 324 |
+
{{ runtimeLogEnabled ? '已启用' : '已关闭' }}
|
| 325 |
+
</button>
|
| 326 |
+
</div>
|
| 327 |
+
<div class="inline-flex items-center gap-3 rounded-2xl border border-slate-200 bg-white px-4 py-2 text-sm text-slate-700 shadow-sm">
|
| 328 |
+
<span>自动滚底</span>
|
| 329 |
+
<button @click="logsAutoScroll = !logsAutoScroll" :class="['rounded-full px-3 py-1 text-xs font-semibold transition-all duration-300', logsAutoScroll ? 'bg-indigo-600 text-white hover:bg-indigo-700' : 'bg-slate-200 text-slate-700 hover:bg-slate-300']">
|
| 330 |
+
{{ logsAutoScroll ? '已开启' : '已关闭' }}
|
| 331 |
+
</button>
|
| 332 |
+
</div>
|
| 333 |
+
</div>
|
| 334 |
+
</div>
|
| 335 |
+
|
| 336 |
+
<div class="mb-4 flex flex-wrap items-center gap-3 text-sm text-slate-500">
|
| 337 |
+
<span>当前日志条数:{{ logs.length }}</span>
|
| 338 |
+
<span>筛选后:{{ filteredLogs.length }}</span>
|
| 339 |
+
<span v-if="logsLastUpdated">最后刷新:{{ logsLastUpdated }}</span>
|
| 340 |
+
</div>
|
| 341 |
+
|
| 342 |
+
<div class="rounded-3xl border border-slate-200 bg-slate-950 text-slate-100 shadow-inner overflow-hidden">
|
| 343 |
+
<div ref="logsScrollContainer" class="max-h-[70vh] overflow-y-auto p-4 font-mono text-xs leading-6 whitespace-pre-wrap break-words">
|
| 344 |
+
<div v-if="isLoadingLogs" class="text-slate-400">正在加载日志...</div>
|
| 345 |
+
<div v-else-if="logsError" class="text-red-300">{{ logsError }}</div>
|
| 346 |
+
<div v-else-if="!logs.length" class="text-slate-500">当前没有可显示的日志</div>
|
| 347 |
+
<div v-else>{{ formattedLogs }}</div>
|
| 348 |
+
</div>
|
| 349 |
+
</div>
|
| 350 |
+
</div>
|
| 351 |
+
|
| 352 |
+
<div v-else class="rounded-3xl border border-blue-100 bg-blue-50/80 p-6">
|
| 353 |
+
<h2 class="text-2xl font-bold text-slate-800">系统设置</h2>
|
| 354 |
+
<p class="mt-3 text-sm leading-6 text-slate-600">系统设置仍使用独立页面管理。这里保留左右布局入口,点击下面按钮即可进入原设置页。</p>
|
| 355 |
+
<div class="mt-5">
|
| 356 |
+
<button @click="goToSettings" class="rounded-2xl bg-blue-600 px-5 py-3 text-sm font-semibold text-white transition-all duration-300 hover:bg-blue-700">进入系统设置页</button>
|
| 357 |
+
</div>
|
| 358 |
+
</div>
|
| 359 |
+
</section>
|
| 360 |
</div>
|
| 361 |
</div>
|
| 362 |
|
|
|
|
| 455 |
</div>
|
| 456 |
</div>
|
| 457 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
</div>
|
| 459 |
</template>
|
| 460 |
|
| 461 |
<script setup>
|
| 462 |
import { ref, onMounted, computed } from 'vue'
|
| 463 |
import axios from 'axios'
|
| 464 |
+
import { useRouter } from 'vue-router'
|
| 465 |
+
|
| 466 |
+
const router = useRouter()
|
| 467 |
|
| 468 |
const tokens = ref([])
|
| 469 |
const showAddModal = ref(false)
|
|
|
|
| 491 |
const isRefreshingAll = ref(false)
|
| 492 |
const isForceRefreshingAll = ref(false)
|
| 493 |
const refreshingTokens = ref([])
|
| 494 |
+
const activeDashboardTab = ref('accounts')
|
| 495 |
const availableModels = ref([])
|
| 496 |
const isLoadingModels = ref(false)
|
| 497 |
const modelsError = ref('')
|
| 498 |
const modelKeyword = ref('')
|
| 499 |
const activeModelFilter = ref('all')
|
| 500 |
const modelsScrollContainer = ref(null)
|
| 501 |
+
const logs = ref([])
|
| 502 |
+
const isLoadingLogs = ref(false)
|
| 503 |
+
const logsError = ref('')
|
| 504 |
+
const logsAutoRefresh = ref(false)
|
| 505 |
+
const logsLastUpdated = ref('')
|
| 506 |
+
const logsLevelFilter = ref('ALL')
|
| 507 |
+
const logsModuleFilter = ref('ALL')
|
| 508 |
+
const logsKeyword = ref('')
|
| 509 |
+
const logsLimit = ref('200')
|
| 510 |
+
const runtimeLogEnabled = ref(true)
|
| 511 |
+
const logsAutoScroll = ref(true)
|
| 512 |
+
const logsScrollContainer = ref(null)
|
| 513 |
+
let logsRefreshTimer = null
|
| 514 |
|
| 515 |
// Toast 通知
|
| 516 |
const toast = ref({
|
|
|
|
| 519 |
type: 'success'
|
| 520 |
})
|
| 521 |
|
| 522 |
+
const filteredLogs = computed(() => {
|
| 523 |
+
const keyword = logsKeyword.value.trim().toLowerCase()
|
| 524 |
+
|
| 525 |
+
const matchedLogs = logs.value.filter(item => {
|
| 526 |
+
const text = item.text || ''
|
| 527 |
+
const upperText = text.toUpperCase()
|
| 528 |
+
const matchLevel = logsLevelFilter.value === 'ALL' || upperText.includes(`[${logsLevelFilter.value}]`)
|
| 529 |
+
const matchModule = logsModuleFilter.value === 'ALL' || upperText.includes(`[${logsModuleFilter.value}]`)
|
| 530 |
+
const matchKeyword = !keyword || text.toLowerCase().includes(keyword)
|
| 531 |
+
return matchLevel && matchModule && matchKeyword
|
| 532 |
+
})
|
| 533 |
+
|
| 534 |
+
if (logsLimit.value === 'ALL') {
|
| 535 |
+
return matchedLogs
|
| 536 |
+
}
|
| 537 |
+
|
| 538 |
+
const limit = parseInt(logsLimit.value, 10)
|
| 539 |
+
if (Number.isNaN(limit) || limit <= 0) {
|
| 540 |
+
return matchedLogs
|
| 541 |
+
}
|
| 542 |
+
|
| 543 |
+
return matchedLogs.slice(-limit)
|
| 544 |
+
})
|
| 545 |
+
|
| 546 |
+
const formattedLogs = computed(() => filteredLogs.value.map(item => item.text).join('\n'))
|
| 547 |
+
|
| 548 |
const filteredModels = computed(() => {
|
| 549 |
const keyword = modelKeyword.value.trim().toLowerCase()
|
| 550 |
if (!keyword) {
|
|
|
|
| 717 |
return model.id
|
| 718 |
}
|
| 719 |
|
| 720 |
+
const getSidebarItemClass = (tabKey, tone) => {
|
| 721 |
+
const activeMap = {
|
| 722 |
+
emerald: 'bg-emerald-600 text-white border-emerald-600 shadow-lg',
|
| 723 |
+
violet: 'bg-violet-600 text-white border-violet-600 shadow-lg',
|
| 724 |
+
blue: 'bg-blue-600 text-white border-blue-600 shadow-lg',
|
| 725 |
+
slate: 'bg-slate-700 text-white border-slate-700 shadow-lg'
|
| 726 |
+
}
|
| 727 |
+
|
| 728 |
+
const idleMap = {
|
| 729 |
+
emerald: 'bg-emerald-50 text-emerald-900 border-emerald-200 hover:bg-emerald-100',
|
| 730 |
+
violet: 'bg-violet-50 text-violet-900 border-violet-200 hover:bg-violet-100',
|
| 731 |
+
blue: 'bg-blue-50 text-blue-900 border-blue-200 hover:bg-blue-100',
|
| 732 |
+
slate: 'bg-slate-100 text-slate-800 border-slate-200 hover:bg-slate-200'
|
| 733 |
+
}
|
| 734 |
+
|
| 735 |
+
return [
|
| 736 |
+
'w-full rounded-2xl border px-4 py-3 text-left text-sm font-semibold transition-all duration-300',
|
| 737 |
+
activeDashboardTab.value === tabKey ? activeMap[tone] : idleMap[tone]
|
| 738 |
+
]
|
| 739 |
+
}
|
| 740 |
+
|
| 741 |
+
const getActionSidebarClass = (tone, disabled = false) => {
|
| 742 |
+
const toneMap = {
|
| 743 |
+
green: 'bg-green-50 text-green-900 border-green-200 hover:bg-green-100',
|
| 744 |
+
purple: 'bg-purple-50 text-purple-900 border-purple-200 hover:bg-purple-100',
|
| 745 |
+
pink: 'bg-pink-50 text-pink-900 border-pink-200 hover:bg-pink-100',
|
| 746 |
+
yellow: 'bg-yellow-50 text-yellow-900 border-yellow-200 hover:bg-yellow-100'
|
| 747 |
+
}
|
| 748 |
+
|
| 749 |
+
return [
|
| 750 |
+
'w-full rounded-2xl border px-4 py-3 text-left text-sm font-semibold transition-all duration-300',
|
| 751 |
+
disabled ? 'cursor-not-allowed bg-slate-200 text-slate-500 border-slate-200' : toneMap[tone]
|
| 752 |
+
]
|
| 753 |
+
}
|
| 754 |
+
|
| 755 |
+
const setDashboardTab = (tabKey) => {
|
| 756 |
+
activeDashboardTab.value = tabKey
|
| 757 |
+
}
|
| 758 |
+
|
| 759 |
+
const goToSettings = () => {
|
| 760 |
+
router.push('/settings')
|
| 761 |
+
}
|
| 762 |
+
|
| 763 |
+
const fetchLogs = async () => {
|
| 764 |
+
isLoadingLogs.value = true
|
| 765 |
+
logsError.value = ''
|
| 766 |
+
try {
|
| 767 |
+
const response = await axios.get('/api/logs', {
|
| 768 |
+
headers: {
|
| 769 |
+
'Authorization': localStorage.getItem('apiKey') || ''
|
| 770 |
+
}
|
| 771 |
+
})
|
| 772 |
+
logs.value = Array.isArray(response.data?.logs) ? response.data.logs : []
|
| 773 |
+
runtimeLogEnabled.value = response.data?.runtimeLogEnabled !== false
|
| 774 |
+
logsLastUpdated.value = new Date().toLocaleString()
|
| 775 |
+
|
| 776 |
+
if (logsAutoScroll.value) {
|
| 777 |
+
requestAnimationFrame(() => {
|
| 778 |
+
if (logsScrollContainer.value) {
|
| 779 |
+
logsScrollContainer.value.scrollTop = logsScrollContainer.value.scrollHeight
|
| 780 |
+
}
|
| 781 |
+
})
|
| 782 |
+
}
|
| 783 |
+
} catch (error) {
|
| 784 |
+
console.error('获取日志失败:', error)
|
| 785 |
+
logsError.value = error.response?.data?.error || error.message || '获取日志失败'
|
| 786 |
+
} finally {
|
| 787 |
+
isLoadingLogs.value = false
|
| 788 |
+
}
|
| 789 |
+
}
|
| 790 |
+
|
| 791 |
+
const stopLogsAutoRefresh = () => {
|
| 792 |
+
if (logsRefreshTimer) {
|
| 793 |
+
clearInterval(logsRefreshTimer)
|
| 794 |
+
logsRefreshTimer = null
|
| 795 |
+
}
|
| 796 |
+
logsAutoRefresh.value = false
|
| 797 |
+
}
|
| 798 |
+
|
| 799 |
+
const toggleAutoRefreshLogs = async () => {
|
| 800 |
+
if (logsAutoRefresh.value) {
|
| 801 |
+
stopLogsAutoRefresh()
|
| 802 |
+
showToast('已停止自动刷新日志')
|
| 803 |
+
return
|
| 804 |
+
}
|
| 805 |
+
|
| 806 |
+
await fetchLogs()
|
| 807 |
+
logsAutoRefresh.value = true
|
| 808 |
+
logsRefreshTimer = setInterval(fetchLogs, 5000)
|
| 809 |
+
showToast('已开启自动刷新日志')
|
| 810 |
+
}
|
| 811 |
+
|
| 812 |
+
const downloadLogs = () => {
|
| 813 |
+
const content = formattedLogs.value
|
| 814 |
+
const blob = new Blob([content], { type: 'text/plain;charset=utf-8' })
|
| 815 |
+
const url = URL.createObjectURL(blob)
|
| 816 |
+
const link = document.createElement('a')
|
| 817 |
+
link.href = url
|
| 818 |
+
link.download = `qwen2api-logs-${Date.now()}.txt`
|
| 819 |
+
document.body.appendChild(link)
|
| 820 |
+
link.click()
|
| 821 |
+
setTimeout(() => {
|
| 822 |
+
document.body.removeChild(link)
|
| 823 |
+
URL.revokeObjectURL(url)
|
| 824 |
+
}, 100)
|
| 825 |
+
showToast('日志已下载')
|
| 826 |
+
}
|
| 827 |
+
|
| 828 |
+
const copyLogs = async () => {
|
| 829 |
+
await copyToClipboard(formattedLogs.value || '当前没有日志')
|
| 830 |
+
}
|
| 831 |
+
|
| 832 |
+
const clearLogs = async () => {
|
| 833 |
+
try {
|
| 834 |
+
await axios.post('/api/logs/clear', {}, {
|
| 835 |
+
headers: {
|
| 836 |
+
'Authorization': localStorage.getItem('apiKey') || ''
|
| 837 |
+
}
|
| 838 |
+
})
|
| 839 |
+
logs.value = []
|
| 840 |
+
logsLastUpdated.value = new Date().toLocaleString()
|
| 841 |
+
showToast('日志已清空')
|
| 842 |
+
} catch (error) {
|
| 843 |
+
console.error('清空日志失败:', error)
|
| 844 |
+
showToast('清空日志失败: ' + (error.response?.data?.error || error.message), 'error')
|
| 845 |
+
}
|
| 846 |
+
}
|
| 847 |
+
|
| 848 |
+
const toggleRuntimeLog = async () => {
|
| 849 |
+
try {
|
| 850 |
+
const response = await axios.post('/api/logs/runtime-log', {
|
| 851 |
+
enabled: !runtimeLogEnabled.value
|
| 852 |
+
}, {
|
| 853 |
+
headers: {
|
| 854 |
+
'Authorization': localStorage.getItem('apiKey') || ''
|
| 855 |
+
}
|
| 856 |
+
})
|
| 857 |
+
|
| 858 |
+
runtimeLogEnabled.value = response.data?.runtimeLogEnabled !== false
|
| 859 |
+
showToast(response.data?.message || '运行日志开关已更新')
|
| 860 |
+
} catch (error) {
|
| 861 |
+
console.error('切换运行日志失败:', error)
|
| 862 |
+
showToast('切换运行日志失败: ' + (error.response?.data?.error || error.message), 'error')
|
| 863 |
+
}
|
| 864 |
+
}
|
| 865 |
+
|
| 866 |
+
const openLogsPanel = async () => {
|
| 867 |
+
activeDashboardTab.value = 'logs'
|
| 868 |
+
await fetchLogs()
|
| 869 |
+
}
|
| 870 |
+
|
| 871 |
const setActiveModelFilter = (filterKey) => {
|
| 872 |
activeModelFilter.value = filterKey
|
| 873 |
|
|
|
|
| 1354 |
}
|
| 1355 |
|
| 1356 |
const openModelsPanel = async () => {
|
| 1357 |
+
activeDashboardTab.value = 'models'
|
| 1358 |
modelKeyword.value = ''
|
| 1359 |
activeModelFilter.value = 'all'
|
| 1360 |
|
src/routes/settings.js
CHANGED
|
@@ -158,4 +158,67 @@ router.post('/simple-model-map', adminKeyVerify, async (req, res) => {
|
|
| 158 |
}
|
| 159 |
})
|
| 160 |
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
}
|
| 159 |
})
|
| 160 |
|
| 161 |
+
router.get('/logs', adminKeyVerify, async (req, res) => {
|
| 162 |
+
try {
|
| 163 |
+
res.json({
|
| 164 |
+
logs: logger.getMemoryLogs(),
|
| 165 |
+
fileLogEnabled: logger.isFileLogEnabled(),
|
| 166 |
+
runtimeLogEnabled: logger.isRuntimeLogEnabled()
|
| 167 |
+
})
|
| 168 |
+
} catch (error) {
|
| 169 |
+
logger.error('读取日志失败', 'CONFIG', '', error)
|
| 170 |
+
res.status(500).json({ error: error.message })
|
| 171 |
+
}
|
| 172 |
+
})
|
| 173 |
+
|
| 174 |
+
router.post('/logs/clear', adminKeyVerify, async (req, res) => {
|
| 175 |
+
try {
|
| 176 |
+
logger.clearMemoryLogs()
|
| 177 |
+
res.json({ message: '日志已清空' })
|
| 178 |
+
} catch (error) {
|
| 179 |
+
logger.error('清空日志失败', 'CONFIG', '', error)
|
| 180 |
+
res.status(500).json({ error: error.message })
|
| 181 |
+
}
|
| 182 |
+
})
|
| 183 |
+
|
| 184 |
+
router.post('/logs/file-log', adminKeyVerify, async (req, res) => {
|
| 185 |
+
try {
|
| 186 |
+
const { enabled } = req.body
|
| 187 |
+
|
| 188 |
+
if (typeof enabled !== 'boolean') {
|
| 189 |
+
return res.status(400).json({ error: 'enabled 必须是布尔值' })
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
logger.setFileLogEnabled(enabled)
|
| 193 |
+
|
| 194 |
+
res.json({
|
| 195 |
+
message: enabled ? '已启用文件日志' : '已关闭文件日志',
|
| 196 |
+
fileLogEnabled: logger.isFileLogEnabled()
|
| 197 |
+
})
|
| 198 |
+
} catch (error) {
|
| 199 |
+
logger.error('切换文件日志失败', 'CONFIG', '', error)
|
| 200 |
+
res.status(500).json({ error: error.message })
|
| 201 |
+
}
|
| 202 |
+
})
|
| 203 |
+
|
| 204 |
+
router.post('/logs/runtime-log', adminKeyVerify, async (req, res) => {
|
| 205 |
+
try {
|
| 206 |
+
const { enabled } = req.body
|
| 207 |
+
|
| 208 |
+
if (typeof enabled !== 'boolean') {
|
| 209 |
+
return res.status(400).json({ error: 'enabled 必须是布尔值' })
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
logger.setRuntimeLogEnabled(enabled)
|
| 213 |
+
|
| 214 |
+
res.json({
|
| 215 |
+
message: enabled ? '已启用运行日志' : '已关闭运行日志',
|
| 216 |
+
runtimeLogEnabled: logger.isRuntimeLogEnabled()
|
| 217 |
+
})
|
| 218 |
+
} catch (error) {
|
| 219 |
+
logger.error('切换运行日志失败', 'CONFIG', '', error)
|
| 220 |
+
res.status(500).json({ error: error.message })
|
| 221 |
+
}
|
| 222 |
+
})
|
| 223 |
+
|
| 224 |
+
module.exports = router
|
src/utils/logger.js
CHANGED
|
@@ -13,6 +13,8 @@ class Logger {
|
|
| 13 |
level: options.level || 'INFO',
|
| 14 |
// 是否启用文件日志
|
| 15 |
enableFileLog: options.enableFileLog || false,
|
|
|
|
|
|
|
| 16 |
// 日志文件路径
|
| 17 |
logDir: options.logDir || paths.logDir,
|
| 18 |
// 日志文件名格式
|
|
@@ -81,6 +83,9 @@ class Logger {
|
|
| 81 |
if (this.options.enableFileLog) {
|
| 82 |
this.initLogDirectory()
|
| 83 |
}
|
|
|
|
|
|
|
|
|
|
| 84 |
}
|
| 85 |
|
| 86 |
/**
|
|
@@ -102,7 +107,7 @@ class Logger {
|
|
| 102 |
* @returns {boolean}
|
| 103 |
*/
|
| 104 |
shouldLog(level) {
|
| 105 |
-
return this.levels[level] >= this.levels[this.options.level]
|
| 106 |
}
|
| 107 |
|
| 108 |
/**
|
|
@@ -176,6 +181,46 @@ class Logger {
|
|
| 176 |
}
|
| 177 |
}
|
| 178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
/**
|
| 180 |
* 日志文件轮转
|
| 181 |
* @param {string} logFile - 日志文件路径
|
|
@@ -257,6 +302,9 @@ class Logger {
|
|
| 257 |
|
| 258 |
// 文件输出
|
| 259 |
this.writeToFile(fileMessage + (data ? `\n${JSON.stringify(data, null, 2)}` : ''))
|
|
|
|
|
|
|
|
|
|
| 260 |
}
|
| 261 |
|
| 262 |
// 便捷方法
|
|
@@ -310,6 +358,7 @@ class Logger {
|
|
| 310 |
const defaultLogger = new Logger({
|
| 311 |
level: process.env.LOG_LEVEL || 'INFO',
|
| 312 |
enableFileLog: process.env.ENABLE_FILE_LOG === 'true',
|
|
|
|
| 313 |
showModule: true,
|
| 314 |
showTimestamp: true,
|
| 315 |
showLevel: true
|
|
|
|
| 13 |
level: options.level || 'INFO',
|
| 14 |
// 是否启用文件日志
|
| 15 |
enableFileLog: options.enableFileLog || false,
|
| 16 |
+
// 是否启用运行日志(控制台 + 内存日志)
|
| 17 |
+
enableRuntimeLog: options.enableRuntimeLog !== false,
|
| 18 |
// 日志文件路径
|
| 19 |
logDir: options.logDir || paths.logDir,
|
| 20 |
// 日志文件名格式
|
|
|
|
| 83 |
if (this.options.enableFileLog) {
|
| 84 |
this.initLogDirectory()
|
| 85 |
}
|
| 86 |
+
|
| 87 |
+
this.memoryLogs = []
|
| 88 |
+
this.maxMemoryLogs = options.maxMemoryLogs || 500
|
| 89 |
}
|
| 90 |
|
| 91 |
/**
|
|
|
|
| 107 |
* @returns {boolean}
|
| 108 |
*/
|
| 109 |
shouldLog(level) {
|
| 110 |
+
return this.options.enableRuntimeLog && this.levels[level] >= this.levels[this.options.level]
|
| 111 |
}
|
| 112 |
|
| 113 |
/**
|
|
|
|
| 181 |
}
|
| 182 |
}
|
| 183 |
|
| 184 |
+
pushMemoryLog(entry) {
|
| 185 |
+
this.memoryLogs.push({
|
| 186 |
+
id: Date.now() + Math.random(),
|
| 187 |
+
timestamp: new Date().toISOString(),
|
| 188 |
+
text: entry
|
| 189 |
+
})
|
| 190 |
+
|
| 191 |
+
if (this.memoryLogs.length > this.maxMemoryLogs) {
|
| 192 |
+
this.memoryLogs.splice(0, this.memoryLogs.length - this.maxMemoryLogs)
|
| 193 |
+
}
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
getMemoryLogs() {
|
| 197 |
+
return [...this.memoryLogs]
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
clearMemoryLogs() {
|
| 201 |
+
this.memoryLogs = []
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
setFileLogEnabled(enabled) {
|
| 205 |
+
this.options.enableFileLog = !!enabled
|
| 206 |
+
|
| 207 |
+
if (this.options.enableFileLog) {
|
| 208 |
+
this.initLogDirectory()
|
| 209 |
+
}
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
isFileLogEnabled() {
|
| 213 |
+
return !!this.options.enableFileLog
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
setRuntimeLogEnabled(enabled) {
|
| 217 |
+
this.options.enableRuntimeLog = !!enabled
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
isRuntimeLogEnabled() {
|
| 221 |
+
return !!this.options.enableRuntimeLog
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
/**
|
| 225 |
* 日志文件轮转
|
| 226 |
* @param {string} logFile - 日志文件路径
|
|
|
|
| 302 |
|
| 303 |
// 文件输出
|
| 304 |
this.writeToFile(fileMessage + (data ? `\n${JSON.stringify(data, null, 2)}` : ''))
|
| 305 |
+
|
| 306 |
+
// 内存缓冲,用于前端日志查看
|
| 307 |
+
this.pushMemoryLog(fileMessage + (data ? `\n${JSON.stringify(data, null, 2)}` : ''))
|
| 308 |
}
|
| 309 |
|
| 310 |
// 便捷方法
|
|
|
|
| 358 |
const defaultLogger = new Logger({
|
| 359 |
level: process.env.LOG_LEVEL || 'INFO',
|
| 360 |
enableFileLog: process.env.ENABLE_FILE_LOG === 'true',
|
| 361 |
+
enableRuntimeLog: process.env.ENABLE_RUNTIME_LOG !== 'false',
|
| 362 |
showModule: true,
|
| 363 |
showTimestamp: true,
|
| 364 |
showLevel: true
|