File size: 3,472 Bytes
bbb6398
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ef8784d
 
 
 
 
bbb6398
 
 
 
 
 
 
 
 
 
ef8784d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bbb6398
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ef8784d
 
 
 
 
 
 
 
 
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
/**

 * API密钥管理器 - 平台工具模块

 * 包含与平台相关的功能函数

 */

// 切换平台折叠状态
function togglePlatform(platformId) {
    this.platformStates[platformId] = !this.platformStates[platformId];
    
    // 保存展开状态到localStorage
    localStorage.setItem('platformStates', JSON.stringify(this.platformStates));
}

// 获取平台API密钥数量
function getPlatformKeyCount(platformId, filtered = false) {
    if (filtered && this.searchTerm !== '') {
        return this.apiKeys.filter(key => 
            key.platform === platformId && 
            this.matchesSearch(key.name, key.key)
        ).length;
    }
    return this.apiKeys.filter(key => key.platform === platformId).length;
}

// 平台是否有API密钥
function hasPlatformKeys(platformId) {
    return this.getPlatformKeyCount(platformId) > 0;
}

// 平台是否应该显示(基于筛选条件)
function isPlatformVisible(platformId) {
    return this.platformFilters[platformId] === true;
}

// 获取所有平台
function getPlatforms() {
    return JSON.parse(platformsData);
}

// 获取所有平台样式配置
function getPlatformStyles() {
    return JSON.parse(platformStylesData);
}

// 获取所有平台的ID
function getPlatformIds() {
    return this.getPlatforms().map(platform => platform.id);
}

// 获取特定平台的样式
function getPlatformStyle(platformId) {
    const styles = getPlatformStyles();
    return styles[platformId] || {};
}

// 切换平台筛选状态
function togglePlatformFilter(platformId) {
    this.platformFilters[platformId] = !this.platformFilters[platformId];
    
    // 如果取消平台筛选,同时取消该平台及其下所有密钥的选择
    if (this.platformFilters[platformId] === false) {
        // 如果平台在选中列表中,移除它
        const platformIndex = this.selectedPlatforms.indexOf(platformId);
        if (platformIndex !== -1) {
            this.selectedPlatforms.splice(platformIndex, 1);
        }
        
        // 取消选中该平台下的所有密钥
        this.selectedKeys = this.selectedKeys.filter(keyId => {
            const key = this.apiKeys.find(k => k.id === keyId);
            return key && key.platform !== platformId;
        });
    }
    
    // 检查是否所有平台都被选中
    const platforms = this.getPlatforms();
    this.allPlatformsSelected = platforms.every(platform => 
        this.platformFilters[platform.id] === true
    );
    
    // 保存筛选状态到localStorage
    localStorage.setItem('platformFilters', JSON.stringify(this.platformFilters));
}

// 切换所有平台筛选状态
function toggleAllPlatformFilters() {
    const newState = !this.allPlatformsSelected;
    this.allPlatformsSelected = newState;
    
    // 将所有平台设置为相同的状态
    const platforms = this.getPlatforms();
    platforms.forEach(platform => {
        this.platformFilters[platform.id] = newState;
    });
    
    // 如果取消全部平台筛选,同时取消所有平台和密钥的选择
    if (newState === false) {
        // 清空选中的平台
        this.selectedPlatforms = [];
        
        // 清空选中的密钥
        this.selectedKeys = [];
    }
    
    // 保存筛选状态到localStorage
    localStorage.setItem('platformFilters', JSON.stringify(this.platformFilters));
}