pre / static /js /api-key-manager /main-manager.js
yangtb24's picture
Upload 37 files
bbb6398 verified
raw
history blame
5.43 kB
// API密钥管理器主模块
// 定义API密钥管理器的主函数
function apiKeyManager() {
return {
// 数据状态
apiKeys: [],
platformStates: {},
platformFilters: {}, // 平台筛选状态
allPlatformsSelected: true, // 是否选择所有平台
searchTerm: '',
showAddModal: false,
showDeleteConfirm: false,
isSubmitting: false,
isDeleting: false,
isLoading: true, // 添加加载状态
errorMessage: '',
copiedId: null,
deleteKeyId: null,
deleteKeyName: '',
selectedKeys: [], // 批量选择的密钥ID数组
selectedPlatforms: [], // 批量选择的平台ID数组
isBulkDelete: false, // 是否为批量删除操作
newKey: {
platform: '',
name: '',
key: ''
},
showEditModal: false,
editKey: {
id: '',
name: '',
key: '',
platform: ''
},
// 生命周期钩子
init() {
// 调用核心模块的初始化函数
initApiKeyManager.call(this);
},
// 加载API密钥
loadApiKeys() {
return loadApiKeys.apply(this, arguments);
},
// 添加API密钥
addApiKey() {
return addApiKey.apply(this, arguments);
},
// 删除API密钥
deleteApiKey(id, name) {
return deleteApiKey.apply(this, arguments);
},
// 切换单个密钥的选择状态
toggleKeySelection(keyId) {
return toggleKeySelection.apply(this, arguments);
},
// 切换平台的选择状态
togglePlatformSelection(platformId) {
return togglePlatformSelection.apply(this, arguments);
},
// 更新平台选择状态(基于已选择的密钥)
updatePlatformSelectionStates() {
return updatePlatformSelectionStates.apply(this, arguments);
},
// 获取所有可见密钥ID
getAllVisibleKeyIds() {
return getAllVisibleKeyIds.apply(this, arguments);
},
// 判断是否全部选中的计算属性
get isAllSelected() {
// 获取所有可见密钥的ID
const allVisibleKeyIds = this.getAllVisibleKeyIds();
// 全选需要满足:有可见密钥,且所有可见密钥都被选中
return allVisibleKeyIds.length > 0 &&
allVisibleKeyIds.every(id => this.selectedKeys.includes(id));
},
// 切换全选/取消全选
toggleSelectAll() {
return toggleSelectAll.apply(this, arguments);
},
// 批量删除API密钥
bulkDeleteApiKeys() {
return bulkDeleteApiKeys.apply(this, arguments);
},
// 批量复制API密钥
bulkCopyApiKeys() {
return bulkCopyApiKeys.apply(this, arguments);
},
// 确认删除(单个或批量)
confirmDelete() {
return confirmDelete.apply(this, arguments);
},
// 复制到剪贴板
copyToClipboard(text, id) {
return copyToClipboard.apply(this, arguments);
},
// 切换平台折叠状态
togglePlatform(platformId) {
return togglePlatform.apply(this, arguments);
},
// 获取平台API密钥数量
getPlatformKeyCount(platformId, filtered = false) {
return getPlatformKeyCount.apply(this, arguments);
},
// 平台是否有API密钥
hasPlatformKeys(platformId) {
return hasPlatformKeys.apply(this, arguments);
},
// 平台是否应该显示(基于筛选条件)
isPlatformVisible(platformId) {
return isPlatformVisible.apply(this, arguments);
},
// 获取所有平台
getPlatforms() {
return getPlatforms.apply(this, arguments);
},
// 切换平台筛选状态
togglePlatformFilter(platformId) {
return togglePlatformFilter.apply(this, arguments);
},
// 切换所有平台筛选状态
toggleAllPlatformFilters() {
return toggleAllPlatformFilters.apply(this, arguments);
},
// 搜索匹配
matchesSearch(name, key, notes) {
return matchesSearch.apply(this, arguments);
},
// 获取总API密钥数量
totalKeyCount() {
return totalKeyCount.apply(this, arguments);
},
// 打开编辑API密钥模态框
editApiKey(id, name, key) {
return editApiKey.apply(this, arguments);
},
// 更新API密钥
updateApiKey() {
return updateApiKey.apply(this, arguments);
},
// 显示通知
showNotification(message, type = 'info') {
return showNotification.apply(this, arguments);
}
};
}