|
|
|
|
|
|
|
|
|
|
|
|
|
function deleteApiKey(id, name) {
|
|
this.deleteKeyId = id;
|
|
this.deleteKeyName = name;
|
|
this.showDeleteConfirm = true;
|
|
}
|
|
|
|
|
|
async function confirmDelete() {
|
|
if (this.isBulkDelete) {
|
|
if (this.selectedKeys.length === 0) return;
|
|
|
|
this.isDeleting = true;
|
|
|
|
try {
|
|
const response = await fetch('/api/keys/bulk-delete', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({ ids: this.selectedKeys }),
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (data.success) {
|
|
|
|
this.showDeleteConfirm = false;
|
|
this.isBulkDelete = false;
|
|
const deletedCount = data.deleted_count || this.selectedKeys.length;
|
|
|
|
|
|
this.selectedKeys = [];
|
|
this.selectedPlatforms = [];
|
|
|
|
|
|
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;
|
|
}
|
|
});
|
|
|
|
|
|
this.loadApiKeys();
|
|
|
|
Toast.fire({
|
|
icon: 'success',
|
|
title: `成功删除 ${deletedCount} 个API密钥`,
|
|
background: '#fee2e2',
|
|
iconColor: '#ef4444'
|
|
});
|
|
} else {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: '批量删除失败',
|
|
text: data.error || '删除操作未能完成,请重试',
|
|
confirmButtonColor: '#0284c7'
|
|
});
|
|
}
|
|
} catch (error) {
|
|
console.error('批量删除API密钥失败:', error);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: '服务器错误',
|
|
text: '无法完成删除操作,请稍后重试',
|
|
confirmButtonColor: '#0284c7'
|
|
});
|
|
} finally {
|
|
this.isDeleting = false;
|
|
}
|
|
} else {
|
|
|
|
if (!this.deleteKeyId) return;
|
|
|
|
this.isDeleting = true;
|
|
|
|
try {
|
|
const response = await fetch(`/api/keys/${this.deleteKeyId}`, {
|
|
method: 'DELETE',
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (data.success) {
|
|
|
|
this.apiKeys = [...this.apiKeys.filter(key => key.id !== this.deleteKeyId)];
|
|
|
|
|
|
this.showDeleteConfirm = false;
|
|
|
|
|
|
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;
|
|
}
|
|
});
|
|
|
|
|
|
this.loadApiKeys();
|
|
|
|
Toast.fire({
|
|
icon: 'success',
|
|
title: 'API密钥已删除',
|
|
background: '#fee2e2',
|
|
iconColor: '#ef4444'
|
|
});
|
|
} else {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: '删除失败',
|
|
text: data.message || '删除操作未能完成,请重试',
|
|
confirmButtonColor: '#0284c7'
|
|
});
|
|
}
|
|
} catch (error) {
|
|
console.error('删除API密钥失败:', error);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: '服务器错误',
|
|
text: '无法完成删除操作,请稍后重试',
|
|
confirmButtonColor: '#0284c7'
|
|
});
|
|
} finally {
|
|
this.isDeleting = false;
|
|
}
|
|
}
|
|
}
|
|
|