diff --git a/frontend/src/api/papers.ts b/frontend/src/api/papers.ts index 0dbb4b2..e0f2dde 100644 --- a/frontend/src/api/papers.ts +++ b/frontend/src/api/papers.ts @@ -116,7 +116,14 @@ export interface PaperParagraph { /** One citation as it appears in the 参考文献 list. */ export interface PaperCitation extends Citation { - /** The number shown in the text as `[index]`, in reading order. */ + /** + * The number shown in the text as `[index]`, in reading order. + * + * It is the number of the **work**, not of the citation: a paper that cites + * the same article in three sentences prints `[7]` three times and lists the + * article once. Everything that numbers citations reads it from here, so the + * markers and the list cannot disagree. + */ index: number sentence_id: number sentence_content: string @@ -124,11 +131,35 @@ export interface PaperCitation extends Citation { paragraph_name: string | null } +/** + * One entry of the 参考文献 list: one work, however often it is cited. + * + * `text` is the whole entry as it prints, already formatted by the server in + * `reference_style`. A client prints it verbatim — assembling a bibliography + * from fields is a second implementation of a rule, and the two would drift. + */ +export interface PaperReference { + /** The number the text shows as `[index]`. */ + index: number + /** The library row it came from, or `null` for a citation written before the + * literature was entered — `text` is empty in that case, and nothing is + * invented to fill it. */ + reference_id: number | null + text: string + /** What a complete entry still lacks, in Chinese — 责任者、出版年、DOI… */ + missing: string[] + /** Every place in the text that cites it, in reading order. */ + citations: PaperCitation[] +} + /** The whole paper as it reads. */ export interface PaperDocument { paper: PaperDetail paragraphs: PaperParagraph[] citations: PaperCitation[] + references: PaperReference[] + /** The citation style the entries were written in, e.g. `springer`. */ + reference_style: string warnings: string[] } @@ -218,6 +249,16 @@ export async function getPaperDocument(id: number): Promise { return data } +/** Display names for the citation styles the server can print. */ +export const REFERENCE_STYLE_LABELS: Record = { + springer: 'Springer 基本格式', +} + +/** The label for a style token, falling back to the token itself. */ +export function referenceStyleLabel(style: string): string { + return REFERENCE_STYLE_LABELS[style] ?? style +} + export async function createPaper(payload: PaperPayload): Promise { const { data } = await http.post('/papers', payload) return data diff --git a/frontend/src/components/papers/PaperParagraph.vue b/frontend/src/components/papers/PaperParagraph.vue index b640fb1..0b67157 100644 --- a/frontend/src/components/papers/PaperParagraph.vue +++ b/frontend/src/components/papers/PaperParagraph.vue @@ -32,6 +32,8 @@ const props = defineProps<{ paragraph: PaperParagraph /** Citation id -> the number shown in the text, assigned by reading order. */ citationIndex: Record + /** Reference id -> its formatted entry, so a marker can say what it points at. */ + referenceText: Record }>() defineEmits<{ edit: [paragraph: PaperParagraph] }>() @@ -106,12 +108,19 @@ const anchor = computed(() => `paragraph-${props.paragraph.paper_template_filed_ > {{ citationIndex[citation.id] ?? '?' }} @@ -222,7 +231,7 @@ const anchor = computed(() => `paragraph-${props.paragraph.paper_template_filed_ } .cite-tip { - max-width: 320px; + max-width: 380px; } .cite-tip-head { @@ -232,7 +241,15 @@ const anchor = computed(() => `paragraph-${props.paragraph.paper_template_filed_ font-weight: 600; } +/* The bibliography entry: the whole point of the tooltip. It is set as a + paragraph of running text because that is how it prints in the list. */ +.cite-tip-entry { + margin-top: 4px; + line-height: 1.7; +} + .cite-tip-unlinked { + margin-top: 4px; font-weight: 400; opacity: 0.7; } diff --git a/frontend/src/views/papers/PaperDetailView.vue b/frontend/src/views/papers/PaperDetailView.vue index ac8d8b9..cf81b5f 100644 --- a/frontend/src/views/papers/PaperDetailView.vue +++ b/frontend/src/views/papers/PaperDetailView.vue @@ -29,7 +29,6 @@ import { Delete, Edit, Refresh, - Right, Switch, Warning, } from '@element-plus/icons-vue' @@ -41,8 +40,10 @@ import { getPaperDocument, PAPER_STATUS_LABELS, PAPER_STATUS_TAG, + referenceStyleLabel, type PaperDocument, type PaperParagraph, + type PaperReference, } from '@/api/papers' import PaperFormDialog from '@/components/papers/PaperFormDialog.vue' import ParagraphEditDialog from '@/components/papers/ParagraphEditDialog.vue' @@ -77,6 +78,52 @@ const citationIndex = computed>(() => { return map }) +/** + * Reference id -> the formatted entry, for the marker tooltips. + * + * The tooltip on a `[7]` in the text should say what `[7]` *is*, and the entry + * is assembled once by the server — this is a lookup of that same string, not a + * second attempt at formatting it. + */ +const referenceText = computed>(() => { + const map: Record = {} + for (const entry of paperDoc.value?.references ?? []) { + if (entry.reference_id != null && entry.text) { + map[entry.reference_id] = entry.text + } + } + return map +}) + +/** How the entries are printed, named rather than hard-coded in the view. */ +const styleLabel = computed(() => + referenceStyleLabel(paperDoc.value?.reference_style ?? 'springer'), +) + +/** + * Where an entry is cited, one row per paragraph. + * + * The same work cited twice in one paragraph is one place with a count, not two + * identical links: what the reader needs from the list is where to look, and + * the quotes for that paragraph travel in the tooltip. + */ +function places(entry: PaperReference): { sort: number; name: string; quotes: string[] }[] { + const byParagraph = new Map() + for (const citation of entry.citations) { + const found = byParagraph.get(citation.paper_template_filed_sort) + if (found) { + found.quotes.push(citation.quote) + continue + } + byParagraph.set(citation.paper_template_filed_sort, { + sort: citation.paper_template_filed_sort, + name: citation.paragraph_name ?? PARAGRAPH_UNSET_LABEL, + quotes: [citation.quote], + }) + } + return [...byParagraph.values()] +} + /** 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 } @@ -268,33 +315,69 @@ onMounted(load) :key="paragraph.paper_template_filed_sort" :paragraph="paragraph" :citation-index="citationIndex" + :reference-text="referenceText" @edit="openParagraph" /> - +
    -
  1. - [{{ citation.index }}] +
  2. + [{{ entry.index }}]
    -
    {{ citation.quote }}
    + +

    {{ entry.text }}

    +

    + 这处引用还没有关联文献库条目,只有引用内容。 +

    +
    - - 引用 #{{ citation.reference_id }} + + 缺 {{ entry.missing.join('、') }} - 未关联引用 id - - {{ citation.paragraph_name ?? PARAGRAPH_UNSET_LABEL }} - - + + 未关联文献 + + + 引用位置 + + + + {{ place.name }} + + ×{{ place.quotes.length }} + + + +
  3. @@ -446,19 +529,56 @@ onMounted(load) .reference-body { min-width: 0; + flex: 1 1 auto; } -.reference-quote { +/* The entry, printed as the style wrote it: one line of running text, hanging + under its number like a bibliography. */ +.reference-text { + margin: 0; font-size: 13px; line-height: 1.8; color: var(--el-text-color-regular); overflow-wrap: anywhere; } +.reference-text--unlinked { + color: var(--el-color-warning); +} + .reference-meta { display: flex; align-items: center; gap: 8px; margin-top: 4px; + flex-wrap: wrap; +} + +.reference-places { + display: inline-flex; + align-items: center; + gap: 2px; + flex-wrap: wrap; + font-size: 12px; + color: var(--el-text-color-secondary); +} + +.reference-places-label { + margin-right: 2px; + color: var(--el-text-color-placeholder); +} + +.place-count { + margin-left: 2px; + color: var(--el-text-color-placeholder); + font-variant-numeric: tabular-nums; +} + +.place-tip { + display: flex; + flex-direction: column; + gap: 4px; + max-width: 420px; + line-height: 1.7; }