|
|
|
|
|
|
|
|
|
|
|
|
|
function toggleKeySelection(keyId) {
|
|
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.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);
|
|
const allSelected = platformKeys.length > 0 &&
|
|
platformKeys.every(key => this.selectedKeys.includes(key.id));
|
|
|
|
if (allSelected) {
|
|
this.selectedPlatforms.push(platform.id);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
function getAllVisibleKeyIds() {
|
|
|
|
const keyElements = document.querySelectorAll('[data-key-id]');
|
|
const keyIds = [];
|
|
keyElements.forEach(el => {
|
|
|
|
if (window.getComputedStyle(el).display !== 'none') {
|
|
const keyId = el.getAttribute('data-key-id');
|
|
if (keyId) keyIds.push(keyId);
|
|
}
|
|
});
|
|
return keyIds;
|
|
}
|
|
|
|
|
|
function toggleSelectAll() {
|
|
const allIds = this.getAllVisibleKeyIds();
|
|
|
|
if (this.isAllSelected) {
|
|
|
|
this.selectedKeys = this.selectedKeys.filter(id => !allIds.includes(id));
|
|
} else {
|
|
|
|
|
|
const newSelection = [...this.selectedKeys];
|
|
|
|
allIds.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'
|
|
});
|
|
}
|
|
}
|
|
|