Files
paper-doc/frontend/src/components/references/ReferenceCitationsDialog.vue
T
govin 872ad8cf3b frontend: add the reference library, its tags, and a way in
参考文献 now sits in the header to the right of 论文 and 模板 — the library is
drawn *from* rather than worked in, so it is a button one step away. Its
own second-level menu marks out 文献列表 / 新增文献 / 标签管理 and then lists
the tags themselves, read from their store, so a label can be picked
straight from the rail.

A tag in the rail links to `/references?tag=<id>`, which makes the query
parameter part of the view rather than hidden filter state: the table's own
selector writes the same parameter, so the two cannot disagree and a
filtered view is a link someone can be sent.

The form keeps the order the feature intends — a tag is created before it
is applied, so no stored reference can point at a label that is not there —
and the citation count in a row opens the answer it exists to give (which
paper, which paragraph, which quoted passage).

Tag colours are painted from the row rather than a class map: the palette
is the writer's, and the chip has to be that hue in the table, in the rail
and in the picker.
2026-09-22 17:55:20 +08:00

129 lines
3.3 KiB
Vue

<script setup lang="ts">
/**
* "Where have I used this?" — the reverse lookup for one reference.
*
* A sentence knows which articles it quotes; only the library can answer the
* other direction, and it is the question that decides whether an entry is safe
* to delete. The dialog shows the paper, the paragraph heading the template puts
* the sentence under, and the passage the citation quotes.
*/
import { computed, ref, watch } from 'vue'
import { ElMessage } from 'element-plus'
import { errorMessage } from '@/api/client'
import {
listReferenceCitations,
type ReferenceCitation,
type ReferenceListItem,
} from '@/api/references'
import { PARAGRAPH_UNSET_LABEL } from '@/utils/format'
const props = defineProps<{
modelValue: boolean
reference: ReferenceListItem | null
}>()
const emit = defineEmits<{ 'update:modelValue': [value: boolean] }>()
const visible = computed({
get: () => props.modelValue,
set: (value: boolean) => emit('update:modelValue', value),
})
const loading = ref(false)
const rows = ref<ReferenceCitation[]>([])
watch(
() => props.modelValue,
async (open) => {
if (!open || !props.reference) return
loading.value = true
rows.value = []
try {
rows.value = await listReferenceCitations(props.reference.id)
} catch (error) {
ElMessage.error(errorMessage(error))
} finally {
loading.value = false
}
},
)
/** The heading a citation sits under, or the label the document renders. */
function paragraphName(row: ReferenceCitation): string {
return row.paragraph_name ?? PARAGRAPH_UNSET_LABEL
}
</script>
<template>
<el-dialog
v-model="visible"
:title="`引用情况 · ${reference?.title ?? ''}`"
width="min(860px, 95vw)"
append-to-body
>
<el-table v-loading="loading" :data="rows" size="small" class="citations">
<el-table-column label="论文" min-width="180">
<template #default="{ row }">
<RouterLink :to="`/papers/${row.paper_id}`" class="paper-link">
{{ row.paper_title }}
</RouterLink>
</template>
</el-table-column>
<el-table-column label="段落" min-width="150">
<template #default="{ row }">{{ paragraphName(row) }}</template>
</el-table-column>
<el-table-column label="句子" min-width="260">
<template #default="{ row }">
<span class="sentence">{{ row.sentence_content || '(空行,只挂引用)' }}</span>
</template>
</el-table-column>
<el-table-column label="引用内容" min-width="220">
<template #default="{ row }">
<span class="quote">{{ row.quote }}</span>
</template>
</el-table-column>
<template #empty>
<el-empty
:description="
reference?.citation_count
? '没有找到引用记录'
: '这篇文献还没有被任何句子引用'
"
/>
</template>
</el-table>
<template #footer>
<el-button @click="visible = false">关闭</el-button>
</template>
</el-dialog>
</template>
<style scoped>
.citations {
width: 100%;
}
.paper-link {
color: var(--el-color-primary);
text-decoration: none;
}
.sentence {
display: block;
overflow-wrap: anywhere;
}
.quote {
display: block;
color: var(--el-text-color-secondary);
overflow-wrap: anywhere;
}
</style>