// 配置管理功能模块 import { showToast } from './utils.js'; import { t } from './i18n.js'; let allConfigs = []; // 存储所有配置数据 let filteredConfigs = []; // 存储过滤后的配置数据 let isLoadingConfigs = false; // 防止重复加载配置 /** * 搜索配置 * @param {string} searchTerm - 搜索关键词 * @param {string} statusFilter - 状态过滤 */ function searchConfigs(searchTerm = '', statusFilter = '', providerFilter = '') { // 确保 searchTerm 是字符串,防止事件对象等非字符串被传入 if (typeof searchTerm !== 'string') { searchTerm = ''; } if (!allConfigs.length) { console.log('没有配置数据可搜索'); return; } filteredConfigs = allConfigs.filter(config => { // 搜索过滤 const matchesSearch = !searchTerm || config.name.toLowerCase().includes(searchTerm.toLowerCase()) || config.path.toLowerCase().includes(searchTerm.toLowerCase()) || (config.content && config.content.toLowerCase().includes(searchTerm.toLowerCase())); // 状态过滤 - 从布尔值 isUsed 转换为状态字符串 const configStatus = config.isUsed ? 'used' : 'unused'; const matchesStatus = !statusFilter || configStatus === statusFilter; // 提供商类型过滤 let matchesProvider = true; if (providerFilter) { const providerInfo = detectProviderFromPath(config.path); if (providerFilter === 'other') { // "其他/未识别" 选项:匹配没有识别到提供商的配置 matchesProvider = providerInfo === null; } else { // 匹配特定提供商类型 matchesProvider = providerInfo !== null && providerInfo.providerType === providerFilter; } } return matchesSearch && matchesStatus && matchesProvider; }); renderConfigList(); updateStats(); } /** * 渲染配置列表 */ function renderConfigList() { const container = document.getElementById('configList'); if (!container) return; container.innerHTML = ''; if (!filteredConfigs.length) { container.innerHTML = `
${t('upload.noConfigs')}