(tabName)
| 957 | }); |
| 958 | |
| 959 | function switchTab(tabName) { |
| 960 | // 获取当前活动的内容区域 |
| 961 | const currentContent = document.querySelector('.tab-content.active'); |
| 962 | const targetContent = document.getElementById(tabName + 'Tab'); |
| 963 | |
| 964 | // 如果点击的是当前标签页,不做任何操作 |
| 965 | if (currentContent === targetContent) return; |
| 966 | |
| 967 | // 找到目标标签按钮 |
| 968 | const targetTab = event && event.target ? event.target : |
| 969 | document.querySelector(`.tab[onclick*="'${tabName}'"]`); |
| 970 | |
| 971 | // 移除所有标签页的active状态 |
| 972 | document.querySelectorAll('.tab').forEach(tab => tab.classList.remove('active')); |
| 973 | |
| 974 | // 添加当前点击标签的active状态 |
| 975 | if (targetTab) { |
| 976 | targetTab.classList.add('active'); |
| 977 | // 更新滑块位置(带动画) |
| 978 | updateTabSlider(targetTab, true); |
| 979 | } |
| 980 | |
| 981 | // 淡出当前内容 |
| 982 | if (currentContent) { |
| 983 | // 设置淡出过渡 |
| 984 | currentContent.style.transition = 'opacity 0.18s ease-out, transform 0.18s ease-out'; |
| 985 | currentContent.style.opacity = '0'; |
| 986 | currentContent.style.transform = 'translateX(-12px)'; |
| 987 | |
| 988 | setTimeout(() => { |
| 989 | currentContent.classList.remove('active'); |
| 990 | currentContent.style.transition = ''; |
| 991 | currentContent.style.opacity = ''; |
| 992 | currentContent.style.transform = ''; |
| 993 | |
| 994 | // 淡入新内容 |
| 995 | if (targetContent) { |
| 996 | // 先设置初始状态(在添加 active 类之前) |
| 997 | targetContent.style.opacity = '0'; |
| 998 | targetContent.style.transform = 'translateX(12px)'; |
| 999 | targetContent.style.transition = 'none'; // 暂时禁用过渡 |
| 1000 | |
| 1001 | // 添加 active 类使元素可见 |
| 1002 | targetContent.classList.add('active'); |
| 1003 | |
| 1004 | // 使用双重 requestAnimationFrame 确保浏览器完成重绘 |
| 1005 | requestAnimationFrame(() => { |
| 1006 | requestAnimationFrame(() => { |
| 1007 | // 启用过渡并应用最终状态 |
| 1008 | targetContent.style.transition = 'opacity 0.25s ease-out, transform 0.25s ease-out'; |
| 1009 | targetContent.style.opacity = '1'; |
| 1010 | targetContent.style.transform = 'translateX(0)'; |
| 1011 | |
| 1012 | // 清理内联样式并执行数据加载 |
| 1013 | setTimeout(() => { |
| 1014 | targetContent.style.transition = ''; |
| 1015 | targetContent.style.opacity = ''; |
| 1016 | targetContent.style.transform = ''; |
nothing calls this directly
no test coverage detected