File size: 4,765 Bytes
bbb6398
 
 
 
 
 
 
 
 
2809c18
 
 
bbb6398
 
 
 
834bfcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bbb6398
 
834bfcd
bbb6398
 
 
 
834bfcd
bbb6398
834bfcd
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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
/**

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

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

 */

// 切换平台折叠状态
function togglePlatform(platformId) {
    this.platformStates[platformId] = !this.platformStates[platformId];
    
    // 保存展开状态到localStorage - 分开存储不同视图的状态
    const stateKey = `platformStates_${this.currentView}`;
    localStorage.setItem(stateKey, JSON.stringify(this.platformStates));
}

// 获取平台API密钥数量
function getPlatformKeyCount(platformId, filtered = false) {
    return this.apiKeys.filter(key => {
        // 基础过滤 - 匹配平台
        if (key.platform !== platformId) return false;
        
        // 视图过滤
        if (this.currentView === 'valid' && key.success !== true) return false;
        if (this.currentView === 'invalid' && key.success !== false) return false;
        
        // 搜索过滤
        if (filtered && this.searchTerm !== '' && !this.matchesSearch(key.name, key.key)) return false;
        
        return true;
    }).length;
}

// 获取平台有效API密钥数量
function getPlatformValidKeyCount(platformId) {
    return this.apiKeys.filter(key => 
        key.platform === platformId && key.success === true
    ).length;
}

// 获取平台无效API密钥数量
function getPlatformInvalidKeyCount(platformId) {
    return this.apiKeys.filter(key => 
        key.platform === platformId && key.success === false
    ).length;
}

// 平台是否有API密钥(考虑当前视图状态)
function hasPlatformKeys(platformId) {
    return this.getPlatformKeyCount(platformId) > 0;
}

// 平台是否应该显示(基于筛选条件和当前视图状态)
function isPlatformVisible(platformId) {
    // 首先检查平台是否在筛选条件中
    if (this.platformFilters[platformId] !== true) {
        return false;
    }
    
    // 然后检查当前视图下该平台是否有密钥
    const hasKeysInCurrentView = this.apiKeys.some(key => {
        if (key.platform !== platformId) return false;
        if (this.currentView === 'valid' && key.success !== true) return false;
        if (this.currentView === 'invalid' && key.success !== false) return false;
        return true;
    });
    
    return hasKeysInCurrentView;
}

// 获取所有平台
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));
}