feat: 添加分页功能和缓存管理,优化问答记录展示
This commit is contained in:
+12
-1
@@ -13,6 +13,9 @@ import { AnswerService } from "@/services";
|
||||
/** Dashboard 最近记录表格每页数量,组件直接复用,避免多个地方写死 */
|
||||
export const DASHBOARD_RECORD_PAGE_SIZE = 10;
|
||||
|
||||
/** 分页大小可选列表,与后端白名单保持一致 */
|
||||
export const DASHBOARD_PAGE_SIZE_OPTIONS = [10, 50, 100] as const;
|
||||
|
||||
/** 题型下拉选项,value 保持 OCS / 旧 Python 服务使用的英文值 */
|
||||
export const QUESTION_TYPE_OPTIONS: Array<{
|
||||
label: string;
|
||||
@@ -104,6 +107,13 @@ export const useAnswerStore = defineStore("answer", () => {
|
||||
await getRecords(page);
|
||||
};
|
||||
|
||||
/** 切换分页大小,重置到第 1 页后重新请求 */
|
||||
const setRecordsPageSize = async (size: number) => {
|
||||
if (recordsLoading.value || size === recordsPageSize.value) return;
|
||||
recordsPageSize.value = size;
|
||||
await getRecords(1);
|
||||
};
|
||||
|
||||
/** 调用答题 API,返回 OCS 兼容结构但只在 store 中维护 UI 状态 */
|
||||
const searchAnswer = async () => {
|
||||
const title = question.value.trim();
|
||||
@@ -245,6 +255,7 @@ export const useAnswerStore = defineStore("answer", () => {
|
||||
loadDashboard,
|
||||
clearCache,
|
||||
selectRecord,
|
||||
setRecordsPage
|
||||
setRecordsPage,
|
||||
setRecordsPageSize
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user