feat: 秘钥管理 web v1
This commit is contained in:
231
web/src/components/GlobalTaskProgressBar.vue
Normal file
231
web/src/components/GlobalTaskProgressBar.vue
Normal file
@@ -0,0 +1,231 @@
|
||||
<script setup lang="ts">
|
||||
import { keysApi } from "@/api/keys";
|
||||
import type { TaskInfo } from "@/types/models";
|
||||
import { onBeforeUnmount, onMounted, ref } from "vue";
|
||||
|
||||
const taskInfo = ref<TaskInfo>({ is_running: false });
|
||||
const visible = ref(false);
|
||||
let pollTimer: number | null = null;
|
||||
|
||||
onMounted(() => {
|
||||
startPolling();
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
stopPolling();
|
||||
});
|
||||
|
||||
function startPolling() {
|
||||
stopPolling();
|
||||
pollTimer = setInterval(async () => {
|
||||
try {
|
||||
const task = await keysApi.getTaskStatus();
|
||||
taskInfo.value = task;
|
||||
visible.value = task.is_running;
|
||||
} catch (error) {
|
||||
console.error("获取任务状态失败:", error);
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function stopPolling() {
|
||||
if (pollTimer) {
|
||||
clearInterval(pollTimer);
|
||||
pollTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
function getProgressPercentage(): number {
|
||||
if (!taskInfo.value.total || taskInfo.value.total === 0) {
|
||||
return 0;
|
||||
}
|
||||
return Math.round(((taskInfo.value.processed || 0) / taskInfo.value.total) * 100);
|
||||
}
|
||||
|
||||
function getProgressText(): string {
|
||||
const { processed = 0, total = 0 } = taskInfo.value;
|
||||
return `${processed}/${total}`;
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
visible.value = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="global-task-progress">
|
||||
<div class="progress-container">
|
||||
<div class="progress-header">
|
||||
<div class="progress-info">
|
||||
<span class="progress-icon">⚡</span>
|
||||
<div class="progress-details">
|
||||
<div class="progress-title">{{ taskInfo.task_name || "正在处理任务" }}</div>
|
||||
<div class="progress-subtitle">
|
||||
{{ getProgressText() }} ({{ getProgressPercentage() }}%)
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button @click="handleClose" class="close-btn" title="隐藏进度条">✕</button>
|
||||
</div>
|
||||
|
||||
<div class="progress-bar-container">
|
||||
<div class="progress-bar" :style="{ width: `${getProgressPercentage()}%` }" />
|
||||
</div>
|
||||
|
||||
<div v-if="taskInfo.message" class="progress-message">
|
||||
{{ taskInfo.message }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.global-task-progress {
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
right: 20px;
|
||||
z-index: 9999;
|
||||
width: 360px;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
|
||||
border: 1px solid #e1e5e9;
|
||||
animation: slideIn 0.3s ease-out;
|
||||
}
|
||||
|
||||
@keyframes slideIn {
|
||||
from {
|
||||
transform: translateX(100%);
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
transform: translateX(0);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.progress-container {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.progress-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.progress-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.progress-icon {
|
||||
font-size: 20px;
|
||||
animation: pulse 1.5s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%,
|
||||
100% {
|
||||
transform: scale(1);
|
||||
}
|
||||
50% {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
}
|
||||
|
||||
.progress-details {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.progress-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.progress-subtitle {
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border: none;
|
||||
background: none;
|
||||
cursor: pointer;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #999;
|
||||
font-size: 14px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.close-btn:hover {
|
||||
background: #f5f5f5;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.progress-bar-container {
|
||||
width: 100%;
|
||||
height: 6px;
|
||||
background: #f0f0f0;
|
||||
border-radius: 3px;
|
||||
overflow: hidden;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, #4ade80, #22c55e);
|
||||
border-radius: 3px;
|
||||
transition: width 0.3s ease;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.progress-bar::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
|
||||
animation: shimmer 2s infinite;
|
||||
}
|
||||
|
||||
@keyframes shimmer {
|
||||
0% {
|
||||
transform: translateX(-100%);
|
||||
}
|
||||
100% {
|
||||
transform: translateX(100%);
|
||||
}
|
||||
}
|
||||
|
||||
.progress-message {
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
text-align: center;
|
||||
padding: 8px;
|
||||
background: #f8f9fa;
|
||||
border-radius: 4px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.global-task-progress {
|
||||
left: 20px;
|
||||
right: 20px;
|
||||
width: auto;
|
||||
top: 10px;
|
||||
}
|
||||
}
|
||||
</style>
|
501
web/src/components/keys/GroupInfoCard.vue
Normal file
501
web/src/components/keys/GroupInfoCard.vue
Normal file
@@ -0,0 +1,501 @@
|
||||
<script setup lang="ts">
|
||||
import { keysApi } from "@/api/keys";
|
||||
import type { Group, GroupStats } from "@/types/models";
|
||||
import { onMounted, ref } from "vue";
|
||||
|
||||
interface Props {
|
||||
group: Group;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
const stats = ref<GroupStats | null>(null);
|
||||
const loading = ref(false);
|
||||
const showDetails = ref(false);
|
||||
|
||||
onMounted(() => {
|
||||
loadStats();
|
||||
});
|
||||
|
||||
async function loadStats() {
|
||||
try {
|
||||
loading.value = true;
|
||||
stats.value = await keysApi.getGroupStats(props.group.id);
|
||||
} catch (error) {
|
||||
console.error("加载统计信息失败:", error);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleEdit() {
|
||||
window.$message.info("编辑分组功能开发中...");
|
||||
}
|
||||
|
||||
function handleDelete() {
|
||||
window.$message.info("删除分组功能开发中...");
|
||||
}
|
||||
|
||||
function toggleDetails() {
|
||||
showDetails.value = !showDetails.value;
|
||||
}
|
||||
|
||||
function formatNumber(num: number): string {
|
||||
if (num >= 1000000) {
|
||||
return `${(num / 1000000).toFixed(1)}M`;
|
||||
}
|
||||
if (num >= 1000) {
|
||||
return `${(num / 1000).toFixed(1)}K`;
|
||||
}
|
||||
return num.toString();
|
||||
}
|
||||
|
||||
function formatPercentage(num: number): string {
|
||||
return `${num.toFixed(1)}%`;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="group-info-container">
|
||||
<div class="group-info-card">
|
||||
<!-- 头部信息 -->
|
||||
<div class="card-header">
|
||||
<div class="header-left">
|
||||
<h3 class="group-title">{{ group.display_name || group.name }}</h3>
|
||||
<div class="group-meta">
|
||||
<span class="channel-badge" :class="`channel-${group.channel_type}`">
|
||||
{{ group.channel_type.toUpperCase() }}
|
||||
</span>
|
||||
<span class="group-id">#{{ group.id }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="header-actions">
|
||||
<button class="action-btn" @click="handleEdit" title="编辑分组">
|
||||
<span class="icon">✏️</span>
|
||||
</button>
|
||||
<button class="action-btn delete-btn" @click="handleDelete" title="删除分组">
|
||||
<span class="icon">🗑️</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 统计摘要区 -->
|
||||
<div class="stats-summary">
|
||||
<div v-if="loading" class="loading-stats">
|
||||
<div class="loading-placeholder" />
|
||||
<div class="loading-placeholder" />
|
||||
<div class="loading-placeholder" />
|
||||
<div class="loading-placeholder" />
|
||||
</div>
|
||||
<div v-else-if="stats" class="stats-grid">
|
||||
<div class="stat-item">
|
||||
<div class="stat-value">{{ stats.active_keys }}/{{ stats.total_keys }}</div>
|
||||
<div class="stat-label">密钥数量</div>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<div class="stat-value">{{ formatNumber(stats.requests_1h) }}</div>
|
||||
<div class="stat-label">近1小时</div>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<div class="stat-value">{{ formatNumber(stats.requests_24h) }}</div>
|
||||
<div class="stat-label">近24小时</div>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<div class="stat-value failure-rate">
|
||||
{{ formatPercentage(stats.failure_rate_24h) }}
|
||||
</div>
|
||||
<div class="stat-label">失败率</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 详细信息区(可折叠) -->
|
||||
<div class="details-section">
|
||||
<button class="toggle-btn" @click="toggleDetails">
|
||||
<span class="toggle-text">{{ showDetails ? "收起" : "展开" }}详细信息</span>
|
||||
<span class="toggle-icon" :class="{ expanded: showDetails }">▼</span>
|
||||
</button>
|
||||
|
||||
<div v-if="showDetails" class="details-content">
|
||||
<div class="detail-section">
|
||||
<h4 class="section-title">基础信息</h4>
|
||||
<div class="detail-grid">
|
||||
<div class="detail-item">
|
||||
<span class="detail-label">分组名称:</span>
|
||||
<span class="detail-value">{{ group.name }}</span>
|
||||
</div>
|
||||
<div class="detail-item">
|
||||
<span class="detail-label">渠道类型:</span>
|
||||
<span class="detail-value">{{ group.channel_type }}</span>
|
||||
</div>
|
||||
<div class="detail-item">
|
||||
<span class="detail-label">排序:</span>
|
||||
<span class="detail-value">{{ group.sort }}</span>
|
||||
</div>
|
||||
<div v-if="group.description" class="detail-item full-width">
|
||||
<span class="detail-label">描述:</span>
|
||||
<span class="detail-value">{{ group.description }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="detail-section">
|
||||
<h4 class="section-title">上游地址</h4>
|
||||
<div class="upstream-list">
|
||||
<div v-for="(upstream, index) in group.upstreams" :key="index" class="upstream-item">
|
||||
<span class="upstream-url">{{ upstream.url }}</span>
|
||||
<span class="upstream-weight">权重: {{ upstream.weight }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="detail-section">
|
||||
<h4 class="section-title">配置信息</h4>
|
||||
<div class="config-content">
|
||||
<div v-if="group.config.test_model" class="config-item">
|
||||
<span class="config-label">测试模型:</span>
|
||||
<span class="config-value">{{ group.config.test_model }}</span>
|
||||
</div>
|
||||
<div v-if="group.config.request_timeout" class="config-item">
|
||||
<span class="config-label">请求超时:</span>
|
||||
<span class="config-value">{{ group.config.request_timeout }}ms</span>
|
||||
</div>
|
||||
<div
|
||||
v-if="Object.keys(group.config.param_overrides || {}).length > 0"
|
||||
class="config-item"
|
||||
>
|
||||
<span class="config-label">参数覆盖:</span>
|
||||
<pre class="config-json">{{
|
||||
JSON.stringify(group.config.param_overrides, null, 2)
|
||||
}}</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.group-info-container {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.group-info-card {
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 12px 16px;
|
||||
border-bottom: 1px solid #e9ecef;
|
||||
}
|
||||
|
||||
.header-left {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.group-title {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin: 0 0 4px 0;
|
||||
}
|
||||
|
||||
.group-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.channel-badge {
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
padding: 2px 6px;
|
||||
border-radius: 3px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.channel-openai {
|
||||
background: rgba(16, 163, 127, 0.1);
|
||||
color: #10a37f;
|
||||
}
|
||||
|
||||
.channel-gemini {
|
||||
background: rgba(66, 133, 244, 0.1);
|
||||
color: #4285f4;
|
||||
}
|
||||
|
||||
.channel-silicon {
|
||||
background: rgba(147, 51, 234, 0.1);
|
||||
color: #9333ea;
|
||||
}
|
||||
|
||||
.channel-chutes {
|
||||
background: rgba(239, 68, 68, 0.1);
|
||||
color: #ef4444;
|
||||
}
|
||||
|
||||
.group-id {
|
||||
font-size: 12px;
|
||||
color: #6c757d;
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
padding: 4px 6px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.action-btn:hover {
|
||||
background: rgba(0, 123, 255, 0.1);
|
||||
}
|
||||
|
||||
.action-btn.delete-btn:hover {
|
||||
background: rgba(239, 68, 68, 0.1);
|
||||
}
|
||||
|
||||
.action-btn .icon {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.stats-summary {
|
||||
padding: 12px 16px;
|
||||
background: #f8f9fa;
|
||||
border-bottom: 1px solid #e9ecef;
|
||||
}
|
||||
|
||||
.loading-stats {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.loading-placeholder {
|
||||
height: 40px;
|
||||
flex: 1;
|
||||
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
|
||||
background-size: 200% 100%;
|
||||
animation: loading 1.5s infinite;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
@keyframes loading {
|
||||
0% {
|
||||
background-position: 200% 0;
|
||||
}
|
||||
100% {
|
||||
background-position: -200% 0;
|
||||
}
|
||||
}
|
||||
|
||||
.stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
text-align: center;
|
||||
padding: 8px;
|
||||
background: white;
|
||||
border-radius: 4px;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
color: #333;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.stat-value.failure-rate {
|
||||
color: #dc3545;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 10px;
|
||||
color: #6c757d;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.details-section {
|
||||
border-top: 1px solid #e9ecef;
|
||||
}
|
||||
|
||||
.toggle-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
padding: 8px 16px;
|
||||
border: none;
|
||||
background: #f8f9fa;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.toggle-btn:hover {
|
||||
background: #e9ecef;
|
||||
}
|
||||
|
||||
.toggle-text {
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
color: #495057;
|
||||
}
|
||||
|
||||
.toggle-icon {
|
||||
font-size: 10px;
|
||||
color: #6c757d;
|
||||
transition: transform 0.2s;
|
||||
}
|
||||
|
||||
.toggle-icon.expanded {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
.details-content {
|
||||
padding: 12px 16px;
|
||||
background: white;
|
||||
}
|
||||
|
||||
.detail-section {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.detail-section:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.detail-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.detail-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.detail-item.full-width {
|
||||
grid-column: 1 / -1;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.detail-label {
|
||||
font-weight: 500;
|
||||
color: #6c757d;
|
||||
}
|
||||
|
||||
.detail-value {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.upstream-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.upstream-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 6px 8px;
|
||||
background: #f8f9fa;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.upstream-url {
|
||||
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.upstream-weight {
|
||||
color: #6c757d;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.config-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.config-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.config-label {
|
||||
font-weight: 500;
|
||||
color: #6c757d;
|
||||
}
|
||||
|
||||
.config-value {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.config-json {
|
||||
background: #f8f9fa;
|
||||
border: 1px solid #e9ecef;
|
||||
border-radius: 4px;
|
||||
padding: 8px;
|
||||
font-size: 10px;
|
||||
color: #495057;
|
||||
overflow-x: auto;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.stats-grid {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.detail-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.upstream-item {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
}
|
||||
}
|
||||
</style>
|
320
web/src/components/keys/GroupList.vue
Normal file
320
web/src/components/keys/GroupList.vue
Normal file
@@ -0,0 +1,320 @@
|
||||
<script setup lang="ts">
|
||||
import { keysApi } from "@/api/keys";
|
||||
import type { Group } from "@/types/models";
|
||||
import { useMessage } from "naive-ui";
|
||||
import { computed, ref } from "vue";
|
||||
|
||||
interface Props {
|
||||
groups: Group[];
|
||||
selectedGroup: Group | null;
|
||||
loading?: boolean;
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: "group-select", group: Group): void;
|
||||
(e: "refresh"): void;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
loading: false,
|
||||
});
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
const searchText = ref("");
|
||||
const message = useMessage();
|
||||
|
||||
// 过滤后的分组列表
|
||||
const filteredGroups = computed(() => {
|
||||
if (!searchText.value) {
|
||||
return props.groups;
|
||||
}
|
||||
const search = searchText.value.toLowerCase();
|
||||
return props.groups.filter(
|
||||
group =>
|
||||
group.name.toLowerCase().includes(search) ||
|
||||
(group.display_name && group.display_name.toLowerCase().includes(search))
|
||||
);
|
||||
});
|
||||
|
||||
function handleGroupClick(group: Group) {
|
||||
emit("group-select", group);
|
||||
}
|
||||
|
||||
// 简单的创建分组功能(演示用)
|
||||
async function createDemoGroup() {
|
||||
try {
|
||||
const newGroup = await keysApi.createGroup({
|
||||
name: `demo-group-${Date.now()}`,
|
||||
display_name: `演示分组 ${props.groups.length + 1}`,
|
||||
description: "这是一个演示分组",
|
||||
sort: props.groups.length + 1,
|
||||
channel_type: "openai",
|
||||
upstreams: [{ url: "https://api.openai.com", weight: 1 }],
|
||||
config: {
|
||||
test_model: "gpt-3.5-turbo",
|
||||
param_overrides: {},
|
||||
request_timeout: 30000,
|
||||
},
|
||||
});
|
||||
|
||||
message.success(`创建分组成功: ${newGroup.display_name}`);
|
||||
emit("refresh");
|
||||
} catch (error) {
|
||||
console.error("创建分组失败:", error);
|
||||
message.error("创建分组失败");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="group-list-container">
|
||||
<div class="group-list-card">
|
||||
<!-- 搜索框 -->
|
||||
<div class="search-section">
|
||||
<input v-model="searchText" placeholder="搜索分组名称..." class="search-input" />
|
||||
</div>
|
||||
|
||||
<!-- 分组列表 -->
|
||||
<div class="groups-section">
|
||||
<div v-if="loading" class="loading-state">加载中...</div>
|
||||
<div v-else-if="filteredGroups.length === 0" class="empty-state">
|
||||
<div class="empty-text">
|
||||
{{ searchText ? "未找到匹配的分组" : "暂无分组" }}
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="groups-list">
|
||||
<div
|
||||
v-for="group in filteredGroups"
|
||||
:key="group.id"
|
||||
class="group-item"
|
||||
:class="{ active: selectedGroup?.id === group.id }"
|
||||
@click="handleGroupClick(group)"
|
||||
>
|
||||
<div class="group-icon">
|
||||
<span v-if="group.channel_type === 'openai'">🤖</span>
|
||||
<span v-else-if="group.channel_type === 'gemini'">💎</span>
|
||||
<span v-else-if="group.channel_type === 'silicon'">⚡</span>
|
||||
<span v-else>🔧</span>
|
||||
</div>
|
||||
<div class="group-content">
|
||||
<div class="group-name">
|
||||
{{ group.display_name || group.name }}
|
||||
</div>
|
||||
<div class="group-info">
|
||||
<span class="channel-type">{{ group.channel_type }}</span>
|
||||
<span class="group-id">#{{ group.id }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 添加分组按钮 -->
|
||||
<div class="add-section">
|
||||
<button class="add-button" @click="createDemoGroup">
|
||||
<span class="add-icon">+</span>
|
||||
添加分组
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.group-list-container {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.group-list-card {
|
||||
height: 100%;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
padding: 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.search-section {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
width: 100%;
|
||||
padding: 6px 8px;
|
||||
border: 1px solid #e9ecef;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.search-input:focus {
|
||||
outline: none;
|
||||
border-color: #007bff;
|
||||
box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
|
||||
}
|
||||
|
||||
.groups-section {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.loading-state {
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
color: #6c757d;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
color: #6c757d;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.groups-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
max-height: 100%;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.group-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
border: 1px solid transparent;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.group-item:hover {
|
||||
background: #f8f9fa;
|
||||
border-color: #e9ecef;
|
||||
}
|
||||
|
||||
.group-item.active {
|
||||
background: #007bff;
|
||||
color: white;
|
||||
border-color: #007bff;
|
||||
}
|
||||
|
||||
.group-icon {
|
||||
font-size: 14px;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(0, 0, 0, 0.1);
|
||||
border-radius: 4px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.group-item.active .group-icon {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
|
||||
.group-content {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.group-name {
|
||||
font-weight: 600;
|
||||
font-size: 12px;
|
||||
line-height: 1.2;
|
||||
margin-bottom: 2px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.group-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
font-size: 10px;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.channel-type {
|
||||
text-transform: uppercase;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.group-id {
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.add-section {
|
||||
border-top: 1px solid #e9ecef;
|
||||
padding-top: 12px;
|
||||
}
|
||||
|
||||
.add-button {
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
border: 1px solid #007bff;
|
||||
background: #007bff;
|
||||
color: white;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
transition: background-color 0.2s;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.add-button:hover {
|
||||
background: #0056b3;
|
||||
}
|
||||
|
||||
.add-icon {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
/* 滚动条样式 */
|
||||
.groups-list::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
}
|
||||
|
||||
.groups-list::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.groups-list::-webkit-scrollbar-thumb {
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.groups-list::-webkit-scrollbar-thumb:hover {
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.group-item {
|
||||
padding: 6px;
|
||||
}
|
||||
|
||||
.group-name {
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.group-info {
|
||||
font-size: 9px;
|
||||
}
|
||||
}
|
||||
</style>
|
848
web/src/components/keys/KeyTable.vue
Normal file
848
web/src/components/keys/KeyTable.vue
Normal file
@@ -0,0 +1,848 @@
|
||||
<script setup lang="ts">
|
||||
import { keysApi } from "@/api/keys";
|
||||
import type { APIKey, Group } from "@/types/models";
|
||||
import { computed, ref, watch } from "vue";
|
||||
|
||||
interface Props {
|
||||
selectedGroup: Group | null;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
const keys = ref<APIKey[]>([]);
|
||||
const loading = ref(false);
|
||||
const searchText = ref("");
|
||||
const statusFilter = ref<"all" | "valid" | "invalid">("all");
|
||||
const currentPage = ref(1);
|
||||
const pageSize = ref(20);
|
||||
const totalKeys = ref(0);
|
||||
const showMoreMenu = ref(false);
|
||||
|
||||
const totalPages = computed(() => Math.ceil(totalKeys.value / pageSize.value));
|
||||
|
||||
watch(
|
||||
() => props.selectedGroup,
|
||||
async newGroup => {
|
||||
if (newGroup) {
|
||||
currentPage.value = 1;
|
||||
await loadKeys();
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
watch([currentPage, pageSize, statusFilter, searchText], async () => {
|
||||
await loadKeys();
|
||||
});
|
||||
|
||||
async function loadKeys() {
|
||||
if (!props.selectedGroup) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
loading.value = true;
|
||||
const result = await keysApi.getGroupKeys(
|
||||
props.selectedGroup.id,
|
||||
currentPage.value,
|
||||
pageSize.value,
|
||||
statusFilter.value === "all" ? undefined : statusFilter.value
|
||||
);
|
||||
keys.value = result.data;
|
||||
totalKeys.value = result.total;
|
||||
} catch (error) {
|
||||
console.error("加载密钥失败:", error);
|
||||
window.$message.error("加载密钥失败");
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function maskKey(key: string): string {
|
||||
if (key.length <= 8) {
|
||||
return key;
|
||||
}
|
||||
return `${key.substring(0, 4)}...${key.substring(key.length - 4)}`;
|
||||
}
|
||||
|
||||
function copyKey(key: APIKey) {
|
||||
navigator.clipboard
|
||||
.writeText(key.key_value)
|
||||
.then(() => {
|
||||
window.$message.success("密钥已复制到剪贴板");
|
||||
})
|
||||
.catch(() => {
|
||||
window.$message.error("复制失败");
|
||||
});
|
||||
}
|
||||
|
||||
async function testKey(_key: APIKey) {
|
||||
try {
|
||||
window.$message.info("正在测试密钥...");
|
||||
// TODO: 实现密钥测试 API
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
const success = Math.random() > 0.3; // 模拟测试结果
|
||||
if (success) {
|
||||
window.$message.success("密钥测试成功");
|
||||
} else {
|
||||
window.$message.error("密钥测试失败: 无效的API密钥");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("测试密钥失败:", error);
|
||||
window.$message.error("测试失败");
|
||||
}
|
||||
}
|
||||
|
||||
function toggleKeyVisibility(key: APIKey) {
|
||||
// TODO: 实现密钥显示/隐藏切换
|
||||
window.$message.info(`切换密钥"${maskKey(key.key_value)}"显示状态功能开发中`);
|
||||
}
|
||||
|
||||
async function restoreKey(key: APIKey) {
|
||||
// eslint-disable-next-line no-alert
|
||||
const confirmed = window.confirm(`确定要恢复密钥"${maskKey(key.key_value)}"吗?`);
|
||||
if (!confirmed) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await keysApi.toggleKeyStatus(key.id.toString(), 1);
|
||||
window.$message.success("密钥已恢复");
|
||||
await loadKeys();
|
||||
} catch (error) {
|
||||
console.error("恢复密钥失败:", error);
|
||||
window.$message.error("恢复失败");
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteKey(key: APIKey) {
|
||||
// eslint-disable-next-line no-alert
|
||||
const confirmed = window.confirm(`确定要删除密钥"${maskKey(key.key_value)}"吗?`);
|
||||
if (!confirmed) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await keysApi.deleteKeyById(key.id.toString());
|
||||
window.$message.success("密钥已删除");
|
||||
await loadKeys();
|
||||
} catch (error) {
|
||||
console.error("删除密钥失败:", error);
|
||||
window.$message.error("删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
function formatDate(date: string) {
|
||||
return new Date(date).toLocaleDateString();
|
||||
}
|
||||
|
||||
function formatRelativeTime(date: string) {
|
||||
const now = new Date();
|
||||
const target = new Date(date);
|
||||
const diff = now.getTime() - target.getTime();
|
||||
const hours = Math.floor(diff / (1000 * 60 * 60));
|
||||
const days = Math.floor(hours / 24);
|
||||
|
||||
if (days > 0) {
|
||||
return `${days}天前`;
|
||||
} else if (hours > 0) {
|
||||
return `${hours}小时前`;
|
||||
} else {
|
||||
return "刚刚";
|
||||
}
|
||||
}
|
||||
|
||||
function getStatusText(status: "active" | "inactive" | "error") {
|
||||
switch (status) {
|
||||
case "active":
|
||||
return "有效";
|
||||
case "inactive":
|
||||
return "无效";
|
||||
case "error":
|
||||
return "错误";
|
||||
default:
|
||||
return "未知";
|
||||
}
|
||||
}
|
||||
|
||||
function getStatusClass(status: "active" | "inactive" | "error") {
|
||||
switch (status) {
|
||||
case "active":
|
||||
return "status-valid";
|
||||
case "inactive":
|
||||
return "status-invalid";
|
||||
case "error":
|
||||
return "status-error";
|
||||
default:
|
||||
return "status-unknown";
|
||||
}
|
||||
}
|
||||
|
||||
function addKey() {
|
||||
window.$message.info("添加密钥功能开发中");
|
||||
}
|
||||
|
||||
async function copyAllKeys() {
|
||||
if (!props.selectedGroup) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await keysApi.exportKeys(props.selectedGroup.id, "all");
|
||||
const keysText = result.keys.join("\n");
|
||||
navigator.clipboard
|
||||
.writeText(keysText)
|
||||
.then(() => {
|
||||
window.$message.success(`已复制${result.keys.length}个密钥到剪贴板`);
|
||||
})
|
||||
.catch(() => {
|
||||
window.$message.error("复制失败");
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("导出失败:", error);
|
||||
window.$message.error("导出失败");
|
||||
}
|
||||
}
|
||||
|
||||
async function copyValidKeys() {
|
||||
if (!props.selectedGroup) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await keysApi.exportKeys(props.selectedGroup.id, "valid");
|
||||
const keysText = result.keys.join("\n");
|
||||
navigator.clipboard
|
||||
.writeText(keysText)
|
||||
.then(() => {
|
||||
window.$message.success(`已复制${result.keys.length}个有效密钥到剪贴板`);
|
||||
})
|
||||
.catch(() => {
|
||||
window.$message.error("复制失败");
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("导出失败:", error);
|
||||
window.$message.error("导出失败");
|
||||
}
|
||||
}
|
||||
|
||||
async function copyInvalidKeys() {
|
||||
if (!props.selectedGroup) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await keysApi.exportKeys(props.selectedGroup.id, "invalid");
|
||||
const keysText = result.keys.join("\n");
|
||||
navigator.clipboard
|
||||
.writeText(keysText)
|
||||
.then(() => {
|
||||
window.$message.success(`已复制${result.keys.length}个无效密钥到剪贴板`);
|
||||
})
|
||||
.catch(() => {
|
||||
window.$message.error("复制失败");
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("导出失败:", error);
|
||||
window.$message.error("导出失败");
|
||||
}
|
||||
}
|
||||
|
||||
async function restoreAllInvalid() {
|
||||
if (!props.selectedGroup) {
|
||||
return;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-alert
|
||||
const confirmed = window.confirm("确定要恢复所有无效密钥吗?");
|
||||
if (!confirmed) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// TODO: 实现恢复所有无效密钥 API
|
||||
window.$message.success("所有无效密钥已恢复");
|
||||
await loadKeys();
|
||||
} catch (error) {
|
||||
console.error("恢复失败:", error);
|
||||
window.$message.error("恢复失败");
|
||||
}
|
||||
}
|
||||
|
||||
async function validateAllKeys() {
|
||||
if (!props.selectedGroup) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await keysApi.validateKeys(props.selectedGroup.id);
|
||||
window.$message.success(`验证完成: 有效${result.valid_count}个,无效${result.invalid_count}个`);
|
||||
} catch (error) {
|
||||
console.error("验证失败:", error);
|
||||
window.$message.error("验证失败");
|
||||
}
|
||||
}
|
||||
|
||||
async function clearAllInvalid() {
|
||||
if (!props.selectedGroup) {
|
||||
return;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-alert
|
||||
const confirmed = window.confirm("确定要清除所有无效密钥吗?此操作不可恢复!");
|
||||
if (!confirmed) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// TODO: 实现清除所有无效密钥 API
|
||||
window.$message.success("所有无效密钥已清除");
|
||||
await loadKeys();
|
||||
} catch (error) {
|
||||
console.error("清除失败:", error);
|
||||
window.$message.error("清除失败");
|
||||
}
|
||||
}
|
||||
|
||||
function changePage(page: number) {
|
||||
currentPage.value = page;
|
||||
}
|
||||
|
||||
function changePageSize(size: number) {
|
||||
pageSize.value = size;
|
||||
currentPage.value = 1;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="key-table-container">
|
||||
<!-- 工具栏 -->
|
||||
<div class="toolbar">
|
||||
<div class="toolbar-left">
|
||||
<button @click="addKey" class="btn btn-primary btn-sm">+ 添加密钥</button>
|
||||
</div>
|
||||
<div class="toolbar-right">
|
||||
<div class="filter-group">
|
||||
<select v-model="statusFilter" class="filter-select">
|
||||
<option value="all">全部</option>
|
||||
<option value="valid">有效</option>
|
||||
<option value="invalid">无效</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="filter-group">
|
||||
<input v-model="searchText" type="text" placeholder="Key 模糊查询" class="search-input" />
|
||||
</div>
|
||||
<div class="more-actions">
|
||||
<button @click="showMoreMenu = !showMoreMenu" class="btn btn-secondary btn-sm">
|
||||
<span class="more-icon">⋯</span>
|
||||
</button>
|
||||
<div v-if="showMoreMenu" class="more-menu">
|
||||
<button @click="copyAllKeys" class="menu-item">复制所有 Key</button>
|
||||
<button @click="copyValidKeys" class="menu-item">复制有效 Key</button>
|
||||
<button @click="copyInvalidKeys" class="menu-item">复制无效 Key</button>
|
||||
<div class="menu-divider" />
|
||||
<button @click="restoreAllInvalid" class="menu-item">恢复所有无效 Key</button>
|
||||
<button @click="validateAllKeys" class="menu-item">验证所有 Key</button>
|
||||
<div class="menu-divider" />
|
||||
<button @click="clearAllInvalid" class="menu-item danger">清空所有无效 Key</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 密钥表格 -->
|
||||
<div class="table-container">
|
||||
<table class="key-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="key-column">密钥 (Key)</th>
|
||||
<th class="status-column">状态</th>
|
||||
<th class="usage-column">24小时请求</th>
|
||||
<th class="last-used-column">最后使用</th>
|
||||
<th class="created-column">创建时间</th>
|
||||
<th class="actions-column">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="loading" class="loading-row">
|
||||
<td colspan="6" class="loading-cell">
|
||||
<div class="loading-spinner">加载中...</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-else-if="keys.length === 0" class="empty-row">
|
||||
<td colspan="6" class="empty-cell">
|
||||
<div class="empty-text">没有找到匹配的密钥</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-else v-for="key in keys" :key="key.id" class="key-row">
|
||||
<td class="key-column">
|
||||
<div class="key-content">
|
||||
<span class="key-text" :title="key.key_value">{{ maskKey(key.key_value) }}</span>
|
||||
<div class="key-actions">
|
||||
<button @click="copyKey(key)" class="key-btn" title="复制">
|
||||
<span class="icon">📋</span>
|
||||
</button>
|
||||
<button @click="toggleKeyVisibility(key)" class="key-btn" title="显示/隐藏">
|
||||
<span class="icon">👁️</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="status-column">
|
||||
<span :class="['status-badge', getStatusClass(key.status)]">
|
||||
{{ getStatusText(key.status) }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="usage-column">
|
||||
<span class="usage-text">{{ key.request_count }} / {{ key.failure_count }}</span>
|
||||
</td>
|
||||
<td class="last-used-column">
|
||||
<span class="time-text">
|
||||
{{ key.last_used_at ? formatRelativeTime(key.last_used_at) : "从未使用" }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="created-column">
|
||||
<span class="time-text">{{ formatDate(key.created_at) }}</span>
|
||||
</td>
|
||||
<td class="actions-column">
|
||||
<div class="action-buttons">
|
||||
<button @click="copyKey(key)" class="action-btn" title="复制">复制</button>
|
||||
<button @click="testKey(key)" class="action-btn" title="测试">测试</button>
|
||||
<button
|
||||
v-if="key.status !== 'active'"
|
||||
@click="restoreKey(key)"
|
||||
class="action-btn"
|
||||
title="恢复"
|
||||
>
|
||||
恢复
|
||||
</button>
|
||||
<button @click="deleteKey(key)" class="action-btn danger" title="删除">删除</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div class="pagination-container">
|
||||
<div class="pagination-info">
|
||||
<span>共 {{ totalKeys }} 条记录</span>
|
||||
<select v-model="pageSize" @change="changePageSize(pageSize)" class="page-size-select">
|
||||
<option :value="10">10条/页</option>
|
||||
<option :value="20">20条/页</option>
|
||||
<option :value="50">50条/页</option>
|
||||
<option :value="100">100条/页</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="pagination-controls">
|
||||
<button
|
||||
@click="changePage(currentPage - 1)"
|
||||
:disabled="currentPage <= 1"
|
||||
class="btn btn-secondary btn-sm"
|
||||
>
|
||||
上一页
|
||||
</button>
|
||||
<span class="page-info">第 {{ currentPage }} 页,共 {{ totalPages }} 页</span>
|
||||
<button
|
||||
@click="changePage(currentPage + 1)"
|
||||
:disabled="currentPage >= totalPages"
|
||||
class="btn btn-secondary btn-sm"
|
||||
>
|
||||
下一页
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.key-table-container {
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
overflow: hidden;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 12px 16px;
|
||||
background: #f8f9fa;
|
||||
border-bottom: 1px solid #e9ecef;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.toolbar-left {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.toolbar-right {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.filter-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.more-actions {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.more-menu {
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
right: 0;
|
||||
background: white;
|
||||
border: 1px solid #e9ecef;
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||
min-width: 180px;
|
||||
z-index: 1000;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.menu-item {
|
||||
display: block;
|
||||
width: 100%;
|
||||
padding: 8px 12px;
|
||||
border: none;
|
||||
background: none;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
color: #333;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.menu-item:hover {
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.menu-item.danger {
|
||||
color: #dc3545;
|
||||
}
|
||||
|
||||
.menu-item.danger:hover {
|
||||
background: #f8d7da;
|
||||
}
|
||||
|
||||
.menu-divider {
|
||||
height: 1px;
|
||||
background: #e9ecef;
|
||||
margin: 4px 0;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 6px 12px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
transition: all 0.2s;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.btn-sm {
|
||||
padding: 4px 8px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: #007bff;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-primary:hover:not(:disabled) {
|
||||
background: #0056b3;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: #6c757d;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
background: #545b62;
|
||||
}
|
||||
|
||||
.more-icon {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.filter-select,
|
||||
.search-input,
|
||||
.page-size-select {
|
||||
padding: 4px 8px;
|
||||
border: 1px solid #ced4da;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
width: 180px;
|
||||
}
|
||||
|
||||
.filter-select:focus,
|
||||
.search-input:focus,
|
||||
.page-size-select:focus {
|
||||
outline: none;
|
||||
border-color: #007bff;
|
||||
box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
|
||||
}
|
||||
|
||||
.table-container {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.key-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
background: white;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.key-table th,
|
||||
.key-table td {
|
||||
padding: 8px 12px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid #e9ecef;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.key-table th {
|
||||
background: #f8f9fa;
|
||||
font-weight: 600;
|
||||
color: #495057;
|
||||
font-size: 12px;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.key-column {
|
||||
width: 35%;
|
||||
}
|
||||
|
||||
.status-column {
|
||||
width: 10%;
|
||||
}
|
||||
|
||||
.usage-column {
|
||||
width: 15%;
|
||||
}
|
||||
|
||||
.last-used-column {
|
||||
width: 15%;
|
||||
}
|
||||
|
||||
.created-column {
|
||||
width: 15%;
|
||||
}
|
||||
|
||||
.actions-column {
|
||||
width: 10%;
|
||||
}
|
||||
|
||||
.key-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.key-text {
|
||||
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
|
||||
font-size: 12px;
|
||||
color: #495057;
|
||||
background: #f8f9fa;
|
||||
padding: 2px 6px;
|
||||
border-radius: 3px;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.key-actions {
|
||||
display: flex;
|
||||
gap: 2px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.key-btn {
|
||||
padding: 2px 4px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
border-radius: 3px;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.key-btn:hover {
|
||||
background: #e9ecef;
|
||||
}
|
||||
|
||||
.key-btn .icon {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
display: inline-block;
|
||||
padding: 2px 6px;
|
||||
border-radius: 10px;
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
text-align: center;
|
||||
min-width: 40px;
|
||||
}
|
||||
|
||||
.status-valid {
|
||||
background: #d4edda;
|
||||
color: #155724;
|
||||
}
|
||||
|
||||
.status-invalid {
|
||||
background: #f8d7da;
|
||||
color: #721c24;
|
||||
}
|
||||
|
||||
.status-error {
|
||||
background: #fff3cd;
|
||||
color: #856404;
|
||||
}
|
||||
|
||||
.status-unknown {
|
||||
background: #d1ecf1;
|
||||
color: #0c5460;
|
||||
}
|
||||
|
||||
.usage-text {
|
||||
font-weight: 500;
|
||||
color: #495057;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.time-text {
|
||||
font-size: 11px;
|
||||
color: #6c757d;
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
gap: 2px;
|
||||
flex-wrap: nowrap;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
padding: 2px 6px;
|
||||
border: none;
|
||||
border-radius: 3px;
|
||||
cursor: pointer;
|
||||
font-size: 10px;
|
||||
transition: all 0.2s;
|
||||
white-space: nowrap;
|
||||
background: #f8f9fa;
|
||||
color: #495057;
|
||||
border: 1px solid #dee2e6;
|
||||
}
|
||||
|
||||
.action-btn:hover {
|
||||
background: #e9ecef;
|
||||
border-color: #adb5bd;
|
||||
}
|
||||
|
||||
.action-btn.danger {
|
||||
color: #dc3545;
|
||||
}
|
||||
|
||||
.action-btn.danger:hover {
|
||||
background: #f8d7da;
|
||||
border-color: #dc3545;
|
||||
}
|
||||
|
||||
.loading-row,
|
||||
.empty-row {
|
||||
height: 80px;
|
||||
}
|
||||
|
||||
.loading-cell,
|
||||
.empty-cell {
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
color: #6c757d;
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.pagination-container {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 12px 16px;
|
||||
background: #f8f9fa;
|
||||
border-top: 1px solid #e9ecef;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.pagination-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
font-size: 12px;
|
||||
color: #6c757d;
|
||||
}
|
||||
|
||||
.pagination-controls {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.page-info {
|
||||
font-size: 12px;
|
||||
color: #6c757d;
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
.toolbar {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.toolbar-left,
|
||||
.toolbar-right {
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
flex-direction: column;
|
||||
gap: 1px;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
font-size: 9px;
|
||||
padding: 1px 4px;
|
||||
}
|
||||
}
|
||||
</style>
|
Reference in New Issue
Block a user