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:
@@ -11,12 +11,14 @@ import { onMounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { Files, Notebook, Setting } from '@element-plus/icons-vue'
|
||||
|
||||
import { listPapers } from '@/api/papers'
|
||||
import { listSectionFields } from '@/api/sectionFields'
|
||||
import { listTemplates } from '@/api/templates'
|
||||
import AppLogo from '@/components/AppLogo.vue'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const paperCount = ref<number | null>(null)
|
||||
const templateCount = ref<number | null>(null)
|
||||
const fieldCount = ref<number | null>(null)
|
||||
|
||||
@@ -28,10 +30,12 @@ function display(value: number | null): string {
|
||||
onMounted(async () => {
|
||||
// `page_size: 1` because only `total` is used. A failure leaves the count as
|
||||
// an em dash rather than blocking the page.
|
||||
const [templates, fields] = await Promise.allSettled([
|
||||
const [papers, templates, fields] = await Promise.allSettled([
|
||||
listPapers({ page: 1, page_size: 1 }),
|
||||
listTemplates({ page: 1, page_size: 1 }),
|
||||
listSectionFields({ page: 1, page_size: 1 }),
|
||||
])
|
||||
if (papers.status === 'fulfilled') paperCount.value = papers.value.total
|
||||
if (templates.status === 'fulfilled') templateCount.value = templates.value.total
|
||||
if (fields.status === 'fulfilled') fieldCount.value = fields.value.total
|
||||
})
|
||||
@@ -49,8 +53,10 @@ onMounted(async () => {
|
||||
<button type="button" class="entry" @click="router.push('/papers')">
|
||||
<el-icon class="entry-icon"><Notebook /></el-icon>
|
||||
<span class="entry-title">论文</span>
|
||||
<span class="entry-desc">按模板撰写、管理与导出论文</span>
|
||||
<el-tag size="small" type="info" effect="plain">内容待定</el-tag>
|
||||
<span class="entry-desc">按模板逐段撰写与管理论文</span>
|
||||
<el-tag size="small" type="success" effect="plain">
|
||||
{{ display(paperCount) }} 篇
|
||||
</el-tag>
|
||||
</button>
|
||||
|
||||
<button type="button" class="entry" @click="router.push('/templates')">
|
||||
@@ -64,6 +70,14 @@ onMounted(async () => {
|
||||
</section>
|
||||
|
||||
<el-card shadow="never" class="stats">
|
||||
<div class="stat">
|
||||
<el-icon class="stat-icon"><Notebook /></el-icon>
|
||||
<div>
|
||||
<div class="stat-value">{{ display(paperCount) }}</div>
|
||||
<div class="stat-label">论文</div>
|
||||
</div>
|
||||
</div>
|
||||
<el-divider direction="vertical" class="stat-divider" />
|
||||
<div class="stat">
|
||||
<el-icon class="stat-icon"><Setting /></el-icon>
|
||||
<div>
|
||||
@@ -80,7 +94,8 @@ onMounted(async () => {
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-hint">
|
||||
字段可以自由组合进模板,显示顺序完全由每个字段的 sort 决定。
|
||||
字段可以自由组合进模板,显示顺序完全由每个字段的 sort 决定;论文按模板的段落逐句填写,
|
||||
换模板不会丢内容。
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
|
||||
@@ -1,16 +1,170 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* The 论文 section.
|
||||
* 我的论文 — the table of every paper.
|
||||
*
|
||||
* Its content is still to be decided. The page exists so the section is
|
||||
* reachable from the header and so its second-level menu has somewhere to
|
||||
* point; the outline that will drive the writing surface already exists as
|
||||
* templates, so what lands here is the editor that reads one.
|
||||
* The full CRUD surface: search, create, edit, open, single and batch delete.
|
||||
* Opening a paper is a navigation rather than a drawer, because a paper is
|
||||
* where the writing happens and a drawer would fight the page for the job.
|
||||
*
|
||||
* Switching a paper's template is deliberately *not* offered here. It re-shapes
|
||||
* the whole document, and the only honest place to do that is the paper's own
|
||||
* view, where the impact can be shown against the content that actually exists.
|
||||
*/
|
||||
import { useRouter } from 'vue-router'
|
||||
import { Files } from '@element-plus/icons-vue'
|
||||
import { onMounted, reactive, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { Delete, Edit, Plus, Refresh, Search, View } from '@element-plus/icons-vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
|
||||
import { errorMessage } from '@/api/client'
|
||||
import {
|
||||
batchDeletePapers,
|
||||
deletePaper,
|
||||
listPapers,
|
||||
PAPER_STATUS_LABELS,
|
||||
PAPER_STATUS_OPTIONS,
|
||||
PAPER_STATUS_TAG,
|
||||
type PaperListItem,
|
||||
type PaperStatus,
|
||||
} from '@/api/papers'
|
||||
import PaperFormDialog from '@/components/papers/PaperFormDialog.vue'
|
||||
import { usePapersStore } from '@/stores/papers'
|
||||
import { formatDateTime, splitKeywords } from '@/utils/format'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const papersStore = usePapersStore()
|
||||
|
||||
const loading = ref(false)
|
||||
const rows = ref<PaperListItem[]>([])
|
||||
const total = ref(0)
|
||||
const selection = ref<PaperListItem[]>([])
|
||||
|
||||
const query = reactive({
|
||||
keyword: '',
|
||||
status: null as PaperStatus | null,
|
||||
page: 1,
|
||||
page_size: 20,
|
||||
})
|
||||
|
||||
const dialogVisible = ref(false)
|
||||
const editing = ref<PaperListItem | null>(null)
|
||||
|
||||
async function load(): Promise<void> {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await listPapers(query)
|
||||
rows.value = result.items
|
||||
total.value = result.total
|
||||
|
||||
// Deleting the last row of the last page would otherwise leave the table
|
||||
// empty while the pager still points past the end.
|
||||
if (result.items.length === 0 && result.total > 0 && query.page > 1) {
|
||||
query.page -= 1
|
||||
await load()
|
||||
}
|
||||
} catch (error) {
|
||||
ElMessage.error(errorMessage(error))
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function search(): void {
|
||||
query.page = 1
|
||||
void load()
|
||||
}
|
||||
|
||||
function resetFilters(): void {
|
||||
query.keyword = ''
|
||||
query.status = null
|
||||
query.page = 1
|
||||
void load()
|
||||
}
|
||||
|
||||
function onCreate(): void {
|
||||
editing.value = null
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
function onEdit(row: PaperListItem): void {
|
||||
editing.value = row
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
function openPaper(row: PaperListItem): void {
|
||||
void router.push(`/papers/${row.id}`)
|
||||
}
|
||||
|
||||
/** Refresh both this table and the menu, which lists the same papers. */
|
||||
async function refreshAll(): Promise<void> {
|
||||
await Promise.all([load(), papersStore.reload()])
|
||||
}
|
||||
|
||||
async function onDelete(row: PaperListItem): Promise<void> {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确定删除论文「${row.title}」?其中的 ${row.sentence_count} 句正文会一并删除。`,
|
||||
'删除论文',
|
||||
{ type: 'warning', confirmButtonText: '删除', cancelButtonText: '取消' },
|
||||
)
|
||||
} catch {
|
||||
return // dismissed
|
||||
}
|
||||
|
||||
try {
|
||||
await deletePaper(row.id)
|
||||
ElMessage.success('已删除')
|
||||
await refreshAll()
|
||||
} catch (error) {
|
||||
ElMessage.error(errorMessage(error))
|
||||
}
|
||||
}
|
||||
|
||||
async function onBatchDelete(): Promise<void> {
|
||||
const ids = selection.value.map((row) => row.id)
|
||||
if (ids.length === 0) return
|
||||
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确定删除选中的 ${ids.length} 篇论文?正文会一并删除。`,
|
||||
'批量删除',
|
||||
{ type: 'warning', confirmButtonText: '删除', cancelButtonText: '取消' },
|
||||
)
|
||||
} catch {
|
||||
return // dismissed
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await batchDeletePapers(ids)
|
||||
ElMessage.success(`已删除 ${result.deleted} 篇论文`)
|
||||
selection.value = []
|
||||
await refreshAll()
|
||||
} catch (error) {
|
||||
ElMessage.error(errorMessage(error))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the create dialog when the menu's 新建论文 entry sent us here.
|
||||
*
|
||||
* The query is cleared straight away, so a refresh or a back-navigation does
|
||||
* not reopen the dialog.
|
||||
*/
|
||||
watch(
|
||||
() => route.query.new,
|
||||
(flag) => {
|
||||
if (!flag) return
|
||||
onCreate()
|
||||
void router.replace({ path: '/papers' })
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
onMounted(async () => {
|
||||
await load()
|
||||
// The menu may have been loaded before this page existed; keep it in step.
|
||||
void papersStore.reload()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -18,24 +172,183 @@ const router = useRouter()
|
||||
<el-card shadow="never">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>我的论文</span>
|
||||
<el-tag size="small" type="info" effect="plain">内容待定</el-tag>
|
||||
<div>
|
||||
<span class="card-title">我的论文</span>
|
||||
<span class="card-subtitle">论文的结构来自模板,内容按段落逐句填写</span>
|
||||
</div>
|
||||
<el-tag type="info" effect="plain">共 {{ total }} 篇</el-tag>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<el-empty description="论文列表与写作界面尚未确定">
|
||||
<template #description>
|
||||
<p class="hint">
|
||||
这一块的内容还没定。目前可以先在
|
||||
<strong>模板</strong> 里把结构配置好——模板选定的段落字段,
|
||||
就是之后写作时逐段填写的目录。
|
||||
</p>
|
||||
</template>
|
||||
<el-button type="primary" :icon="Files" @click="router.push('/templates/list')">
|
||||
去配置模板
|
||||
<div class="toolbar">
|
||||
<el-input
|
||||
v-model="query.keyword"
|
||||
placeholder="搜索标题、作者或关键词"
|
||||
clearable
|
||||
class="search"
|
||||
@keyup.enter="search"
|
||||
@clear="search"
|
||||
>
|
||||
<template #prefix><el-icon><Search /></el-icon></template>
|
||||
</el-input>
|
||||
|
||||
<el-select
|
||||
v-model="query.status"
|
||||
placeholder="全部状态"
|
||||
clearable
|
||||
class="status-filter"
|
||||
@change="search"
|
||||
>
|
||||
<el-option
|
||||
v-for="option in PAPER_STATUS_OPTIONS"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
:label="option.label"
|
||||
/>
|
||||
</el-select>
|
||||
|
||||
<el-button @click="search">查询</el-button>
|
||||
<el-button text @click="resetFilters">重置</el-button>
|
||||
|
||||
<div class="toolbar-spacer" />
|
||||
|
||||
<el-button :icon="Refresh" :loading="loading" @click="load">刷新</el-button>
|
||||
<el-button
|
||||
type="danger"
|
||||
plain
|
||||
:icon="Delete"
|
||||
:disabled="selection.length === 0"
|
||||
@click="onBatchDelete"
|
||||
>
|
||||
批量删除{{ selection.length ? `(${selection.length})` : '' }}
|
||||
</el-button>
|
||||
</el-empty>
|
||||
<el-button type="primary" :icon="Plus" @click="onCreate">新建论文</el-button>
|
||||
</div>
|
||||
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="rows"
|
||||
row-key="id"
|
||||
stripe
|
||||
class="table"
|
||||
@selection-change="(value: PaperListItem[]) => (selection = value)"
|
||||
>
|
||||
<el-table-column type="selection" width="46" reserve-selection />
|
||||
|
||||
<el-table-column label="论文标题" min-width="220">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" class="title-link" @click="openPaper(row)">
|
||||
{{ row.title }}
|
||||
</el-button>
|
||||
<div v-if="row.abstract" class="abstract" :title="row.abstract">
|
||||
{{ row.abstract }}
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="模板" min-width="160">
|
||||
<template #default="{ row }">
|
||||
<el-tag v-if="row.template_name" size="small" effect="plain">
|
||||
{{ row.template_name }}
|
||||
</el-tag>
|
||||
<el-tag v-else size="small" type="warning" effect="plain">未选择模板</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="作者" width="120" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
<span v-if="row.author">{{ row.author }}</span>
|
||||
<span v-else class="muted">—</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="状态" width="100" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag
|
||||
size="small"
|
||||
:type="PAPER_STATUS_TAG[row.status as PaperStatus]"
|
||||
effect="plain"
|
||||
>
|
||||
{{ PAPER_STATUS_LABELS[row.status as PaperStatus] }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="进度" width="130">
|
||||
<template #default="{ row }">
|
||||
<span class="progress">
|
||||
<strong>{{ row.paragraph_count }}</strong> / {{ row.template_paragraph_count }} 段
|
||||
</span>
|
||||
<div class="progress-sub">{{ row.sentence_count }} 句</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="关键词" min-width="160">
|
||||
<template #default="{ row }">
|
||||
<template v-if="splitKeywords(row.keywords).length">
|
||||
<el-tag
|
||||
v-for="word in splitKeywords(row.keywords).slice(0, 3)"
|
||||
:key="word"
|
||||
size="small"
|
||||
type="info"
|
||||
effect="plain"
|
||||
class="keyword"
|
||||
>
|
||||
{{ word }}
|
||||
</el-tag>
|
||||
<span v-if="splitKeywords(row.keywords).length > 3" class="muted">
|
||||
+{{ splitKeywords(row.keywords).length - 3 }}
|
||||
</span>
|
||||
</template>
|
||||
<span v-else class="muted">—</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="目标期刊" width="150" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
<span v-if="row.target_journal">{{ row.target_journal }}</span>
|
||||
<span v-else class="muted">—</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="更新时间" width="160">
|
||||
<template #default="{ row }">{{ formatDateTime(row.updated_at) }}</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="操作" width="190" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" :icon="View" @click="openPaper(row)">打开</el-button>
|
||||
<el-button link type="primary" :icon="Edit" @click="onEdit(row)">编辑</el-button>
|
||||
<el-button link type="danger" :icon="Delete" @click="onDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<template #empty>
|
||||
<el-empty
|
||||
:description="
|
||||
query.keyword || query.status ? '没有匹配的论文' : '还没有论文,先创建一篇'
|
||||
"
|
||||
>
|
||||
<el-button type="primary" :icon="Plus" @click="onCreate">新建论文</el-button>
|
||||
</el-empty>
|
||||
</template>
|
||||
</el-table>
|
||||
|
||||
<div class="table-pagination">
|
||||
<el-pagination
|
||||
v-model:current-page="query.page"
|
||||
v-model:page-size="query.page_size"
|
||||
:total="total"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
background
|
||||
@current-change="load"
|
||||
@size-change="search"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<PaperFormDialog v-model="dialogVisible" :paper="editing" @saved="refreshAll" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -44,13 +357,63 @@ const router = useRouter()
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.hint {
|
||||
max-width: 460px;
|
||||
margin: 0 auto;
|
||||
.card-title {
|
||||
font-weight: 600;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.card-subtitle {
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.search {
|
||||
width: 260px;
|
||||
}
|
||||
|
||||
.status-filter {
|
||||
width: 130px;
|
||||
}
|
||||
|
||||
.table {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.title-link {
|
||||
font-weight: 600;
|
||||
padding: 0;
|
||||
height: auto;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.abstract {
|
||||
margin-top: 2px;
|
||||
max-width: 320px;
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.progress {
|
||||
font-size: 13px;
|
||||
line-height: 1.7;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.progress-sub {
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-placeholder);
|
||||
}
|
||||
|
||||
.keyword {
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
.muted {
|
||||
color: var(--el-text-color-placeholder);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -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