diff --git a/src/main/resources/static/js/app.js b/src/main/resources/static/js/app.js index fd835db..096919e 100644 --- a/src/main/resources/static/js/app.js +++ b/src/main/resources/static/js/app.js @@ -132,21 +132,9 @@ const App = (function() { navigate('#/' + page); }); - // 返回按钮 + // 返回按钮 - 使用浏览器历史返回 $('#btn-back').on('click', function() { - // 如果有历史记录就返回,否则跳转到书架 - if (window.history.length > 1) { - const currentHash = window.location.hash; - window.history.back(); - // 检查是否真的返回了,如果没有就跳转到书架 - setTimeout(() => { - if (window.location.hash === currentHash) { - navigate('#/shelf'); - } - }, 100); - } else { - navigate('#/shelf'); - } + window.history.back(); }); // 搜索按钮 @@ -241,15 +229,29 @@ const App = (function() { } }); - // 小说卡片点击(包括搜索结果中的) + // 搜索结果中的小说卡片点击(优先处理) + $(document).on('click', '#search-results .novel-card', function(e) { + e.preventDefault(); + e.stopPropagation(); + const novelId = $(this).data('novel-id'); + if (novelId) { + hideSearch(); + // 使用setTimeout确保搜索面板完全隐藏后再跳转 + setTimeout(() => { + navigate('#/novel/' + novelId); + }, 100); + } + }); + + // 其他页面的小说卡片点击 $(document).on('click', '.novel-card, .novel-grid-card, .shelf-item', function(e) { + // 如果是搜索结果中的,上面的事件已处理,这里跳过 + if ($(this).closest('#search-results').length) return; + + e.preventDefault(); if ($(e.target).closest('button').length) return; const novelId = $(this).data('novel-id') || $(this).closest('[data-novel-id]').data('novel-id'); if (novelId) { - // 如果在搜索面板中,先关闭搜索面板 - if ($('#search-panel').is(':visible')) { - hideSearch(); - } navigate('#/novel/' + novelId); } });