File size: 7,849 Bytes
bbb6398
 
 
 
 
 
 
 
ef8784d
bbb6398
834bfcd
bbb6398
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ef8784d
 
 
 
 
 
 
 
 
 
bbb6398
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
834bfcd
bbb6398
 
 
 
834bfcd
 
 
2809c18
 
 
 
 
834bfcd
2809c18
 
834bfcd
 
2809c18
 
 
 
 
 
 
 
 
 
 
 
 
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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// API密钥管理器主模块
// 定义API密钥管理器的主函数
function apiKeyManager() {
    return {
        // 数据状态
        apiKeys: [],
        platformStates: {},
        platformFilters: {}, // 平台筛选状态
        platformIds: [], // 所有平台ID列表
        allPlatformsSelected: true, // 是否选择所有平台
        currentView: 'valid', // 当前视图:'valid'(有效)或'invalid'(无效)
        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();
            
            // 过滤出只属于选中平台的密钥ID
            const filteredIds = allVisibleKeyIds.filter(id => {
                const key = this.apiKeys.find(k => k.id === id);
                return key && this.platformFilters[key.platform] === true;
            });
            
            // 全选需要满足:有属于选中平台的可见密钥,且这些密钥都被选中
            return filteredIds.length > 0 && 
                   filteredIds.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);
        },
        
        // 切换当前视图(有效/无效密钥)
        switchView(view) {
            if (this.currentView !== view) {
                // 保存当前视图的平台展开状态
                const currentStateKey = `platformStates_${this.currentView}`;
                localStorage.setItem(currentStateKey, JSON.stringify(this.platformStates));
                
                // 切换视图
                this.currentView = view;
                
                // 保存用户的视图选择到localStorage
                localStorage.setItem('keyView', view);
                
                // 加载新视图的平台展开状态
                const newStateKey = `platformStates_${view}`;
                const savedPlatformStates = localStorage.getItem(newStateKey);
                if (savedPlatformStates) {
                    this.platformStates = JSON.parse(savedPlatformStates);
                } else {
                    // 如果没有保存过这个视图的状态,使用默认值(全部展开)
                    const platforms = this.getPlatforms();
                    platforms.forEach(platform => {
                        this.platformStates[platform.id] = true;
                    });
                }
                
                // 重置选择状态
                this.selectedKeys = [];
                this.selectedPlatforms = [];
                
                // 重新加载API密钥数据
                this.loadApiKeys();
            }
        },
        
        // 判断密钥是否在当前视图中可见
        isKeyVisibleInCurrentView(key) {
            if (this.currentView === 'valid') {
                return key.success === true;
            } else if (this.currentView === 'invalid') {
                return key.success === false;
            }
            return true; // 默认都显示
        },
        
        // 获取所有平台
        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);
        }
    };
}