|
|
|
|
|
|
|
|
|
|
|
|
|
function toggleKeySelection(keyId) {
|
|
|
|
const key = this.apiKeys.find(k => k.id === keyId);
|
|
|
|
|
|
if (!key || (this.currentView === 'valid' && key.success !== true) ||
|
|
(this.currentView === 'invalid' && key.success !== false)) {
|
|
return;
|
|
}
|
|
|
|
const index = this.selectedKeys.indexOf(keyId);
|
|
if (index === -1) {
|
|
|
|
this.selectedKeys.push(keyId);
|
|
} else {
|
|
|
|
this.selectedKeys.splice(index, 1);
|
|
}
|
|
|
|
|
|
this.updatePlatformSelectionStates();
|
|
}
|
|
|
|
|
|
function togglePlatformSelection(platformId) {
|
|
const index = this.selectedPlatforms.indexOf(platformId);
|
|
|
|
if (index === -1) {
|
|
|
|
this.selectedPlatforms.push(platformId);
|
|
|
|
|
|
this.apiKeys.forEach(key => {
|
|
|
|
if (key.platform === platformId && !this.selectedKeys.includes(key.id) &&
|
|
((this.currentView === 'valid' && key.success === true) ||
|
|
(this.currentView === 'invalid' && key.success === false))) {
|
|
this.selectedKeys.push(key.id);
|
|
}
|
|
});
|
|
} else {
|
|
|
|
this.selectedPlatforms.splice(index, 1);
|
|
|
|
|
|
this.selectedKeys = this.selectedKeys.filter(keyId => {
|
|
const key = this.apiKeys.find(k => k.id === keyId);
|
|
return key && key.platform !== platformId;
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
function updatePlatformSelectionStates() {
|
|
const platforms = this.getPlatforms();
|
|
|
|
|
|
this.selectedPlatforms = [];
|
|
|
|
|
|
platforms.forEach(platform => {
|
|
|
|
const platformKeys = this.apiKeys.filter(key =>
|
|
key.platform === platform.id &&
|
|
((this.currentView === 'valid' && key.success === true) ||
|
|
(this.currentView === 'invalid' && key.success === false))
|
|
);
|
|
|
|
const allSelected = platformKeys.length > 0 &&
|
|
platformKeys.every(key => this.selectedKeys.includes(key.id));
|
|
|
|
if (allSelected) {
|
|
this.selectedPlatforms.push(platform.id);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
function getAllVisibleKeyIds() {
|
|
|
|
const visibleIds = this.apiKeys
|
|
.filter(key => {
|
|
|
|
if (this.currentView === 'valid' && key.success !== true) return false;
|
|
if (this.currentView === 'invalid' && key.success !== false) return false;
|
|
|
|
|
|
if (!this.platformFilters[key.platform]) return false;
|
|
|
|
|
|
if (this.searchTerm && !this.matchesSearch(key.name, key.key)) return false;
|
|
|
|
return true;
|
|
})
|
|
.map(key => key.id);
|
|
|
|
return visibleIds;
|
|
}
|
|
|
|
|
|
function toggleSelectAll() {
|
|
const allIds = this.getAllVisibleKeyIds();
|
|
|
|
|
|
const filteredIds = allIds.filter(id => {
|
|
const key = this.apiKeys.find(k => k.id === id);
|
|
return key && this.platformFilters[key.platform] === true;
|
|
});
|
|
|
|
if (this.isAllSelected) {
|
|
|
|
this.selectedKeys = this.selectedKeys.filter(id => !filteredIds.includes(id));
|
|
} else {
|
|
|
|
|
|
const newSelection = [...this.selectedKeys];
|
|
|
|
filteredIds.forEach(id => {
|
|
if (!newSelection.includes(id)) {
|
|
newSelection.push(id);
|
|
}
|
|
});
|
|
this.selectedKeys = newSelection;
|
|
}
|
|
|
|
|
|
this.updatePlatformSelectionStates();
|
|
}
|
|
|
|
|
|
function bulkDeleteApiKeys() {
|
|
if (this.selectedKeys.length === 0) return;
|
|
|
|
|
|
this.isBulkDelete = true;
|
|
|
|
|
|
this.showDeleteConfirm = true;
|
|
}
|
|
|
|
|
|
function bulkCopyApiKeys() {
|
|
if (this.selectedKeys.length === 0) return;
|
|
|
|
|
|
const selectedKeyValues = [];
|
|
this.selectedKeys.forEach(keyId => {
|
|
|
|
const keyElement = document.querySelector(`[data-key-id="${keyId}"]`);
|
|
if (keyElement) {
|
|
|
|
const keyValueElement = keyElement.querySelector('.text-gray-500.font-mono');
|
|
if (keyValueElement) {
|
|
const keyValue = keyValueElement.textContent.trim();
|
|
selectedKeyValues.push(keyValue);
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
if (selectedKeyValues.length > 0) {
|
|
|
|
const formattedKeys = selectedKeyValues.join('\n');
|
|
|
|
|
|
const textarea = document.createElement('textarea');
|
|
textarea.value = formattedKeys;
|
|
textarea.style.position = 'fixed';
|
|
document.body.appendChild(textarea);
|
|
textarea.select();
|
|
|
|
try {
|
|
document.execCommand('copy');
|
|
|
|
|
|
const Toast = Swal.mixin({
|
|
toast: true,
|
|
position: 'top-end',
|
|
showConfirmButton: false,
|
|
timer: 1500,
|
|
timerProgressBar: true,
|
|
didOpen: (toast) => {
|
|
toast.onmouseenter = Swal.stopTimer;
|
|
toast.onmouseleave = Swal.resumeTimer;
|
|
}
|
|
});
|
|
|
|
Toast.fire({
|
|
icon: 'success',
|
|
title: `已成功复制 ${selectedKeyValues.length} 个密钥到剪贴板`,
|
|
background: '#f0fdf4',
|
|
iconColor: '#16a34a'
|
|
});
|
|
} catch (err) {
|
|
console.error('复制失败:', err);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: '复制失败',
|
|
text: '请手动复制内容',
|
|
confirmButtonColor: '#0284c7'
|
|
});
|
|
} finally {
|
|
document.body.removeChild(textarea);
|
|
}
|
|
} else {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: '复制失败',
|
|
text: '无法获取所选密钥的值',
|
|
confirmButtonColor: '#0284c7'
|
|
});
|
|
}
|
|
}
|
|
|