// 图书浏览页面脚本 $(document).ready(function() { // 分类筛选下拉菜单 $('.category-filter-toggle:not(.sort-toggle):not(.order-toggle)').click(function(e) { e.stopPropagation(); // 关闭其他可能打开的下拉菜单 $('.category-filter-dropdown').not($(this).siblings('.category-filter-dropdown')).removeClass('show'); $('.category-filter-toggle').not($(this)).removeClass('active'); $(this).toggleClass('active'); $(this).siblings('.category-filter-dropdown').toggleClass('show'); }); // 排序下拉菜单 $('.sort-toggle').click(function(e) { e.stopPropagation(); // 关闭其他可能打开的下拉菜单 $('.category-filter-dropdown').not($(this).siblings('.sort-dropdown')).removeClass('show'); $('.category-filter-toggle').not($(this)).removeClass('active'); $(this).toggleClass('active'); $(this).siblings('.sort-dropdown').toggleClass('show'); }); // 升降序下拉菜单 $('.order-toggle').click(function(e) { e.stopPropagation(); // 关闭其他可能打开的下拉菜单 $('.category-filter-dropdown').not($(this).siblings('.order-dropdown')).removeClass('show'); $('.category-filter-toggle').not($(this)).removeClass('active'); $(this).toggleClass('active'); $(this).siblings('.order-dropdown').toggleClass('show'); }); // 点击外部关闭下拉菜单 $(document).click(function(e) { if (!$(e.target).closest('.category-filters, .sort-filters, .order-filters').length) { $('.category-filter-dropdown, .sort-dropdown, .order-dropdown').removeClass('show'); $('.category-filter-toggle').removeClass('active'); } }); // 处理借阅图书 let bookIdToBorrow = null; let bookTitleToBorrow = ''; $('.borrow-book').click(function(e) { e.preventDefault(); bookIdToBorrow = $(this).data('id'); // 获取图书标题 const bookCard = $(this).closest('.book-card'); bookTitleToBorrow = bookCard.find('.book-title').text(); $('#borrowBookTitle').text(bookTitleToBorrow); $('#borrowModal').modal('show'); }); $('#confirmBorrow').click(function() { if (!bookIdToBorrow) return; // 禁用按钮防止重复提交 $(this).prop('disabled', true).html(' 处理中...'); $.ajax({ url: `/borrow/add/${bookIdToBorrow}`, type: 'POST', success: function(response) { $('#borrowModal').modal('hide'); if (response.success) { showNotification(response.message, 'success'); // 更新UI显示 const bookCard = $(`.book-card[data-id="${bookIdToBorrow}"]`); // 更改可借状态 bookCard.find('.book-ribbon span').removeClass('available').addClass('unavailable').text('已借出'); // 更改借阅按钮 bookCard.find('.btn-borrow').replaceWith(` `); // 创建借阅成功动画 const successOverlay = $('
'); bookCard.append(successOverlay); setTimeout(() => { successOverlay.fadeOut(500, function() { $(this).remove(); }); }, 2000); } else { showNotification(response.message, 'error'); } // 恢复按钮状态 $('#confirmBorrow').prop('disabled', false).html('确认借阅'); }, error: function() { $('#borrowModal').modal('hide'); showNotification('借阅操作失败,请稍后重试', 'error'); $('#confirmBorrow').prop('disabled', false).html('确认借阅'); } }); }); // 清除模态框数据 $('#borrowModal').on('hidden.bs.modal', function() { bookIdToBorrow = null; bookTitleToBorrow = ''; $('#borrowBookTitle').text(''); }); // 动态添加动画CSS const animationCSS = ` .borrow-success-overlay { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(102, 126, 234, 0.9); display: flex; flex-direction: column; align-items: center; justify-content: center; color: white; font-weight: 600; border-radius: 10px; z-index: 10; animation: fadeIn 0.3s; } .borrow-success-overlay i { font-size: 40px; margin-bottom: 10px; animation: scaleIn 0.5s; } @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } } @keyframes scaleIn { from { transform: scale(0); } to { transform: scale(1); } } `; $('