frontend: add the paper list, document view, and paragraph editor
The 论文 menu now carries the papers themselves, read from a pinia store, so a paper opens straight from the rail; every page that changes the list reloads that store, and a filter box appears once there are more than six. PapersView is the library — search, create, edit, open, single and batch delete. PaperDetailView is the writing surface: it renders the server's document verbatim, with an edit button beside every paragraph (written or not, because content only ever enters a paper through the editor), citation markers numbered in reading order to match the 参考文献 list, and a 切换模板 dialog that previews the impact before re-shaping the document. The paragraph editor shows one paragraph as the paper will read it — every sentence on its own line, in sort order, each editable, each able to carry citations — and writes the paragraph back whole. Whitespace-only lines are dropped on save; a citation with an empty 引用内容 is refused; and 所属段落 moves the paragraph to another position, appended after what is already there.
This commit is contained in:
@@ -0,0 +1,466 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* One paper, read as a document.
|
||||
*
|
||||
* The page renders exactly what the server assembled — the template's
|
||||
* paragraphs in position order, each carrying the sentences stored at its
|
||||
* position — and refuses to do any of the assembling itself. That is the whole
|
||||
* point of the feature: the shape of a paper is decided once, by its template,
|
||||
* and cannot be re-derived differently on the client.
|
||||
*
|
||||
* Three states are visible and none of them is an error:
|
||||
*
|
||||
* * a **written paragraph** — heading, prose, numbered citation markers;
|
||||
* * an **empty paragraph** — heading and a placeholder, because the structure
|
||||
* is there before the words are;
|
||||
* * an **unmatched paragraph** (未设定) — content whose position the current
|
||||
* template does not define, kept in order rather than hidden, and recoverable
|
||||
* by editing the paragraph or switching back.
|
||||
*
|
||||
* Every paragraph carries its own edit button, written or not: the editor is
|
||||
* the only way content enters a paper, so it may never be the thing that is
|
||||
* missing.
|
||||
*/
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import {
|
||||
ArrowLeft,
|
||||
Delete,
|
||||
Edit,
|
||||
Refresh,
|
||||
Right,
|
||||
Switch,
|
||||
Warning,
|
||||
} from '@element-plus/icons-vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
|
||||
import { errorMessage } from '@/api/client'
|
||||
import {
|
||||
deletePaper,
|
||||
getPaperDocument,
|
||||
PAPER_STATUS_LABELS,
|
||||
PAPER_STATUS_TAG,
|
||||
type PaperDocument,
|
||||
type PaperParagraph,
|
||||
} from '@/api/papers'
|
||||
import PaperFormDialog from '@/components/papers/PaperFormDialog.vue'
|
||||
import ParagraphEditDialog from '@/components/papers/ParagraphEditDialog.vue'
|
||||
import TemplateSwitchDialog from '@/components/papers/TemplateSwitchDialog.vue'
|
||||
import PaperParagraphView from '@/components/papers/PaperParagraph.vue'
|
||||
import { usePapersStore } from '@/stores/papers'
|
||||
import { PARAGRAPH_UNSET_LABEL, formatDateTime, splitKeywords } from '@/utils/format'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const papersStore = usePapersStore()
|
||||
|
||||
const loading = ref(false)
|
||||
const paperDoc = ref<PaperDocument | null>(null)
|
||||
|
||||
const paragraphDialog = ref(false)
|
||||
const editingSort = ref<number | null>(null)
|
||||
|
||||
const switchDialog = ref(false)
|
||||
const formDialog = ref(false)
|
||||
|
||||
const paperId = computed(() => Number(route.params.id))
|
||||
|
||||
const paper = computed(() => paperDoc.value?.paper ?? null)
|
||||
|
||||
/** Citation id -> the number shown in the text, in reading order. */
|
||||
const citationIndex = computed<Record<number, number>>(() => {
|
||||
const map: Record<number, number> = {}
|
||||
for (const citation of paperDoc.value?.citations ?? []) {
|
||||
map[citation.id] = citation.index
|
||||
}
|
||||
return map
|
||||
})
|
||||
|
||||
/** How much of the structure has been written, for the header read-out. */
|
||||
const progress = computed(() => {
|
||||
if (!paperDoc.value) return { written: 0, total: 0, unmatched: 0 }
|
||||
const paragraphs = paperDoc.value.paragraphs
|
||||
return {
|
||||
written: paragraphs.filter((paragraph) => paragraph.sentences.length > 0).length,
|
||||
total: paragraphs.filter((paragraph) => paragraph.matched).length,
|
||||
unmatched: paragraphs.filter((paragraph) => !paragraph.matched).length,
|
||||
}
|
||||
})
|
||||
|
||||
/** Any 未设定 paragraph means content lost its heading in a template switch. */
|
||||
const hasUnmatched = computed(() => progress.value.unmatched > 0)
|
||||
|
||||
async function load(): Promise<void> {
|
||||
if (!Number.isFinite(paperId.value)) {
|
||||
void router.replace('/papers')
|
||||
return
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
paperDoc.value = await getPaperDocument(paperId.value)
|
||||
} catch (error) {
|
||||
ElMessage.error(errorMessage(error))
|
||||
paperDoc.value = null
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function openParagraph(paragraph: PaperParagraph): void {
|
||||
editingSort.value = paragraph.paper_template_filed_sort
|
||||
paragraphDialog.value = true
|
||||
}
|
||||
|
||||
/** A paragraph write returns the refreshed document, so state is replaced. */
|
||||
function onParagraphSaved(updated: PaperDocument): void {
|
||||
paperDoc.value = updated
|
||||
void papersStore.reload()
|
||||
}
|
||||
|
||||
async function onPaperSaved(): Promise<void> {
|
||||
await load()
|
||||
await papersStore.reload()
|
||||
}
|
||||
|
||||
async function onTemplateSwitched(): Promise<void> {
|
||||
await onPaperSaved()
|
||||
if (hasUnmatched.value) {
|
||||
ElMessage.warning(
|
||||
`有 ${progress.value.unmatched} 段内容在新模板里没有对应标题,已按顺序保留并显示为「${PARAGRAPH_UNSET_LABEL}」`,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
async function onDelete(): Promise<void> {
|
||||
const current = paper.value
|
||||
if (!current) return
|
||||
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确定删除论文「${current.title}」?其中的 ${current.sentence_count} 句正文会一并删除。`,
|
||||
'删除论文',
|
||||
{ type: 'warning', confirmButtonText: '删除', cancelButtonText: '取消' },
|
||||
)
|
||||
} catch {
|
||||
return // dismissed
|
||||
}
|
||||
|
||||
try {
|
||||
await deletePaper(current.id)
|
||||
await papersStore.reload()
|
||||
ElMessage.success('已删除')
|
||||
void router.push('/papers')
|
||||
} catch (error) {
|
||||
ElMessage.error(errorMessage(error))
|
||||
}
|
||||
}
|
||||
|
||||
/** Scroll to a paragraph, so a citation can point back at its source. */
|
||||
function scrollToParagraph(sort: number): void {
|
||||
const element = document.getElementById(`paragraph-${sort}`)
|
||||
element?.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
||||
}
|
||||
|
||||
/** Reload when the route id changes, without remounting the view. */
|
||||
watch(paperId, () => {
|
||||
editingSort.value = null
|
||||
void load()
|
||||
})
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-loading="loading" class="page">
|
||||
<el-empty v-if="!loading && !paper" description="论文不存在或已被删除">
|
||||
<el-button type="primary" :icon="ArrowLeft" @click="router.push('/papers')">
|
||||
返回论文列表
|
||||
</el-button>
|
||||
</el-empty>
|
||||
|
||||
<template v-else-if="paper">
|
||||
<el-card shadow="never" class="head-card">
|
||||
<div class="head">
|
||||
<div class="head-main">
|
||||
<div class="head-top">
|
||||
<el-button link :icon="ArrowLeft" @click="router.push('/papers')">论文列表</el-button>
|
||||
<el-divider direction="vertical" />
|
||||
<el-tag size="small" :type="PAPER_STATUS_TAG[paper.status]" effect="plain">
|
||||
{{ PAPER_STATUS_LABELS[paper.status] }}
|
||||
</el-tag>
|
||||
<el-tag v-if="paper.template_name" size="small" effect="plain" type="success">
|
||||
模板:{{ paper.template_name }}
|
||||
</el-tag>
|
||||
<el-tag v-else size="small" effect="plain" type="warning">未选择模板</el-tag>
|
||||
<span v-if="hasUnmatched" class="unmatched-hint">
|
||||
<el-icon><Warning /></el-icon>
|
||||
{{ progress.unmatched }} 段没有对应标题
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<h1 class="head-title">{{ paper.title }}</h1>
|
||||
|
||||
<div class="head-meta">
|
||||
<span v-if="paper.author">作者:{{ paper.author }}</span>
|
||||
<span v-if="paper.target_journal">目标期刊:{{ paper.target_journal }}</span>
|
||||
<span>
|
||||
进度:{{ progress.written }} / {{ progress.total }} 段 ·
|
||||
{{ paper.sentence_count }} 句
|
||||
</span>
|
||||
<span>更新于 {{ formatDateTime(paper.updated_at) }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="splitKeywords(paper.keywords).length" class="head-keywords">
|
||||
<el-tag
|
||||
v-for="word in splitKeywords(paper.keywords)"
|
||||
:key="word"
|
||||
size="small"
|
||||
type="info"
|
||||
effect="plain"
|
||||
>
|
||||
{{ word }}
|
||||
</el-tag>
|
||||
</div>
|
||||
|
||||
<p v-if="paper.abstract" class="head-abstract">{{ paper.abstract }}</p>
|
||||
</div>
|
||||
|
||||
<div class="head-actions">
|
||||
<el-button :icon="Refresh" :loading="loading" @click="load">刷新</el-button>
|
||||
<el-button :icon="Switch" @click="switchDialog = true">切换模板</el-button>
|
||||
<el-button :icon="Edit" @click="formDialog = true">编辑信息</el-button>
|
||||
<el-button type="danger" plain :icon="Delete" @click="onDelete">删除</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<el-alert
|
||||
v-for="warning in paperDoc?.warnings ?? []"
|
||||
:key="warning"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
show-icon
|
||||
:title="warning"
|
||||
/>
|
||||
|
||||
<el-card shadow="never" class="paper-card">
|
||||
<template #header>
|
||||
<div class="paper-head">
|
||||
<span class="paper-title">正文</span>
|
||||
<span class="paper-hint">
|
||||
段落顺序完全来自模板的 sort;每个段落右侧都可以单独编辑
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<el-empty
|
||||
v-if="!paperDoc?.paragraphs.length"
|
||||
description="这篇论文还没有结构,先选择一个模板"
|
||||
>
|
||||
<el-button type="primary" :icon="Switch" @click="switchDialog = true">
|
||||
选择模板
|
||||
</el-button>
|
||||
</el-empty>
|
||||
|
||||
<div v-else class="sheet">
|
||||
<PaperParagraphView
|
||||
v-for="paragraph in paperDoc.paragraphs"
|
||||
:key="paragraph.paper_template_filed_sort"
|
||||
:paragraph="paragraph"
|
||||
:citation-index="citationIndex"
|
||||
@edit="openParagraph"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<el-card v-if="paperDoc?.citations.length" shadow="never">
|
||||
<template #header>
|
||||
<div class="paper-head">
|
||||
<span class="paper-title">参考文献引用</span>
|
||||
<span class="paper-hint">按正文出现顺序编号,正文中的上标与这里的序号一一对应</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<ol class="references">
|
||||
<li v-for="citation in paperDoc.citations" :key="citation.id" class="reference">
|
||||
<span class="reference-index">[{{ citation.index }}]</span>
|
||||
<div class="reference-body">
|
||||
<div class="reference-quote">{{ citation.quote }}</div>
|
||||
<div class="reference-meta">
|
||||
<el-tag v-if="citation.reference_id" size="small" effect="plain">
|
||||
引用 #{{ citation.reference_id }}
|
||||
</el-tag>
|
||||
<el-tag v-else size="small" type="warning" effect="plain">未关联引用 id</el-tag>
|
||||
<el-button link type="primary" @click="scrollToParagraph(citation.paper_template_filed_sort)">
|
||||
{{ citation.paragraph_name ?? PARAGRAPH_UNSET_LABEL }}
|
||||
<el-icon><Right /></el-icon>
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ol>
|
||||
</el-card>
|
||||
|
||||
<ParagraphEditDialog
|
||||
v-model="paragraphDialog"
|
||||
:paper-id="paper.id"
|
||||
:field-sort="editingSort"
|
||||
:paragraphs="paperDoc?.paragraphs ?? []"
|
||||
@saved="onParagraphSaved"
|
||||
/>
|
||||
|
||||
<TemplateSwitchDialog
|
||||
v-if="paperDoc"
|
||||
v-model="switchDialog"
|
||||
:paper="paper"
|
||||
:paragraphs="paperDoc.paragraphs"
|
||||
@saved="onTemplateSwitched"
|
||||
/>
|
||||
|
||||
<PaperFormDialog
|
||||
v-model="formDialog"
|
||||
:paper="paper"
|
||||
@saved="onPaperSaved"
|
||||
/>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.head-card :deep(.el-card__body) {
|
||||
padding-bottom: 16px;
|
||||
}
|
||||
|
||||
.head {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 20px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.head-main {
|
||||
min-width: 0;
|
||||
flex: 1 1 420px;
|
||||
}
|
||||
|
||||
.head-top {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.unmatched-hint {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
font-size: 12px;
|
||||
color: var(--el-color-warning);
|
||||
}
|
||||
|
||||
.head-title {
|
||||
margin: 8px 0 6px;
|
||||
font-size: 22px;
|
||||
font-weight: 650;
|
||||
line-height: 1.4;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.head-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
flex-wrap: wrap;
|
||||
font-size: 13px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.head-keywords {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
flex-wrap: wrap;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.head-abstract {
|
||||
margin: 10px 0 0;
|
||||
font-size: 13px;
|
||||
line-height: 1.8;
|
||||
color: var(--el-text-color-regular);
|
||||
}
|
||||
|
||||
.head-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.paper-head {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.paper-title {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.paper-hint {
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
/* The writing surface: a sheet, not a table — the paper's own typography is
|
||||
what the template describes, so the container stays out of the way. */
|
||||
.sheet {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
max-width: 900px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.references {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.reference {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.reference-index {
|
||||
flex: 0 0 auto;
|
||||
min-width: 34px;
|
||||
font-variant-numeric: tabular-nums;
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
|
||||
.reference-body {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.reference-quote {
|
||||
font-size: 13px;
|
||||
line-height: 1.8;
|
||||
color: var(--el-text-color-regular);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.reference-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user