/** * 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); } // 获取特定平台的样式 function getPlatformStyle(platformId) { const styles = getPlatformStyles(); return styles[platformId] || {}; } // 切换平台筛选状态 function togglePlatformFilter(platformId) { this.platformFilters[platformId] = !this.platformFilters[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; }); // 保存筛选状态到localStorage localStorage.setItem('platformFilters', JSON.stringify(this.platformFilters)); }