File size: 2,455 Bytes
bbb6398 834bfcd bbb6398 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
/**
* API密钥管理器 - UI工具模块
* 包含各种UI交互辅助功能
*/
// 复制到剪贴板
function copyToClipboard(text, id) {
// 使用临时textarea元素复制文本
const textarea = document.createElement('textarea');
textarea.value = text;
textarea.style.position = 'fixed';
document.body.appendChild(textarea);
textarea.select();
try {
document.execCommand('copy');
this.copiedId = id;
// 使用SweetAlert2显示复制成功动画
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: '已复制到剪贴板',
background: '#f0fdf4',
iconColor: '#16a34a'
});
// 2秒后重置复制状态
setTimeout(() => {
this.copiedId = null;
}, 2000);
} catch (err) {
console.error('复制失败:', err);
Swal.fire({
icon: 'error',
title: '复制失败',
text: '请手动复制内容',
confirmButtonColor: '#0284c7'
});
} finally {
document.body.removeChild(textarea);
}
}
// 显示通知
function showNotification(message, type = 'info') {
const event = new CustomEvent('show-notification', {
detail: { message, type }
});
window.dispatchEvent(event);
}
// 获取总API密钥数量
function totalKeyCount() {
// 根据当前视图过滤密钥
if (this.currentView === 'valid') {
return this.apiKeys.filter(key => key.success === true).length;
} else if (this.currentView === 'invalid') {
return this.apiKeys.filter(key => key.success === false).length;
}
return this.apiKeys.length;
}
// 搜索匹配
function matchesSearch(name, key, notes) {
if (!this.searchTerm) return true;
const searchLower = this.searchTerm.toLowerCase();
return (
(name && name.toLowerCase().includes(searchLower)) ||
(key && key.toLowerCase().includes(searchLower))
);
}
|