File size: 5,431 Bytes
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
// 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);
}
};
}
|