From 5b37e40db31120e7ee0008f09e03698ee8d3a0ed Mon Sep 17 00:00:00 2001 From: Quentin Date: Sun, 11 Oct 2026 19:09:51 +0800 Subject: [PATCH] =?UTF-8?q?refactor(BookDetail):=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E4=B8=8D=E7=A8=B3=E7=9A=84=20Arco=20=E5=AD=90=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=20+=20=E8=87=AA=E5=AE=9E=E7=8E=B0=E7=AE=80=E6=B4=81?= =?UTF-8?q?=E5=B8=83=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 a-page-header/a-statistic/a-descriptions/a-list-item-meta (Arco 2.x 这些组件在 BookDetail 里有渲染问题) - 顶部改用 a-card + flex 自定义布局 - 4 张统计卡用 div + 大数字 - 左侧目录改用 ul/li 自定义(避开 a-list slot 顺序坑) - 右侧三 tab 保留 a-tabs,word/json 内用 div + a-button --- .../src/views/BookManage/BookDetail/index.vue | 507 ++++++++++-------- 1 file changed, 279 insertions(+), 228 deletions(-) diff --git a/frontend/src/views/BookManage/BookDetail/index.vue b/frontend/src/views/BookManage/BookDetail/index.vue index d51b495..2ff3ca3 100644 --- a/frontend/src/views/BookManage/BookDetail/index.vue +++ b/frontend/src/views/BookManage/BookDetail/index.vue @@ -5,8 +5,6 @@ import { getBook, type Book, retryFailed, softDeleteBook } from '@/api/book'; import { getDocumentUrl } from '@/api/document'; import { Message } from '@arco-design/web-vue'; -type FileKind = 'docx' | 'html' | 'json' | 'error_log'; - const route = useRoute(); const router = useRouter(); const bookId = Number(route.params.id); @@ -16,23 +14,23 @@ const loading = ref(false); const selectedDocId = ref(null); const activeTab = ref<'word' | 'html' | 'json'>('html'); -const selectedDoc = computed(() => { - if (!book.value || !selectedDocId.value) return null; - return book.value.documents.find((d) => d.doc_id === selectedDocId.value); -}); - -// 当前 tab 对应的 file_type -const fileType: Record = { +type FileKind = 'docx' | 'html' | 'json' | 'error_log'; +const fileTypeMap: Record = { word: 'docx', html: 'html', json: 'json', }; +const selectedDoc = computed(() => { + if (!book.value || !selectedDocId.value) return null; + return book.value.documents.find((d) => d.doc_id === selectedDocId.value); +}); + const fileUrl = ref(''); const fileLoading = ref(false); const fetchFileUrl = async () => { - if (!selectedDoc.value || !activeTab.value) { + if (!selectedDoc.value) { fileUrl.value = ''; return; } @@ -40,9 +38,9 @@ const fetchFileUrl = async () => { try { const r = await getDocumentUrl( selectedDoc.value.doc_id, - fileType[activeTab.value], + fileTypeMap[activeTab.value], ); - fileUrl.value = r.url; + fileUrl.value = r?.url ?? ''; } catch (e) { fileUrl.value = ''; } finally { @@ -62,7 +60,7 @@ const fetchBook = async () => { } }; -watch([selectedDocId, activeTab], fetchFileUrl); +watch([selectedDocId, activeTab], fetchFileUrl, { immediate: false }); const onRetry = async () => { const r = await retryFailed(bookId); @@ -82,21 +80,8 @@ const onDelete = async () => { } }; -const formatBytes = (n: number): string => { - if (!n) return '0 B'; - if (n < 1024) return `${n} B`; - if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`; - return `${(n / 1024 / 1024).toFixed(2)} MB`; -}; - -const statusColor: Record = { - pending: 'gray', - processing: 'arcoblue', - html_ready: 'green', - json_ready: 'green', - done: 'green', - failed: 'red', - partial: 'orange', +const openInNewTab = (url: string) => { + window.open(url, '_blank'); }; const statusText: Record = { @@ -109,13 +94,14 @@ const statusText: Record = { partial: '部分失败', }; -const docTypeColor: Record = { - 课时作业: 'arcoblue', - 周末提升: 'purple', - 阶段质量评估: 'orange', - 期末质量评估: 'red', - answer: 'cyan', - unknown: 'gray', +const statusColor: Record = { + pending: 'gray', + processing: 'arcoblue', + html_ready: 'green', + json_ready: 'green', + failed: 'red', + partial: 'orange', + done: 'green', }; const completionRate = computed(() => { @@ -123,31 +109,31 @@ const completionRate = computed(() => { return Math.round((book.value.success_count / book.value.total_count) * 100); }); -const openInNewTab = (url: string) => { - window.open(url, '_blank'); -}; +const truncate = (s: string, len = 8) => (s ? `${s.slice(0, len)}…` : ''); onMounted(fetchBook); @@ -387,45 +330,86 @@ onMounted(fetchBook);