上课记录查询完整展示结果
This commit is contained in:
@@ -38,14 +38,17 @@ def records(
|
|||||||
q: str = Query(..., min_length=1, description="自然语言查询,例如:王鑫鹏5月数学课"),
|
q: str = Query(..., min_length=1, description="自然语言查询,例如:王鑫鹏5月数学课"),
|
||||||
limit: int = Query(30, ge=1, le=1000),
|
limit: int = Query(30, ge=1, le=1000),
|
||||||
offset: int = Query(0, ge=0),
|
offset: int = Query(0, ge=0),
|
||||||
|
show_all: bool = Query(False, alias="all"),
|
||||||
_user: str = Depends(verify_records_auth),
|
_user: str = Depends(verify_records_auth),
|
||||||
):
|
):
|
||||||
|
effective_limit = 0 if show_all else limit
|
||||||
|
effective_offset = 0 if show_all else offset
|
||||||
return query_public_records(
|
return query_public_records(
|
||||||
load_records(),
|
load_records(),
|
||||||
load_teachers(),
|
load_teachers(),
|
||||||
q,
|
q,
|
||||||
limit=limit,
|
limit=effective_limit,
|
||||||
offset=offset,
|
offset=effective_offset,
|
||||||
summaries_root=COURSE_SUMMARIES_ROOT,
|
summaries_root=COURSE_SUMMARIES_ROOT,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+6
-52
@@ -43,7 +43,6 @@ const submitSummarySupplementBtn = document.querySelector("#submitSummarySupplem
|
|||||||
const WEEKDAYS = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
|
const WEEKDAYS = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
|
||||||
const COPY_LINE_BREAK = "\r\n";
|
const COPY_LINE_BREAK = "\r\n";
|
||||||
const SORT_DIRECTIONS = { asc: 1, desc: -1 };
|
const SORT_DIRECTIONS = { asc: 1, desc: -1 };
|
||||||
const RECORD_PAGE_SIZE = 30;
|
|
||||||
const RECORD_TABLE_COLUMN_COUNT = 8;
|
const RECORD_TABLE_COLUMN_COUNT = 8;
|
||||||
let currentRecords = [];
|
let currentRecords = [];
|
||||||
let recordSort = { date: "asc", time: "asc" };
|
let recordSort = { date: "asc", time: "asc" };
|
||||||
@@ -53,7 +52,7 @@ let correctedRecordOrder = [];
|
|||||||
let expandedSummaryRecords = new Set();
|
let expandedSummaryRecords = new Set();
|
||||||
let expandedSummaryBodies = new Set();
|
let expandedSummaryBodies = new Set();
|
||||||
let collapsedTeacherGroups = new Set();
|
let collapsedTeacherGroups = new Set();
|
||||||
let currentRecordPage = { query: "", offset: 0, limit: RECORD_PAGE_SIZE, total: 0, shown: 0, hasMore: false };
|
let currentRecordPage = { query: "", offset: 0, limit: 0, total: 0, shown: 0, hasMore: false };
|
||||||
let activeCorrectionKey = "";
|
let activeCorrectionKey = "";
|
||||||
let activeDeleteKey = "";
|
let activeDeleteKey = "";
|
||||||
let activeSummarySupplementKey = "";
|
let activeSummarySupplementKey = "";
|
||||||
@@ -91,42 +90,11 @@ function metricHtml(label, valueHtml) {
|
|||||||
return `<div class="metric"><span>${escapeHtml(label)}</span><strong>${valueHtml}</strong></div>`;
|
return `<div class="metric"><span>${escapeHtml(label)}</span><strong>${valueHtml}</strong></div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function currentPageNumber(state) {
|
|
||||||
return Math.floor((state.offset || 0) / (state.limit || RECORD_PAGE_SIZE)) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function totalPageNumber(state) {
|
|
||||||
const limit = state.limit || RECORD_PAGE_SIZE;
|
|
||||||
return Math.max(1, Math.ceil((state.total || 0) / limit));
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderPager(container, state) {
|
|
||||||
if (!container) return;
|
|
||||||
const total = Number(state.total || 0);
|
|
||||||
const shown = Number(state.shown || 0);
|
|
||||||
const limit = Number(state.limit || RECORD_PAGE_SIZE);
|
|
||||||
const offset = Number(state.offset || 0);
|
|
||||||
if (total <= limit && offset === 0) {
|
|
||||||
container.hidden = true;
|
|
||||||
container.innerHTML = "";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const start = shown ? offset + 1 : 0;
|
|
||||||
const end = offset + shown;
|
|
||||||
container.hidden = false;
|
|
||||||
container.innerHTML = `<div class="pager-info">第 ${currentPageNumber(state)} / ${totalPageNumber(state)} 页 · ${start}-${end} / ${total} 条</div>
|
|
||||||
<div class="pager-actions">
|
|
||||||
<button class="secondary-button pager-prev" type="button" ${offset <= 0 ? "disabled" : ""}>上一页</button>
|
|
||||||
<button class="secondary-button pager-next" type="button" ${state.hasMore ? "" : "disabled"}>下一页</button>
|
|
||||||
</div>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function pageRangeText(state) {
|
function pageRangeText(state) {
|
||||||
const total = Number(state.total || 0);
|
const total = Number(state.total || 0);
|
||||||
const shown = Number(state.shown || 0);
|
const shown = Number(state.shown || 0);
|
||||||
const offset = Number(state.offset || 0);
|
|
||||||
if (!total || !shown) return "0 条";
|
if (!total || !shown) return "0 条";
|
||||||
return `${offset + 1}-${offset + shown} 条`;
|
return `${shown} 条`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeRecordKey(row, index) {
|
function makeRecordKey(row, index) {
|
||||||
@@ -792,7 +760,6 @@ async function loadHealth() {
|
|||||||
async function queryRecords(query, options = {}) {
|
async function queryRecords(query, options = {}) {
|
||||||
const q = query.trim();
|
const q = query.trim();
|
||||||
if (!q) return;
|
if (!q) return;
|
||||||
const offset = Number(options.offset || 0);
|
|
||||||
recordRows.innerHTML = `<tr><td colspan="${RECORD_TABLE_COLUMN_COUNT}" class="empty">正在查询</td></tr>`;
|
recordRows.innerHTML = `<tr><td colspan="${RECORD_TABLE_COLUMN_COUNT}" class="empty">正在查询</td></tr>`;
|
||||||
recordMeta.innerHTML = "";
|
recordMeta.innerHTML = "";
|
||||||
if (recordPager) {
|
if (recordPager) {
|
||||||
@@ -811,13 +778,13 @@ async function queryRecords(query, options = {}) {
|
|||||||
collapsedTeacherGroups = new Set();
|
collapsedTeacherGroups = new Set();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const params = new URLSearchParams({ q, limit: String(RECORD_PAGE_SIZE), offset: String(offset) });
|
const params = new URLSearchParams({ q, all: "1" });
|
||||||
const data = await fetchJson(`/api/records?${params.toString()}`);
|
const data = await fetchJson(`/api/records?${params.toString()}`);
|
||||||
const summary = data.summary;
|
const summary = data.summary;
|
||||||
currentRecordPage = {
|
currentRecordPage = {
|
||||||
query: q,
|
query: q,
|
||||||
offset: data.offset || offset,
|
offset: data.offset || 0,
|
||||||
limit: data.limit || RECORD_PAGE_SIZE,
|
limit: data.limit || 0,
|
||||||
total: data.total_records || 0,
|
total: data.total_records || 0,
|
||||||
shown: data.shown_records || (data.records || []).length,
|
shown: data.shown_records || (data.records || []).length,
|
||||||
hasMore: Boolean(data.has_more),
|
hasMore: Boolean(data.has_more),
|
||||||
@@ -825,7 +792,7 @@ async function queryRecords(query, options = {}) {
|
|||||||
recordMeta.innerHTML = [
|
recordMeta.innerHTML = [
|
||||||
metric("识别日期", data.query.date_range),
|
metric("识别日期", data.query.date_range),
|
||||||
metric("命中记录", `${summary.count} 条`),
|
metric("命中记录", `${summary.count} 条`),
|
||||||
metric("当前显示", pageRangeText(currentRecordPage)),
|
metric("完整展示", pageRangeText(currentRecordPage)),
|
||||||
metric("总课时", displayHours(summary.total_hours, summary.total_duration)),
|
metric("总课时", displayHours(summary.total_hours, summary.total_duration)),
|
||||||
metric("授课老师", `${Object.keys(summary.teachers || {}).length} 位`),
|
metric("授课老师", `${Object.keys(summary.teachers || {}).length} 位`),
|
||||||
].join("");
|
].join("");
|
||||||
@@ -836,7 +803,6 @@ async function queryRecords(query, options = {}) {
|
|||||||
|
|
||||||
if (!data.records.length) {
|
if (!data.records.length) {
|
||||||
recordRows.innerHTML = `<tr><td colspan="${RECORD_TABLE_COLUMN_COUNT}" class="empty">未找到符合条件的上课记录</td></tr>`;
|
recordRows.innerHTML = `<tr><td colspan="${RECORD_TABLE_COLUMN_COUNT}" class="empty">未找到符合条件的上课记录</td></tr>`;
|
||||||
renderPager(recordPager, currentRecordPage);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -846,7 +812,6 @@ async function queryRecords(query, options = {}) {
|
|||||||
_recordKey: makeRecordKey(row, currentRecordPage.offset + index),
|
_recordKey: makeRecordKey(row, currentRecordPage.offset + index),
|
||||||
}));
|
}));
|
||||||
recordRows.innerHTML = renderGroupedRecords(currentRecords);
|
recordRows.innerHTML = renderGroupedRecords(currentRecords);
|
||||||
renderPager(recordPager, currentRecordPage);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
recordRows.innerHTML = `<tr><td colspan="${RECORD_TABLE_COLUMN_COUNT}" class="empty">查询失败:${escapeHtml(error.message)}</td></tr>`;
|
recordRows.innerHTML = `<tr><td colspan="${RECORD_TABLE_COLUMN_COUNT}" class="empty">查询失败:${escapeHtml(error.message)}</td></tr>`;
|
||||||
}
|
}
|
||||||
@@ -912,17 +877,6 @@ recordRows.addEventListener("keydown", (event) => {
|
|||||||
toggleRecordSummary(row.dataset.recordKey);
|
toggleRecordSummary(row.dataset.recordKey);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (recordPager) {
|
|
||||||
recordPager.addEventListener("click", (event) => {
|
|
||||||
const previous = event.target.closest(".pager-prev");
|
|
||||||
const next = event.target.closest(".pager-next");
|
|
||||||
if (!previous && !next) return;
|
|
||||||
const delta = previous ? -currentRecordPage.limit : currentRecordPage.limit;
|
|
||||||
const nextOffset = Math.max(0, currentRecordPage.offset + delta);
|
|
||||||
queryRecords(currentRecordPage.query || recordQuery.value, { offset: nextOffset, reset: false });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[correctionDate, correctionTime, correctionStudent, correctionTeacher, correctionSubject].forEach((input) => {
|
[correctionDate, correctionTime, correctionStudent, correctionTeacher, correctionSubject].forEach((input) => {
|
||||||
input.addEventListener("input", updateCorrectionPreview);
|
input.addEventListener("input", updateCorrectionPreview);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user