// 租户分面配置 // 根据不同的 tenant_id 配置不同的分面字段名、显示标签和容器ID const TENANT_FACETS_CONFIG = { // tenant_id=162: 使用小写的规格名称 "162": { specificationFields: [ { field: "specifications.color", label: "Color", containerId: "colorTags", size: 20, type: "terms", disjunctive: true }, { field: "specifications.size", label: "Size", containerId: "sizeTags", size: 15, type: "terms", disjunctive: true }, { field: "specifications.material", label: "Material", containerId: "materialTags", size: 10, type: "terms", disjunctive: true } ] }, // tenant_id=170: 使用首字母大写的规格名称(Color, Size),没有material "170": { specificationFields: [ { field: "specifications.Color", label: "Color", containerId: "colorTags", size: 20, type: "terms", disjunctive: true }, { field: "specifications.Size", label: "Size", containerId: "sizeTags", size: 15, type: "terms", disjunctive: true } // 示例:如果170还有其他规格,可以这样添加: // { // field: "specifications.Weight", // label: "Weight", // containerId: "weightTags", // size: 15, // type: "terms", // disjunctive: true // } ] } }; // 获取租户的分面配置 function getTenantFacetsConfig(tenantId) { // 如果没有配置,返回默认配置(使用小写) return TENANT_FACETS_CONFIG[tenantId] || { specificationFields: [ { field: "specifications.color", label: "Color", containerId: "colorTags", size: 20, type: "terms", disjunctive: true }, { field: "specifications.size", label: "Size", containerId: "sizeTags", size: 15, type: "terms", disjunctive: true }, { field: "specifications.material", label: "Material", containerId: "materialTags", size: 10, type: "terms", disjunctive: true } ] }; } // 根据字段名获取分面配置信息(用于显示) function getFacetDisplayConfig(tenantId, facetField) { const config = getTenantFacetsConfig(tenantId); // 查找匹配的规格字段配置 const specField = config.specificationFields.find(f => f.field === facetField); if (specField) { return { containerId: specField.containerId, label: specField.label, maxDisplay: 10 }; } // 类目字段的固定配置 const categoryConfigs = { 'category1_name': { containerId: 'category1Tags', label: 'Category', maxDisplay: 10 }, 'category2_name': { containerId: 'category2Tags', label: 'Sub Category', maxDisplay: 10 }, 'category3_name': { containerId: 'category3Tags', label: 'Third Category', maxDisplay: 10 } }; return categoryConfigs[facetField] || null; } // 获取所有已配置的 tenant_id 列表 function getAvailableTenantIds() { try { if (typeof TENANT_FACETS_CONFIG === 'undefined') { console.error('TENANT_FACETS_CONFIG is not defined'); return []; } if (!TENANT_FACETS_CONFIG || typeof TENANT_FACETS_CONFIG !== 'object') { console.error('TENANT_FACETS_CONFIG is invalid:', typeof TENANT_FACETS_CONFIG); return []; } const keys = Object.keys(TENANT_FACETS_CONFIG); console.log('TENANT_FACETS_CONFIG keys:', keys, 'Config:', TENANT_FACETS_CONFIG); return keys; } catch (e) { console.error('Error in getAvailableTenantIds:', e); return []; } }