diff --git a/web/admin-spa/src/views/ApiKeysView.vue b/web/admin-spa/src/views/ApiKeysView.vue index fb3199df..00677508 100644 --- a/web/admin-spa/src/views/ApiKeysView.vue +++ b/web/admin-spa/src/views/ApiKeysView.vue @@ -14,7 +14,7 @@ + + +
+ + + ... + + + + + + ... + +
+ + + + + @@ -659,6 +753,11 @@ const apiKeyDateFilters = ref({}) const defaultTime = ref([new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)]) const accounts = ref({ claude: [], gemini: [] }) +// 分页相关 +const currentPage = ref(1) +const pageSize = ref(10) +const pageSizeOptions = [5, 10, 20, 50, 100] + // 标签相关 const selectedTagFilter = ref('') const availableTags = ref([]) @@ -672,8 +771,8 @@ const editingApiKey = ref(null) const renewingApiKey = ref(null) const newApiKeyData = ref(null) -// 计算排序后的API Keys -const sortedApiKeys = computed(() => { +// 计算筛选和排序后的API Keys(未分页) +const filteredAndSortedApiKeys = computed(() => { // 先进行标签筛选 let filteredKeys = apiKeys.value if (selectedTagFilter.value) { @@ -710,6 +809,37 @@ const sortedApiKeys = computed(() => { return sorted }) +// 计算总页数 +const totalPages = computed(() => { + return Math.ceil(filteredAndSortedApiKeys.value.length / pageSize.value) +}) + +// 计算当前页显示的API Keys +const sortedApiKeys = computed(() => { + const start = (currentPage.value - 1) * pageSize.value + const end = start + pageSize.value + return filteredAndSortedApiKeys.value.slice(start, end) +}) + +// 计算要显示的页码 +const pageNumbers = computed(() => { + const pages = [] + const maxPagesToShow = 5 + let startPage = Math.max(1, currentPage.value - Math.floor(maxPagesToShow / 2)) + let endPage = Math.min(totalPages.value, startPage + maxPagesToShow - 1) + + // 调整起始页 + if (endPage - startPage < maxPagesToShow - 1) { + startPage = Math.max(1, endPage - maxPagesToShow + 1) + } + + for (let i = startPage; i <= endPage; i++) { + pages.push(i) + } + + return pages +}) + // 加载账户列表 const loadAccounts = async () => { try { @@ -771,6 +901,9 @@ const loadApiKeys = async () => { } }) availableTags.value = Array.from(tagsSet).sort() + + // 重置到第一页 + currentPage.value = 1 } } catch (error) { showToast('加载 API Keys 失败', 'error') @@ -787,6 +920,8 @@ const sortApiKeys = (field) => { apiKeysSortBy.value = field apiKeysSortOrder.value = 'asc' } + // 排序时重置到第一页 + currentPage.value = 1 } // 格式化数字 @@ -1173,4 +1308,5 @@ onMounted(async () => { .api-key-date-picker :deep(.el-range-separator) { @apply text-gray-500; } + \ No newline at end of file