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:
2026-09-18 17:29:16 +08:00
parent 06d7e922bd
commit 4d749b3592
13 changed files with 2813 additions and 57 deletions
@@ -0,0 +1,250 @@
<script setup lang="ts">
/**
* One paragraph of a paper, as the reader sees it.
*
* Two things about this component carry the feature's contracts:
*
* 1. **The structure is never skipped.** A paragraph with no sentences still
* renders its heading and a quiet placeholder, because the paper's shape
* comes from its template and an unwritten paragraph is still a paragraph.
* 2. **A paragraph is reassembled from its sentences.** They are printed in
* `sort` order, one after another, with no separator added — Chinese
* sentences already end in punctuation, and inserting anything between them
* would show up in the text.
*
* A sentence that quotes something gets a superscript marker numbered by the
* paper's citation list, so the marker and the 参考文献 entry cannot disagree.
*/
import { computed } from 'vue'
import { Edit } from '@element-plus/icons-vue'
import type { PaperParagraph } from '@/api/papers'
import { PARAGRAPH_UNSET_LABEL, levelIndent } from '@/utils/format'
const props = defineProps<{
paragraph: PaperParagraph
/** Citation id -> the number shown in the text, assigned by reading order. */
citationIndex: Record<number, number>
}>()
defineEmits<{ edit: [paragraph: PaperParagraph] }>()
/** The heading's own typography, read from the template's field. */
const headingStyle = computed(() => {
const style: Record<string, string> = {}
if (props.paragraph.font_size != null) style.fontSize = `${props.paragraph.font_size}pt`
if (props.paragraph.font_color) style.color = props.paragraph.font_color
return style
})
/** Indentation follows the field's level, exactly as the template outline does. */
const headingIndent = computed(() => levelIndent(props.paragraph.level))
/** Whether anything has actually been written here. */
const hasContent = computed(() =>
props.paragraph.sentences.some(
(sentence) => sentence.content.trim().length > 0 || sentence.citations.length > 0,
),
)
/** Anchor id, so a citation can point back at the paragraph it came from. */
const anchor = computed(() => `paragraph-${props.paragraph.paper_template_filed_sort}`)
</script>
<template>
<section :id="anchor" class="paragraph" :class="{ 'is-unset': !paragraph.matched }">
<header class="paragraph-head">
<h3 class="paragraph-title" :style="{ paddingLeft: headingIndent }">
<span class="paragraph-sort" :title="`sort = ${paragraph.paper_template_filed_sort}`">
{{ paragraph.paper_template_filed_sort }}
</span>
<span v-if="paragraph.name" class="paragraph-name" :style="headingStyle">
{{ paragraph.name }}
</span>
<span v-else class="paragraph-name paragraph-name--unset" :style="headingStyle">
{{ PARAGRAPH_UNSET_LABEL }}
</span>
</h3>
<div class="paragraph-actions">
<el-tag v-if="!paragraph.matched" size="small" type="warning" effect="plain">
模板无此段
</el-tag>
<span v-else class="paragraph-count">{{ paragraph.sentences.length }} 句</span>
<!-- The edit button sits beside every paragraph, written or not. -->
<el-button
size="small"
type="primary"
plain
:icon="Edit"
@click="$emit('edit', paragraph)"
>
编辑
</el-button>
</div>
</header>
<p v-if="hasContent" class="paragraph-body">
<template v-for="sentence in paragraph.sentences" :key="sentence.id">
<span class="sentence">{{ sentence.content }}</span>
<el-tooltip
v-for="citation in sentence.citations"
:key="citation.id"
placement="top"
:show-after="120"
>
<template #content>
<div class="cite-tip">
<div class="cite-tip-head">
[{{ citationIndex[citation.id] ?? '?' }}]
<span v-if="citation.reference_id">引用 #{{ citation.reference_id }}</span>
<span v-else class="cite-tip-unlinked">未关联引用 id</span>
</div>
<div class="cite-tip-quote">{{ citation.quote }}</div>
</div>
</template>
<sup class="cite-mark">{{ citationIndex[citation.id] ?? '?' }}</sup>
</el-tooltip>
</template>
</p>
<p v-else class="paragraph-empty">(本段暂无内容)</p>
</section>
</template>
<style scoped>
.paragraph {
padding: 14px 16px;
border-radius: 8px;
border: 1px solid transparent;
transition: background-color 0.15s ease, border-color 0.15s ease;
}
.paragraph + .paragraph {
border-top: 1px solid var(--el-border-color-lighter);
border-top-left-radius: 0;
border-top-right-radius: 0;
}
.paragraph:hover {
background-color: var(--el-fill-color-lighter);
}
.paragraph.is-unset {
background-color: var(--el-color-warning-light-9);
}
.paragraph.is-unset:hover {
background-color: var(--el-color-warning-light-8);
}
.paragraph-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.paragraph-title {
display: flex;
align-items: baseline;
gap: 8px;
margin: 0;
min-width: 0;
font-weight: 600;
line-height: 1.6;
}
/* The position the paragraph occupies in the document. Shown because it is
what a sentence is addressed by, and what survives a template switch. */
.paragraph-sort {
flex: 0 0 auto;
min-width: 24px;
padding: 0 6px;
font-size: 11px;
font-weight: 400;
font-variant-numeric: tabular-nums;
text-align: center;
color: var(--el-text-color-secondary);
background-color: var(--el-fill-color);
border-radius: 4px;
}
.paragraph-name {
min-width: 0;
overflow-wrap: anywhere;
}
.paragraph-name--unset {
color: var(--el-color-warning);
font-style: italic;
}
.paragraph-actions {
display: flex;
align-items: center;
gap: 8px;
flex: 0 0 auto;
}
.paragraph-count {
font-size: 12px;
color: var(--el-text-color-placeholder);
}
.paragraph-body {
margin: 8px 0 0;
/* Body text is set at a readable size rather than at the heading's: a
template's font size describes its headings, not its prose. */
font-size: 15px;
line-height: 2;
color: var(--el-text-color-primary);
text-align: justify;
/* The two-character indent a Chinese manuscript expects. */
text-indent: 2em;
overflow-wrap: anywhere;
}
.sentence {
white-space: pre-wrap;
}
.cite-mark {
margin: 0 1px;
padding: 0 2px;
font-size: 11px;
color: var(--el-color-primary);
cursor: help;
vertical-align: super;
line-height: 0;
}
.paragraph-empty {
margin: 8px 0 0;
font-size: 13px;
color: var(--el-text-color-placeholder);
font-style: italic;
}
.cite-tip {
max-width: 320px;
}
.cite-tip-head {
display: flex;
align-items: center;
gap: 8px;
font-weight: 600;
}
.cite-tip-unlinked {
font-weight: 400;
opacity: 0.7;
}
.cite-tip-quote {
margin-top: 4px;
line-height: 1.6;
}
</style>