This repository has been archived on 2026-06-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
wsh5485 c64651d6c7 feat(移动端): 添加移动端导航菜单并优化响应式设计
refactor(预约统计): 修改查询逻辑只计算有效预约
2025-12-12 03:39:01 +08:00

84 lines
2.8 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 移动端导航菜单控制
function toggleMobileMenu() {
const toggle = document.querySelector('.mobile-menu-toggle');
const overlay = document.querySelector('.mobile-nav-overlay');
const nav = document.querySelector('.mobile-nav');
if (!toggle || !overlay || !nav) return;
toggle.classList.toggle('active');
overlay.classList.toggle('active');
nav.classList.toggle('active');
document.body.style.overflow = nav.classList.contains('active') ? 'hidden' : '';
}
function closeMobileMenu() {
const toggle = document.querySelector('.mobile-menu-toggle');
const overlay = document.querySelector('.mobile-nav-overlay');
const nav = document.querySelector('.mobile-nav');
if (!toggle || !overlay || !nav) return;
toggle.classList.remove('active');
overlay.classList.remove('active');
nav.classList.remove('active');
document.body.style.overflow = '';
}
// 页面加载完成后初始化
document.addEventListener('DOMContentLoaded', function() {
// 点击导航链接后关闭菜单
const mobileNavLinks = document.querySelectorAll('.mobile-nav .nav-link');
mobileNavLinks.forEach(link => {
link.addEventListener('click', closeMobileMenu);
});
// 点击遮罩层关闭菜单
const overlay = document.querySelector('.mobile-nav-overlay');
if (overlay) {
overlay.addEventListener('click', closeMobileMenu);
}
// ESC键关闭菜单
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
closeMobileMenu();
}
});
// 防止双击缩放(iOS Safari
let lastTouchEnd = 0;
document.addEventListener('touchend', function(event) {
const now = Date.now();
if (now - lastTouchEnd <= 300) {
event.preventDefault();
}
lastTouchEnd = now;
}, false);
// 优化触摸反馈
document.addEventListener('touchstart', function(e) {
const target = e.target;
if (target.classList.contains('btn') ||
target.classList.contains('time-slot') ||
target.classList.contains('calendar-day') ||
target.classList.contains('nav-link')) {
target.style.transition = 'transform 0.1s';
target.style.transform = 'scale(0.97)';
}
}, { passive: true });
document.addEventListener('touchend', function(e) {
const target = e.target;
if (target.classList.contains('btn') ||
target.classList.contains('time-slot') ||
target.classList.contains('calendar-day') ||
target.classList.contains('nav-link')) {
setTimeout(() => {
target.style.transform = '';
}, 100);
}
}, { passive: true });
});