feat: 复习总览改用范围入口并移除标签导图旧块

This commit is contained in:
2026-11-20 17:55:27 +08:00
parent 7627f0651d
commit 469e8eb5e1
28 changed files with 1164 additions and 952 deletions
+188 -52
View File
@@ -1,68 +1,204 @@
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { listRecalls, type RecallSummary } from '@/api/recalls';
import { formatDateTime, formatDurationMs } from '@/utils/format';
import { useDelayedVisible } from './composables/useDelayedVisible';
const route = useRoute();
const router = useRouter();
const open = ref(route.query.history === 'open');
import { computed, onMounted, ref } from "vue";
import { listRecalls, type RecallSummary } from "@/api/recalls";
import { useDelayedVisible } from "./composables/useDelayedVisible";
import ReviewRecallRow from "./ReviewRecallRow.vue";
const props = withDefaults(defineProps<{ excludeRecallNum?: string | null }>(), { excludeRecallNum: null });
/** 首屏只放最近三条:再长的历史进「查看全部」弹窗,总览页不铺长列表 */
const RECENT_SIZE = 3;
/** 多取一条:顶部草稿可能也在最近列表里,过滤后仍能保留 3 条 */
const RECENT_FETCH_SIZE = RECENT_SIZE + 1;
/** 弹窗内分页沿用列表页大小 */
const DIALOG_PAGE_SIZE = 20;
const records = ref<RecallSummary[]>([]);
const page = ref(1);
const recent = computed(() => records.value.filter(record => record.recallNum !== props.excludeRecallNum).slice(0, RECENT_SIZE));
const total = ref(0);
const pageSize = 20;
const loaded = ref(false);
const loading = ref(false);
const failed = ref(false);
const loaded = ref(false);
const visible = useDelayedVisible(loading);
const pages = computed(() => Math.max(1, Math.ceil(total.value / pageSize)));
const load = async (next = page.value) => {
const loadingVisible = useDelayedVisible(loading);
const dialogOpen = ref(false);
const dialogRecords = ref<RecallSummary[]>([]);
const dialogPage = ref(1);
const dialogLoaded = ref(false);
const dialogLoading = ref(false);
const dialogFailed = ref(false);
const dialogLoadingVisible = useDelayedVisible(dialogLoading);
const dialogPages = computed(() => Math.max(1, Math.ceil(total.value / DIALOG_PAGE_SIZE)));
const loadRecent = async () => {
if (loading.value) return;
loading.value = true; failed.value = false;
loading.value = true;
failed.value = false;
try {
const result = (await listRecalls({ pageNum: next, pageSize })).data;
records.value = result.records; page.value = result.current; total.value = result.total; loaded.value = true;
} catch { failed.value = true; }
finally { loading.value = false; }
const page = (await listRecalls({ pageNum: 1, pageSize: RECENT_FETCH_SIZE }, { silent: true })).data;
records.value = page.records;
total.value = page.total;
loaded.value = true;
} catch {
failed.value = true;
} finally {
loading.value = false;
}
};
const toggle = (event: Event) => {
open.value = (event.target as HTMLDetailsElement).open;
if (open.value && !loaded.value && !failed.value) void load();
const loadPage = async (pageNum = dialogPage.value) => {
if (dialogLoading.value) return;
dialogLoading.value = true;
dialogFailed.value = false;
try {
const page = (await listRecalls({ pageNum, pageSize: DIALOG_PAGE_SIZE }, { silent: true })).data;
dialogRecords.value = page.records;
dialogPage.value = page.current;
total.value = page.total;
dialogLoaded.value = true;
} catch {
dialogFailed.value = true;
} finally {
dialogLoading.value = false;
}
};
onMounted(() => { if (open.value) void load(); });
const openAll = () => {
dialogOpen.value = true;
void loadPage(1);
};
onMounted(() => {
void loadRecent();
});
</script>
<template>
<details class="review-history" :open="open" @toggle="toggle">
<summary>自由回忆记录</summary>
<p v-if="visible" role="status">正在读取回忆记录…</p>
<div v-if="failed" role="alert">回忆记录未能读取,请检查网络后重试。<el-button :loading="loading" @click="load()">重试读取</el-button></div>
<template v-else>
<div v-if="total > pageSize" class="history-pager">
<el-button size="small" :disabled="page <= 1 || loading" @click="load(page - 1)">上一页</el-button>
<span>第 {{ page }} / {{ pages }} 页</span>
<el-button size="small" :disabled="page >= pages || loading" @click="load(page + 1)">下一页</el-button>
<section class="module review-history">
<div class="module-head">
<h2 class="module-title">最近回忆</h2>
<span v-if="loaded && total > 0" class="history-total">{{ total }} 条</span>
<el-button v-if="total > RECENT_SIZE" class="history-more" text size="small" @click="openAll">
查看全部
</el-button>
</div>
<p v-if="loadingVisible" role="status">正在读取回忆记录…</p>
<div v-if="failed" class="history-error" role="alert">
回忆记录未能读取。<el-button size="small" :loading="loading" @click="loadRecent">重试读取</el-button>
</div>
<template v-else-if="loaded">
<p v-if="!recent.length" class="history-empty">{{ total > 0 ? '最近的记录已在上面显示。' : '还没有自由回忆记录,选一个标签范围开始第一次回忆。' }}</p>
<div v-else class="history-rows">
<ReviewRecallRow v-for="record in recent" :key="record.recallNum" :record="record" />
</div>
<p v-if="loaded && !records.length">还没有自由回忆记录。</p>
<article v-for="record in records" :key="record.recallNum" class="history-record">
<div>
<h3>{{ record.scope.displayName }}</h3>
<p>{{ record.scope.type === 'TASK' ? '原任务范围' : '标签范围' }}<span v-if="record.scope.type === 'TASK'">({{ record.scope.taskNum }})</span><span v-else>({{ record.scope.combineMode === 'INTERSECT' ? '交集' : '并集' }})</span></p>
<p>{{ record.status === 'ACTIVE' ? '草稿' : '已结束' }} {{ formatDateTime(record.updatedAt) }}</p>
<p v-if="record.activeDurationMs > 0 || (record.actualDurationMs ?? 0) > 0">有效时间 {{ formatDurationMs(record.activeDurationMs) }}<template v-if="record.actualDurationMs != null"> · 实际用时 {{ formatDurationMs(record.actualDurationMs) }}</template></p>
</div>
<el-button size="small" plain @click="router.push(`/review/recalls/${encodeURIComponent(record.recallNum)}`)">{{ record.status === 'ACTIVE' ? '查看草稿' : '回看回忆' }}</el-button>
</article>
<el-pagination v-if="total > pageSize" :current-page="page" :page-size="pageSize" :total="total" :disabled="loading" layout="prev, pager, next" @current-change="load" />
</template>
</details>
<el-dialog v-model="dialogOpen" class="history-dialog" title="全部回忆记录" width="640px">
<p v-if="dialogLoadingVisible" role="status">正在读取回忆记录…</p>
<div v-if="dialogFailed" role="alert">
回忆记录未能读取。<el-button size="small" :loading="dialogLoading" @click="loadPage()">重试读取</el-button>
</div>
<template v-else>
<div v-if="dialogPages > 1" class="history-pager">
<el-button size="small" :disabled="dialogPage <= 1 || dialogLoading" @click="loadPage(dialogPage - 1)">上一页</el-button>
<span>第 {{ dialogPage }} / {{ dialogPages }} 页</span>
<el-button size="small" :disabled="dialogPage >= dialogPages || dialogLoading" @click="loadPage(dialogPage + 1)">下一页</el-button>
</div>
<p v-if="dialogLoaded && !dialogRecords.length" class="history-empty">还没有自由回忆记录。</p>
<div class="history-rows">
<ReviewRecallRow v-for="record in dialogRecords" :key="record.recallNum" :record="record" />
</div>
<el-pagination
v-if="dialogPages > 1"
class="history-pagination"
layout="prev, pager, next"
:total="total"
:page-size="DIALOG_PAGE_SIZE"
:current-page="dialogPage"
:disabled="dialogLoading"
@current-change="loadPage"
/>
</template>
<template #footer>
<el-button @click="dialogOpen = false">关闭</el-button>
</template>
</el-dialog>
</section>
</template>
<style scoped>
.review-history { padding: 16px; background: var(--surface-strong); border: 1px solid var(--border-soft); border-radius: 8px; }
summary { cursor: pointer; color: var(--green-900); padding: 8px 0; }
.history-record { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border-soft); }
.history-record > div { min-width: 0; overflow-wrap: anywhere; }
h3 { margin: 0; font-size: 15px; }
p { margin: 4px 0; font-size: 13px; color: var(--text-secondary); }
.history-pager { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; font-variant-numeric: tabular-nums; }
@media (max-width: 768px) { .history-record { align-items: stretch; flex-direction: column; } .history-record .el-button { min-height: 44px; } }
.module {
display: flex;
flex-direction: column;
gap: 12px;
}
.module-head {
display: flex;
align-items: baseline;
flex-wrap: wrap;
gap: 8px 12px;
}
.module-title {
margin: 0;
font-size: 17px;
font-weight: 600;
color: var(--green-900);
}
.history-total {
font-size: 13px;
color: var(--text-secondary);
font-variant-numeric: tabular-nums;
}
.history-more {
margin-left: auto;
}
.history-empty {
margin: 0;
font-size: 13px;
color: var(--text-secondary);
}
.history-error {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8px;
font-size: 13px;
color: var(--accent-danger-text);
}
.history-rows {
display: flex;
flex-direction: column;
gap: 8px;
}
.history-pager {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 12px;
margin-bottom: 8px;
font-size: 13px;
color: var(--text-secondary);
font-variant-numeric: tabular-nums;
}
.history-pagination {
margin-top: 12px;
}
</style>
<style>
/* 20 条一页的弹窗列表在桌面上会超出视口,只让弹窗正文滚动 */
.history-dialog .el-dialog__body {
max-height: min(60vh, calc(100dvh - 200px));
overflow-y: auto;
}
</style>