feat: 自由回忆工作区重做,复习页拆成独立视图

This commit is contained in:
2026-11-20 09:42:42 +08:00
parent 4937ed9cac
commit 15d84decfb
63 changed files with 4367 additions and 4166 deletions
+68
View File
@@ -0,0 +1,68 @@
<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');
const records = ref<RecallSummary[]>([]);
const page = ref(1);
const total = ref(0);
const pageSize = 20;
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) => {
if (loading.value) return;
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 toggle = (event: Event) => {
open.value = (event.target as HTMLDetailsElement).open;
if (open.value && !loaded.value && !failed.value) void load();
};
onMounted(() => { if (open.value) void load(); });
</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>
</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>
</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; } }
</style>