File size: 3,250 Bytes
bbb6398
 
 
 
 
 
 
 
 
ef8784d
 
 
2809c18
 
 
 
 
 
 
 
 
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
86
87
88
89
90
91
/**

 * API密钥管理器 - 核心模块

 * 包含数据状态定义和初始化功能

 */

function initApiKeyManager() {
    // 初始化各平台的折叠状态和筛选状态
    const platforms = JSON.parse(platformsData);
    
    // 初始化平台ID列表
    this.platformIds = platforms.map(platform => platform.id);
    
    // 从localStorage读取当前视图状态,如果有的话
    const savedView = localStorage.getItem('keyView');
    if (savedView === 'valid' || savedView === 'invalid') {
        this.currentView = savedView;
    }
    
    // 从localStorage读取对应视图的平台展开状态,如果有的话
    const stateKey = `platformStates_${this.currentView}`;
    const savedPlatformStates = localStorage.getItem(stateKey);
    const parsedPlatformStates = savedPlatformStates ? JSON.parse(savedPlatformStates) : {};
    
    // 从localStorage读取平台筛选状态,如果有的话
    const savedPlatformFilters = localStorage.getItem('platformFilters');
    const parsedPlatformFilters = savedPlatformFilters ? JSON.parse(savedPlatformFilters) : {};
    
    
    // 初始化平台状态,优先使用保存的状态
    platforms.forEach(platform => {
        this.platformStates[platform.id] = parsedPlatformStates[platform.id] !== undefined 
            ? parsedPlatformStates[platform.id] 
            : true;
        
        this.platformFilters[platform.id] = parsedPlatformFilters[platform.id] !== undefined 
            ? parsedPlatformFilters[platform.id] 
            : true;
    });
    
    // 检查是否所有平台都被选中
    this.allPlatformsSelected = platforms.every(platform => 
        this.platformFilters[platform.id] === true
    );
    
    // 加载API密钥
    this.loadApiKeys();
    
    // 初始化剪贴板JS
    new ClipboardJS('[data-clipboard-text]');
    
    // 设置平台类型为上次选择的值(如果有)
    const lastPlatform = localStorage.getItem('lastSelectedPlatform');
    if (lastPlatform) {
        this.newKey.platform = lastPlatform;
    }
    
    // 这里不再恢复搜索词状态,只保留平台状态和页面位置
    
    // 监听来自快捷键的打开模态框事件
    window.addEventListener('open-add-modal', () => {
        this.showAddModal = true;
        // 聚焦到平台选择框,方便用户立即操作
        setTimeout(() => {
            document.getElementById('platform').focus();
        }, 100);
    });
    
    // 监听模态框内的键盘事件
    document.addEventListener('keydown', (e) => {
        // Alt+Enter 提交表单
        if (e.altKey && e.key === 'Enter') {
            if (this.showAddModal) {
                e.preventDefault();
                this.addApiKey();
            } else if (this.showEditModal) {
                e.preventDefault();
                this.updateApiKey();
            }
        }
        
        // Esc 关闭模态框
        if (e.key === 'Escape') {
            if (this.showAddModal) {
                this.showAddModal = false;
            } else if (this.showEditModal) {
                this.showEditModal = false;
            }
        }
    });
}