|
@@ -20,11 +20,11 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
|
const historyEndDateInput = document.getElementById('history-end-date');
|
|
const historyEndDateInput = document.getElementById('history-end-date');
|
|
|
const historySearchBtn = document.getElementById('history-search-btn');
|
|
const historySearchBtn = document.getElementById('history-search-btn');
|
|
|
const historyContainer = document.getElementById('history-container');
|
|
const historyContainer = document.getElementById('history-container');
|
|
|
- const historyLoadMoreBtn = document.getElementById('history-load-more');
|
|
|
|
|
|
|
+ const historyStats = document.getElementById('history-stats');
|
|
|
|
|
|
|
|
// 获取DOM元素 - 我的收藏模块
|
|
// 获取DOM元素 - 我的收藏模块
|
|
|
const favoriteContainer = document.getElementById('favorite-container');
|
|
const favoriteContainer = document.getElementById('favorite-container');
|
|
|
- const favoriteLoadMoreBtn = document.getElementById('favorite-load-more');
|
|
|
|
|
|
|
+ const favoriteStats = document.getElementById('favorite-stats');
|
|
|
|
|
|
|
|
// 获取DOM元素 - 出题模块
|
|
// 获取DOM元素 - 出题模块
|
|
|
const problemContent = document.getElementById('problem-content');
|
|
const problemContent = document.getElementById('problem-content');
|
|
@@ -101,11 +101,27 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
|
// 为历史记录查询按钮添加点击事件
|
|
// 为历史记录查询按钮添加点击事件
|
|
|
historySearchBtn.addEventListener('click', () => { fetchHistory(false) });
|
|
historySearchBtn.addEventListener('click', () => { fetchHistory(false) });
|
|
|
|
|
|
|
|
- // 为历史记录加载更多按钮添加点击事件
|
|
|
|
|
- historyLoadMoreBtn.addEventListener('click', () => fetchHistory(true));
|
|
|
|
|
|
|
+ // 添加滚动监听器,实现自动加载更多
|
|
|
|
|
+ document.querySelector('.history-data-container').addEventListener('scroll', function () {
|
|
|
|
|
+ const module5 = document.querySelector('.module-5');
|
|
|
|
|
+ const module6 = document.querySelector('.module-6');
|
|
|
|
|
|
|
|
- // 为收藏加载更多按钮添加点击事件
|
|
|
|
|
- favoriteLoadMoreBtn.addEventListener('click', () => fetchFavorites(true));
|
|
|
|
|
|
|
+ // 检查历史记录模块是否可见
|
|
|
|
|
+ if (module5.style.display === 'block') {
|
|
|
|
|
+ const historyStatsRect = historyStats.getBoundingClientRect();
|
|
|
|
|
+ if (historyStatsRect.top <= window.innerHeight && !isLoadingHistory && hasMoreHistory) {
|
|
|
|
|
+ fetchHistory(true);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 检查收藏模块是否可见
|
|
|
|
|
+ if (module6.style.display === 'block') {
|
|
|
|
|
+ const favoriteStatsRect = favoriteStats.getBoundingClientRect();
|
|
|
|
|
+ if (favoriteStatsRect.top <= window.innerHeight && !isLoadingFavorite && hasMoreFavorite) {
|
|
|
|
|
+ fetchFavorites(true);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// 根据题型生成题目
|
|
// 根据题型生成题目
|
|
|
let answerTimer = null;
|
|
let answerTimer = null;
|
|
@@ -243,6 +259,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ generateProblem(0)
|
|
|
// 渲染问题答案
|
|
// 渲染问题答案
|
|
|
function renderProblemAnswers(answers) {
|
|
function renderProblemAnswers(answers) {
|
|
|
if (!answers || answers.length === 0) {
|
|
if (!answers || answers.length === 0) {
|
|
@@ -537,17 +554,11 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
|
async function fetchHistory(loadMore = false) {
|
|
async function fetchHistory(loadMore = false) {
|
|
|
if (isLoadingHistory) return;
|
|
if (isLoadingHistory) return;
|
|
|
isLoadingHistory = true;
|
|
isLoadingHistory = true;
|
|
|
|
|
+ historyStats.textContent = ''
|
|
|
|
|
|
|
|
- // 如果不是加载更多,则重置状态
|
|
|
|
|
if (!loadMore) {
|
|
if (!loadMore) {
|
|
|
currentHistoryPage = 1;
|
|
currentHistoryPage = 1;
|
|
|
hasMoreHistory = true;
|
|
hasMoreHistory = true;
|
|
|
- historyContainer.innerHTML = '<div class="placeholder">正在加载历史记录...</div>';
|
|
|
|
|
- historyLoadMoreBtn.style.display = 'none';
|
|
|
|
|
- } else {
|
|
|
|
|
- // 显示加载中状态
|
|
|
|
|
- historyLoadMoreBtn.textContent = '加载中...';
|
|
|
|
|
- historyLoadMoreBtn.disabled = true;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
@@ -563,7 +574,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
|
params.append('end_date', historyEndDateInput.value);
|
|
params.append('end_date', historyEndDateInput.value);
|
|
|
}
|
|
}
|
|
|
params.append('page', currentHistoryPage.toString());
|
|
params.append('page', currentHistoryPage.toString());
|
|
|
- params.append('page_size', '5');
|
|
|
|
|
|
|
+ params.append('page_size', '10');
|
|
|
|
|
|
|
|
// 调用API获取历史记录
|
|
// 调用API获取历史记录
|
|
|
const response = await fetch(`/api/history?${params.toString()}`);
|
|
const response = await fetch(`/api/history?${params.toString()}`);
|
|
@@ -572,11 +583,10 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
|
if (response.ok && data.history) {
|
|
if (response.ok && data.history) {
|
|
|
// 渲染历史记录
|
|
// 渲染历史记录
|
|
|
renderHistoryData(data.history, historyContainer, loadMore, false);
|
|
renderHistoryData(data.history, historyContainer, loadMore, false);
|
|
|
-
|
|
|
|
|
// 更新分页状态
|
|
// 更新分页状态
|
|
|
hasMoreHistory = currentHistoryPage < data.total_pages;
|
|
hasMoreHistory = currentHistoryPage < data.total_pages;
|
|
|
- historyLoadMoreBtn.style.display = hasMoreHistory ? 'block' : 'none';
|
|
|
|
|
-
|
|
|
|
|
|
|
+ const historyRecordsStats = document.querySelector('.history-records-stats span');
|
|
|
|
|
+ historyRecordsStats.textContent = data.count
|
|
|
// 如果成功加载,增加页码
|
|
// 如果成功加载,增加页码
|
|
|
currentHistoryPage++;
|
|
currentHistoryPage++;
|
|
|
|
|
|
|
@@ -586,42 +596,33 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
if (!loadMore) {
|
|
if (!loadMore) {
|
|
|
historyContainer.innerHTML = `<div class="error">${error.message}</div>`;
|
|
historyContainer.innerHTML = `<div class="error">${error.message}</div>`;
|
|
|
|
|
+ historyStats.textContent = '加载失败';
|
|
|
} else {
|
|
} else {
|
|
|
// 显示加载失败消息
|
|
// 显示加载失败消息
|
|
|
alert('加载更多历史记录失败: ' + error.message);
|
|
alert('加载更多历史记录失败: ' + error.message);
|
|
|
}
|
|
}
|
|
|
} finally {
|
|
} finally {
|
|
|
isLoadingHistory = false;
|
|
isLoadingHistory = false;
|
|
|
- if (loadMore) {
|
|
|
|
|
- historyLoadMoreBtn.textContent = '加载更多';
|
|
|
|
|
- historyLoadMoreBtn.disabled = false;
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
// 获取收藏记录数据
|
|
// 获取收藏记录数据
|
|
|
async function fetchFavorites(loadMore = false) {
|
|
async function fetchFavorites(loadMore = false) {
|
|
|
if (isLoadingFavorite) return;
|
|
if (isLoadingFavorite) return;
|
|
|
isLoadingFavorite = true;
|
|
isLoadingFavorite = true;
|
|
|
-
|
|
|
|
|
|
|
+ favoriteStats.textContent = ''
|
|
|
// 如果不是加载更多,则重置状态
|
|
// 如果不是加载更多,则重置状态
|
|
|
if (!loadMore) {
|
|
if (!loadMore) {
|
|
|
currentFavoritePage = 1;
|
|
currentFavoritePage = 1;
|
|
|
hasMoreFavorite = true;
|
|
hasMoreFavorite = true;
|
|
|
- favoriteContainer.innerHTML = '<div class="placeholder">正在加载收藏记录...</div>';
|
|
|
|
|
- favoriteLoadMoreBtn.style.display = 'none';
|
|
|
|
|
- } else {
|
|
|
|
|
- // 显示加载中状态
|
|
|
|
|
- favoriteLoadMoreBtn.textContent = '加载中...';
|
|
|
|
|
- favoriteLoadMoreBtn.disabled = true;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
// 构建查询参数
|
|
// 构建查询参数
|
|
|
const params = new URLSearchParams();
|
|
const params = new URLSearchParams();
|
|
|
params.append('page', currentFavoritePage);
|
|
params.append('page', currentFavoritePage);
|
|
|
- params.append('page_size', 5);
|
|
|
|
|
- params.append('only_favorite', true);
|
|
|
|
|
- params.append('include_deleted', true);
|
|
|
|
|
|
|
+ params.append('page_size', "10");
|
|
|
|
|
+ params.append('only_favorite', "true");
|
|
|
|
|
+ params.append('include_deleted', "false");
|
|
|
|
|
|
|
|
// 调用API获取收藏记录
|
|
// 调用API获取收藏记录
|
|
|
const response = await fetch(`/api/history?${params.toString()}`);
|
|
const response = await fetch(`/api/history?${params.toString()}`);
|
|
@@ -632,25 +633,25 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
|
renderHistoryData(data.history, favoriteContainer, loadMore, true);
|
|
renderHistoryData(data.history, favoriteContainer, loadMore, true);
|
|
|
// 更新分页状态
|
|
// 更新分页状态
|
|
|
hasMoreFavorite = currentFavoritePage < data.total_pages;
|
|
hasMoreFavorite = currentFavoritePage < data.total_pages;
|
|
|
- favoriteLoadMoreBtn.style.display = hasMoreFavorite ? 'block' : 'none';
|
|
|
|
|
|
|
+
|
|
|
|
|
+ const favoriteRecordsStats = document.querySelector('.favorite-records-stats span');
|
|
|
|
|
+ favoriteRecordsStats.textContent = data.count
|
|
|
// 更新分页状态
|
|
// 更新分页状态
|
|
|
currentFavoritePage++;
|
|
currentFavoritePage++;
|
|
|
} else {
|
|
} else {
|
|
|
if (!loadMore) {
|
|
if (!loadMore) {
|
|
|
favoriteContainer.innerHTML = `<div class="error">${data.detail || '获取收藏记录失败'}</div>`;
|
|
favoriteContainer.innerHTML = `<div class="error">${data.detail || '获取收藏记录失败'}</div>`;
|
|
|
|
|
+ favoriteStats.textContent = '加载失败';
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.error('Error:', error);
|
|
console.error('Error:', error);
|
|
|
if (!loadMore) {
|
|
if (!loadMore) {
|
|
|
favoriteContainer.innerHTML = '<div class="error">请求失败,请检查网络连接</div>';
|
|
favoriteContainer.innerHTML = '<div class="error">请求失败,请检查网络连接</div>';
|
|
|
|
|
+ favoriteStats.textContent = '加载失败';
|
|
|
}
|
|
}
|
|
|
} finally {
|
|
} finally {
|
|
|
isLoadingFavorite = false;
|
|
isLoadingFavorite = false;
|
|
|
- if (loadMore) {
|
|
|
|
|
- favoriteLoadMoreBtn.textContent = '加载更多';
|
|
|
|
|
- favoriteLoadMoreBtn.disabled = false;
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -663,7 +664,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 构建卡片内容
|
|
// 构建卡片内容
|
|
|
- let cardsHTML = '';
|
|
|
|
|
|
|
+ let cardsHTML = ``;
|
|
|
historyItems.forEach(item => {
|
|
historyItems.forEach(item => {
|
|
|
// 格式化日期时间
|
|
// 格式化日期时间
|
|
|
const date = new Date(item.created_at);
|
|
const date = new Date(item.created_at);
|
|
@@ -827,7 +828,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
function renderHistoryAnswers(answers) {
|
|
function renderHistoryAnswers(answers) {
|
|
|
- let str=''
|
|
|
|
|
|
|
+ let str = ''
|
|
|
if (!answers || answers.length === 0) {
|
|
if (!answers || answers.length === 0) {
|
|
|
str = '<p class="placeholder">没有找到答案</p>';
|
|
str = '<p class="placeholder">没有找到答案</p>';
|
|
|
return str;
|
|
return str;
|
|
@@ -889,24 +890,6 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 为加载更多按钮添加事件监听
|
|
|
|
|
- if (historyLoadMoreBtn) {
|
|
|
|
|
- historyLoadMoreBtn.addEventListener('click', () => {
|
|
|
|
|
- if (!isLoadingHistory && hasMoreHistory) {
|
|
|
|
|
- fetchHistory(true);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 为收藏加载更多按钮添加事件监听
|
|
|
|
|
- if (favoriteLoadMoreBtn) {
|
|
|
|
|
- favoriteLoadMoreBtn.addEventListener('click', () => {
|
|
|
|
|
- if (!isLoadingFavorite && hasMoreFavorite) {
|
|
|
|
|
- fetchFavorites(true);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
// 设置日期输入框的默认值为当前日期
|
|
// 设置日期输入框的默认值为当前日期
|
|
|
const today = new Date();
|
|
const today = new Date();
|
|
|
// 计算三天前的日期
|
|
// 计算三天前的日期
|