/** * 侧边栏自动替换脚本 * 自动检测并替换旧的导航栏为侧边栏 */ (function() { 'use strict'; // 侧边栏CSS const sidebarCSS = ` .sidebar { position: fixed; top: 0; left: 0; width: 260px; height: 100vh; background: linear-gradient(180deg, #2c3e50 0%, #34495e 100%); color: #fff; z-index: 1000; display: flex; flex-direction: column; transition: transform 0.3s ease; box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1); } .sidebar-header { padding: 1.5rem; border-bottom: 1px solid rgba(255, 255, 255, 0.1); display: flex; justify-content: space-between; align-items: center; } .sidebar-brand { font-size: 1.25rem; font-weight: 600; } .sidebar-nav { flex: 1; overflow-y: auto; padding: 1rem 0; } .sidebar-nav .nav-link { color: rgba(255, 255, 255, 0.8); padding: 0.75rem 1.5rem; transition: all 0.3s; border-left: 3px solid transparent; display: flex; align-items: center; text-decoration: none; } .sidebar-nav .nav-link:hover { background-color: rgba(255, 255, 255, 0.1); color: #fff; border-left-color: #0d6efd; } .sidebar-nav .nav-link.active { background-color: rgba(13, 110, 253, 0.2); color: #fff; border-left-color: #0d6efd; font-weight: 600; } .sidebar-nav .nav-link i { width: 24px; font-size: 1.1rem; margin-right: 0.75rem; } .sidebar-nav .nav-text { flex: 1; } .sidebar-footer { padding: 1rem; border-top: 1px solid rgba(255, 255, 255, 0.1); } @media (max-width: 767.98px) { .sidebar { transform: translateX(-100%); } .sidebar.show { transform: translateX(0); } .sidebar-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0, 0, 0, 0.5); z-index: 1049; display: none; transition: opacity 0.3s; } .sidebar-overlay.show { display: block; } .top-navbar { position: fixed; top: 0; left: 0; right: 0; height: 56px; background: linear-gradient(180deg, #2c3e50 0%, #34495e 100%); z-index: 1048; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); } body { padding-top: 56px; } } @media (min-width: 768px) { .main-content { margin-left: 260px; min-height: 100vh; position: relative; z-index: 1; width: calc(100% - 260px); } } .sidebar-nav::-webkit-scrollbar { width: 6px; } .sidebar-nav::-webkit-scrollbar-track { background: rgba(255, 255, 255, 0.05); } .sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.2); border-radius: 3px; } .sidebar-nav::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.3); } `; // 菜单配置 const menuConfig = [ { href: '/merchant/dashboard.html', icon: 'bi-speedometer2', text: '首页', page: 'dashboard' }, { href: '/merchant/products.html', icon: 'bi-box-seam', text: '商品管理', page: 'products' }, { href: '/merchant/orders.html', icon: 'bi-receipt-cutoff', text: '订单管理', page: 'orders' }, { href: '/merchant/inventory.html', icon: 'bi-archive', text: '库存管理', page: 'inventory' }, { href: '/merchant/statistics.html', icon: 'bi-bar-chart-line', text: '数据统计', page: 'statistics' }, { href: '/merchant/announcements.html', icon: 'bi-megaphone', text: '公告管理', page: 'announcements' }, { href: '/merchant/messages.html', icon: 'bi-chat-dots', text: '留言管理', page: 'messages' }, { href: '/merchant/reviews.html', icon: 'bi-star', text: '评价管理', page: 'reviews' }, { href: '/merchant/users.html', icon: 'bi-people', text: '用户管理', page: 'users' } ]; // 检测当前页面 function detectCurrentPage() { const path = window.location.pathname; for (const item of menuConfig) { if (path.includes(item.page)) { return item.page; } } return 'dashboard'; } // 生成侧边栏HTML function generateSidebar(activePage) { const menuHTML = menuConfig.map(item => { const activeClass = item.page === activePage ? 'active' : ''; return `