bugfix: 一些bug修复
This commit is contained in:
+19
-22
@@ -82,16 +82,11 @@ export const useAnswerStore = defineStore("answer", () => {
|
||||
const cacheClearing = ref(false);
|
||||
const recordsPage = ref(1);
|
||||
const recordsPageSize = ref(DASHBOARD_RECORD_PAGE_SIZE);
|
||||
const recordCount = ref(0);
|
||||
const selectedRecord = ref<IQaRecord>();
|
||||
|
||||
/** Dashboard 表格当前页数据,分页只作用在前端的最近 100 条内存记录上 */
|
||||
const pagedRecords = computed(() => {
|
||||
const start = (recordsPage.value - 1) * recordsPageSize.value;
|
||||
return records.value.slice(start, start + recordsPageSize.value);
|
||||
});
|
||||
|
||||
/** 表格总数,用于 TableCom 分页器 */
|
||||
const recordCount = computed(() => records.value.length);
|
||||
/** Dashboard 表格当前页数据,页码切换会重新请求服务端分页接口 */
|
||||
const pagedRecords = computed(() => records.value);
|
||||
|
||||
/** Dashboard 顶部运行时长展示 */
|
||||
const uptimeText = computed(() => {
|
||||
@@ -103,9 +98,10 @@ export const useAnswerStore = defineStore("answer", () => {
|
||||
selectedRecord.value = record;
|
||||
};
|
||||
|
||||
/** 切换最近记录表格页码 */
|
||||
const setRecordsPage = (page: number) => {
|
||||
recordsPage.value = page;
|
||||
/** 切换最近记录表格页码,并请求对应页数据 */
|
||||
const setRecordsPage = async (page: number) => {
|
||||
if (recordsLoading.value || page === recordsPage.value) return;
|
||||
await getRecords(page);
|
||||
};
|
||||
|
||||
/** 调用答题 API,返回 OCS 兼容结构但只在 store 中维护 UI 状态 */
|
||||
@@ -131,6 +127,7 @@ export const useAnswerStore = defineStore("answer", () => {
|
||||
|
||||
if (res.data.code === 1) {
|
||||
answerResult.value = res.data;
|
||||
recordsPage.value = 1;
|
||||
await Promise.allSettled([getStats(), getRecords()]);
|
||||
return;
|
||||
}
|
||||
@@ -172,18 +169,18 @@ export const useAnswerStore = defineStore("answer", () => {
|
||||
}
|
||||
};
|
||||
|
||||
/** 读取最近问答记录,并在数量变少时把页码拉回合法范围 */
|
||||
const getRecords = async () => {
|
||||
/** 读取最近问答记录;服务端按 page/size 返回当前页数据 */
|
||||
const getRecords = async (page = recordsPage.value) => {
|
||||
recordsLoading.value = true;
|
||||
try {
|
||||
const res = await AnswerService.getRecords();
|
||||
const res = await AnswerService.getRecords({
|
||||
page,
|
||||
size: recordsPageSize.value
|
||||
});
|
||||
records.value = res.data.records;
|
||||
|
||||
const maxPage = Math.max(
|
||||
1,
|
||||
Math.ceil(records.value.length / recordsPageSize.value)
|
||||
);
|
||||
if (recordsPage.value > maxPage) recordsPage.value = maxPage;
|
||||
recordsPage.value = res.data.page;
|
||||
recordsPageSize.value = res.data.size;
|
||||
recordCount.value = res.data.total;
|
||||
} catch (error) {
|
||||
dashboardErrorMessage.value = getClientErrorMessage(
|
||||
error,
|
||||
@@ -200,7 +197,7 @@ export const useAnswerStore = defineStore("answer", () => {
|
||||
await Promise.allSettled([getHealth(), getStats(), getRecords()]);
|
||||
};
|
||||
|
||||
/** 清空缓存后刷新统计;问答记录不会被清空,保持旧服务语义 */
|
||||
/** 清空缓存和问答记录后刷新统计与表格 */
|
||||
const clearCache = async () => {
|
||||
cacheClearing.value = true;
|
||||
dashboardErrorMessage.value = "";
|
||||
@@ -210,7 +207,7 @@ export const useAnswerStore = defineStore("answer", () => {
|
||||
if (!res.data.success) {
|
||||
dashboardErrorMessage.value = res.data.message;
|
||||
}
|
||||
await getStats();
|
||||
await Promise.allSettled([getStats(), getRecords(1)]);
|
||||
} catch (error) {
|
||||
dashboardErrorMessage.value = getClientErrorMessage(
|
||||
error,
|
||||
|
||||
Reference in New Issue
Block a user