feat: 全新的Vue3管理后台(admin-spa)和路由重构

🎨 新增功能:
- 使用Vue3 + Vite构建的全新管理后台界面
- 支持Tab切换的API统计页面(统计查询/使用教程)
- 优雅的胶囊式Tab切换设计
- 同步了PR #106的会话窗口管理功能
- 完整的响应式设计和骨架屏加载状态

🔧 路由调整:
- 新版管理后台部署在 /admin-next/ 路径
- 将根路径 / 重定向到 /admin-next/api-stats
- 将 /web 页面路由重定向到新版,保留 /web/auth/* 认证路由
- 将 /apiStats 页面路由重定向到新版,保留API端点

🗑️ 清理工作:
- 删除旧版 web/admin/ 静态文件
- 删除旧版 web/apiStats/ 静态文件
- 清理相关的文件服务代码

🐛 修复问题:
- 修复重定向循环问题
- 修复环境变量配置
- 修复路由404错误
- 优化构建配置

🚀 生成方式:使用 Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
shaw
2025-07-29 12:40:51 +08:00
parent c98de2aca5
commit 414856f152
70 changed files with 18748 additions and 10314 deletions

View File

@@ -0,0 +1,193 @@
<template>
<Teleport to="body">
<Transition name="modal" appear>
<div
v-if="isVisible"
class="fixed inset-0 modal z-50 flex items-center justify-center p-4"
@click.self="handleCancel"
>
<div class="modal-content w-full max-w-md p-6 mx-auto">
<div class="flex items-start gap-4 mb-6">
<div class="flex-shrink-0 w-12 h-12 bg-gradient-to-br from-red-500 to-red-600 rounded-xl flex items-center justify-center">
<i class="fas fa-exclamation-triangle text-white text-lg"></i>
</div>
<div class="flex-1">
<h3 class="text-lg font-semibold text-gray-900 mb-2">{{ title }}</h3>
<div class="text-gray-600 leading-relaxed whitespace-pre-line">{{ message }}</div>
</div>
</div>
<div class="flex items-center justify-end gap-3">
<button
@click="handleCancel"
class="btn bg-gray-100 text-gray-700 hover:bg-gray-200 px-6 py-3"
:disabled="isProcessing"
>
{{ cancelText }}
</button>
<button
@click="handleConfirm"
class="btn btn-danger px-6 py-3"
:class="{ 'opacity-50 cursor-not-allowed': isProcessing }"
:disabled="isProcessing"
>
<div v-if="isProcessing" class="loading-spinner mr-2"></div>
{{ confirmText }}
</button>
</div>
</div>
</div>
</Transition>
</Teleport>
</template>
<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
// 状态
const isVisible = ref(false)
const isProcessing = ref(false)
const title = ref('')
const message = ref('')
const confirmText = ref('确认')
const cancelText = ref('取消')
let resolvePromise = null
// 显示确认对话框
const showConfirm = (titleText, messageText, confirmTextParam = '确认', cancelTextParam = '取消') => {
return new Promise((resolve) => {
title.value = titleText
message.value = messageText
confirmText.value = confirmTextParam
cancelText.value = cancelTextParam
isVisible.value = true
isProcessing.value = false
resolvePromise = resolve
})
}
// 处理确认
const handleConfirm = () => {
if (isProcessing.value) return
isProcessing.value = true
// 延迟一点时间以显示loading状态
setTimeout(() => {
isVisible.value = false
isProcessing.value = false
if (resolvePromise) {
resolvePromise(true)
resolvePromise = null
}
}, 200)
}
// 处理取消
const handleCancel = () => {
if (isProcessing.value) return
isVisible.value = false
if (resolvePromise) {
resolvePromise(false)
resolvePromise = null
}
}
// 键盘事件处理
const handleKeydown = (event) => {
if (!isVisible.value) return
if (event.key === 'Escape') {
handleCancel()
} else if (event.key === 'Enter' && !event.shiftKey && !event.ctrlKey && !event.altKey) {
handleConfirm()
}
}
// 全局方法注册
onMounted(() => {
window.showConfirm = showConfirm
document.addEventListener('keydown', handleKeydown)
})
onUnmounted(() => {
if (window.showConfirm === showConfirm) {
delete window.showConfirm
}
document.removeEventListener('keydown', handleKeydown)
})
// 暴露方法供组件使用
defineExpose({
showConfirm
})
</script>
<style scoped>
.modal {
background: rgba(0, 0, 0, 0.5);
backdrop-filter: blur(8px);
}
.modal-content {
background: white;
border-radius: 16px;
box-shadow: 0 20px 64px rgba(0, 0, 0, 0.15);
border: 1px solid #e5e7eb;
max-height: 90vh;
overflow-y: auto;
}
.btn {
@apply inline-flex items-center justify-center px-4 py-2 text-sm font-semibold rounded-lg transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2;
}
.btn-danger {
@apply bg-red-600 text-white hover:bg-red-700 focus:ring-red-500;
}
.loading-spinner {
@apply w-4 h-4 border-2 border-gray-300 border-t-white rounded-full animate-spin;
}
/* Modal transitions */
.modal-enter-active,
.modal-leave-active {
transition: all 0.3s ease;
}
.modal-enter-from,
.modal-leave-to {
opacity: 0;
}
.modal-enter-active .modal-content,
.modal-leave-active .modal-content {
transition: transform 0.3s ease;
}
.modal-enter-from .modal-content,
.modal-leave-to .modal-content {
transform: scale(0.9) translateY(-20px);
}
/* Scrollbar styling */
.modal-content::-webkit-scrollbar {
width: 6px;
}
.modal-content::-webkit-scrollbar-track {
background: #f1f5f9;
border-radius: 3px;
}
.modal-content::-webkit-scrollbar-thumb {
background: #cbd5e1;
border-radius: 3px;
}
.modal-content::-webkit-scrollbar-thumb:hover {
background: #94a3b8;
}
</style>

View File

@@ -0,0 +1,59 @@
<template>
<Teleport to="body">
<div v-if="show" class="fixed inset-0 modal z-50 flex items-center justify-center p-4">
<div class="modal-content w-full max-w-md p-6 mx-auto">
<div class="flex items-start gap-4 mb-6">
<div class="w-12 h-12 bg-gradient-to-br from-yellow-400 to-yellow-500 rounded-full flex items-center justify-center flex-shrink-0">
<i class="fas fa-exclamation text-white text-xl"></i>
</div>
<div class="flex-1">
<h3 class="text-lg font-bold text-gray-900 mb-2">{{ title }}</h3>
<p class="text-gray-600 text-sm leading-relaxed whitespace-pre-line">{{ message }}</p>
</div>
</div>
<div class="flex gap-3">
<button
@click="$emit('cancel')"
class="flex-1 px-4 py-2.5 bg-gray-100 text-gray-700 rounded-xl font-medium hover:bg-gray-200 transition-colors"
>
{{ cancelText }}
</button>
<button
@click="$emit('confirm')"
class="flex-1 px-4 py-2.5 bg-gradient-to-r from-yellow-500 to-orange-500 text-white rounded-xl font-medium hover:from-yellow-600 hover:to-orange-600 transition-colors shadow-sm"
>
{{ confirmText }}
</button>
</div>
</div>
</div>
</Teleport>
</template>
<script setup>
defineProps({
show: {
type: Boolean,
required: true
},
title: {
type: String,
default: ''
},
message: {
type: String,
default: ''
},
confirmText: {
type: String,
default: '继续'
},
cancelText: {
type: String,
default: '取消'
}
})
defineEmits(['confirm', 'cancel'])
</script>

View File

@@ -0,0 +1,81 @@
<template>
<div class="flex items-center gap-4">
<!-- Logo区域 -->
<div class="w-12 h-12 bg-gradient-to-br from-blue-500/20 to-purple-500/20 border border-gray-300/30 rounded-xl flex items-center justify-center backdrop-blur-sm flex-shrink-0 overflow-hidden">
<template v-if="!loading">
<img v-if="logoSrc"
:src="logoSrc"
alt="Logo"
class="w-8 h-8 object-contain"
@error="handleLogoError">
<i v-else class="fas fa-cloud text-xl text-gray-700"></i>
</template>
<div v-else class="w-8 h-8 bg-gray-300/50 rounded animate-pulse"></div>
</div>
<!-- 标题区域 -->
<div class="flex flex-col justify-center min-h-[48px]">
<div class="flex items-center gap-3">
<template v-if="!loading && title">
<h1 :class="['text-2xl font-bold header-title leading-tight', titleClass]">{{ title }}</h1>
</template>
<div v-else-if="loading" class="h-8 w-64 bg-gray-300/50 rounded animate-pulse"></div>
</div>
<p v-if="subtitle" class="text-gray-600 text-sm leading-tight mt-0.5">{{ subtitle }}</p>
</div>
</div>
</template>
<script setup>
defineProps({
loading: {
type: Boolean,
default: false
},
title: {
type: String,
default: ''
},
subtitle: {
type: String,
default: ''
},
logoSrc: {
type: String,
default: ''
},
titleClass: {
type: String,
default: 'text-gray-900'
}
})
// 处理图片加载错误
const handleLogoError = (e) => {
e.target.style.display = 'none'
}
</script>
<style scoped>
/* 骨架屏动画 */
@keyframes pulse {
0% {
opacity: 0.7;
}
50% {
opacity: 0.4;
}
100% {
opacity: 0.7;
}
}
.animate-pulse {
animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
/* 标题样式 */
.header-title {
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
</style>

View File

@@ -0,0 +1,56 @@
<template>
<div class="stat-card">
<div class="flex items-start justify-between">
<div class="flex-1">
<p class="text-sm font-medium text-gray-600 mb-1">{{ title }}</p>
<p class="text-3xl font-bold text-gray-800">{{ value }}</p>
<p v-if="subtitle" class="text-sm text-gray-500 mt-2">{{ subtitle }}</p>
</div>
<div :class="['stat-icon', iconBgClass]">
<i :class="icon"></i>
</div>
</div>
</div>
</template>
<script setup>
import { computed } from 'vue'
const props = defineProps({
title: {
type: String,
required: true
},
value: {
type: [String, Number],
required: true
},
subtitle: {
type: String,
default: ''
},
icon: {
type: String,
required: true
},
iconColor: {
type: String,
default: 'primary'
}
})
const iconBgClass = computed(() => {
const colorMap = {
primary: 'bg-gradient-to-br from-blue-500 to-purple-500',
success: 'bg-gradient-to-br from-green-500 to-emerald-500',
warning: 'bg-gradient-to-br from-yellow-500 to-orange-500',
danger: 'bg-gradient-to-br from-red-500 to-pink-500',
info: 'bg-gradient-to-br from-cyan-500 to-blue-500'
}
return colorMap[props.iconColor] || colorMap.primary
})
</script>
<style scoped>
/* 使用全局样式中定义的 .stat-card 和 .stat-icon 类 */
</style>

View File

@@ -0,0 +1,373 @@
<template>
<Teleport to="body">
<div class="toast-container">
<div
v-for="toast in toasts"
:key="toast.id"
:class="[
'toast',
`toast-${toast.type}`,
toast.isVisible ? 'toast-show' : 'toast-hide'
]"
@click="removeToast(toast.id)"
>
<div class="toast-content">
<div class="toast-icon">
<i :class="getIconClass(toast.type)"></i>
</div>
<div class="toast-body">
<div v-if="toast.title" class="toast-title">{{ toast.title }}</div>
<div class="toast-message">{{ toast.message }}</div>
</div>
<button
class="toast-close"
@click.stop="removeToast(toast.id)"
>
<i class="fas fa-times"></i>
</button>
</div>
<div
v-if="toast.duration > 0"
class="toast-progress"
:style="{ animationDuration: `${toast.duration}ms` }"
></div>
</div>
</div>
</Teleport>
</template>
<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
// 状态
const toasts = ref([])
let toastIdCounter = 0
// 获取图标类名
const getIconClass = (type) => {
const iconMap = {
success: 'fas fa-check-circle',
error: 'fas fa-exclamation-circle',
warning: 'fas fa-exclamation-triangle',
info: 'fas fa-info-circle'
}
return iconMap[type] || iconMap.info
}
// 添加Toast
const addToast = (message, type = 'info', title = null, duration = 5000) => {
const id = ++toastIdCounter
const toast = {
id,
message,
type,
title,
duration,
isVisible: false
}
toasts.value.push(toast)
// 下一帧显示动画
setTimeout(() => {
toast.isVisible = true
}, 10)
// 自动移除
if (duration > 0) {
setTimeout(() => {
removeToast(id)
}, duration)
}
return id
}
// 移除Toast
const removeToast = (id) => {
const index = toasts.value.findIndex(toast => toast.id === id)
if (index > -1) {
const toast = toasts.value[index]
toast.isVisible = false
// 等待动画完成后移除
setTimeout(() => {
const currentIndex = toasts.value.findIndex(t => t.id === id)
if (currentIndex > -1) {
toasts.value.splice(currentIndex, 1)
}
}, 300)
}
}
// 清除所有Toast
const clearAllToasts = () => {
toasts.value.forEach(toast => {
toast.isVisible = false
})
setTimeout(() => {
toasts.value.length = 0
}, 300)
}
// 暴露方法给全局使用
const showToast = (message, type = 'info', title = null, duration = 5000) => {
return addToast(message, type, title, duration)
}
// 全局方法注册
onMounted(() => {
// 将方法挂载到全局
window.showToast = showToast
})
onUnmounted(() => {
// 清理全局方法
if (window.showToast === showToast) {
delete window.showToast
}
})
// 暴露方法供组件使用
defineExpose({
showToast,
removeToast,
clearAllToasts
})
</script>
<style scoped>
.toast-container {
position: fixed;
top: 20px;
right: 20px;
z-index: 9999;
display: flex;
flex-direction: column;
gap: 12px;
pointer-events: none;
}
.toast {
min-width: 320px;
max-width: 500px;
background: white;
border-radius: 12px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
border: 1px solid #e5e7eb;
overflow: hidden;
position: relative;
pointer-events: auto;
cursor: pointer;
transform: translateX(100%);
opacity: 0;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.toast-show {
transform: translateX(0);
opacity: 1;
}
.toast-hide {
transform: translateX(100%);
opacity: 0;
}
.toast-content {
display: flex;
align-items: flex-start;
padding: 16px;
gap: 12px;
}
.toast-icon {
flex-shrink: 0;
width: 24px;
height: 24px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
font-size: 14px;
}
.toast-body {
flex: 1;
}
.toast-title {
font-weight: 600;
font-size: 14px;
line-height: 1.4;
margin-bottom: 4px;
}
.toast-message {
font-size: 14px;
line-height: 1.5;
word-wrap: break-word;
}
.toast-close {
flex-shrink: 0;
width: 24px;
height: 24px;
border: none;
background: none;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
border-radius: 4px;
color: #9ca3af;
transition: all 0.2s ease;
}
.toast-close:hover {
background: #f3f4f6;
color: #6b7280;
}
.toast-progress {
position: absolute;
bottom: 0;
left: 0;
height: 3px;
background: currentColor;
opacity: 0.3;
animation: toast-progress linear forwards;
}
@keyframes toast-progress {
from {
width: 100%;
}
to {
width: 0%;
}
}
/* Success Toast */
.toast-success {
border-left: 4px solid #10b981;
}
.toast-success .toast-icon {
color: #10b981;
background: #d1fae5;
}
.toast-success .toast-title {
color: #065f46;
}
.toast-success .toast-message {
color: #047857;
}
.toast-success .toast-progress {
background: #10b981;
}
/* Error Toast */
.toast-error {
border-left: 4px solid #ef4444;
}
.toast-error .toast-icon {
color: #ef4444;
background: #fee2e2;
}
.toast-error .toast-title {
color: #991b1b;
}
.toast-error .toast-message {
color: #dc2626;
}
.toast-error .toast-progress {
background: #ef4444;
}
/* Warning Toast */
.toast-warning {
border-left: 4px solid #f59e0b;
}
.toast-warning .toast-icon {
color: #f59e0b;
background: #fef3c7;
}
.toast-warning .toast-title {
color: #92400e;
}
.toast-warning .toast-message {
color: #d97706;
}
.toast-warning .toast-progress {
background: #f59e0b;
}
/* Info Toast */
.toast-info {
border-left: 4px solid #3b82f6;
}
.toast-info .toast-icon {
color: #3b82f6;
background: #dbeafe;
}
.toast-info .toast-title {
color: #1e40af;
}
.toast-info .toast-message {
color: #2563eb;
}
.toast-info .toast-progress {
background: #3b82f6;
}
/* Responsive */
@media (max-width: 640px) {
.toast-container {
top: 10px;
right: 10px;
left: 10px;
}
.toast {
min-width: auto;
max-width: none;
}
}
/* Toast List Transitions */
.toast-list-enter-active,
.toast-list-leave-active {
transition: all 0.3s ease;
}
.toast-list-enter-from {
opacity: 0;
transform: translateX(100%);
}
.toast-list-leave-to {
opacity: 0;
transform: translateX(100%);
}
.toast-list-move {
transition: transform 0.3s ease;
}
</style>