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.
This commit is contained in:
+15
-6
@@ -2,10 +2,10 @@
|
||||
/**
|
||||
* Application shell.
|
||||
*
|
||||
* Three bands, in this order: a header holding the mark, the two top-level
|
||||
* sections, and the mark again at the far right; then the row below it, which
|
||||
* is the second-level menu on the left followed by the content area. The menu
|
||||
* is present only on routes that declare a `section` in their meta.
|
||||
* Three bands, in this order: a header holding the mark, the top-level sections,
|
||||
* and the mark again at the far right; then the row below it, which is the
|
||||
* second-level menu on the left followed by the content area. The menu is
|
||||
* present only on routes that declare a `section` in their meta.
|
||||
*/
|
||||
import { computed } from 'vue'
|
||||
import { RouterView, RouterLink, useRoute } from 'vue-router'
|
||||
@@ -18,10 +18,18 @@ import { useAppStore } from '@/stores/app'
|
||||
const route = useRoute()
|
||||
const appStore = useAppStore()
|
||||
|
||||
/** The two top-level sections. `index` is the path `el-menu` routes to. */
|
||||
/**
|
||||
* The top-level sections. `index` is the path `el-menu` routes to.
|
||||
*
|
||||
* 参考文献 sits to the right of 论文 and 模板 because it is a different kind of
|
||||
* thing: the writing surface and the templates are worked *in*, while the
|
||||
* library is drawn *from* — one button away rather than one more thing to
|
||||
* choose between.
|
||||
*/
|
||||
const TOP_MENU = [
|
||||
{ index: '/papers', label: '论文' },
|
||||
{ index: '/templates', label: '模板' },
|
||||
{ index: '/references', label: '参考文献' },
|
||||
] as const
|
||||
|
||||
/**
|
||||
@@ -29,7 +37,8 @@ const TOP_MENU = [
|
||||
*
|
||||
* Derived from the path rather than tracked in state, so browser back/forward
|
||||
* and a pasted deep link both leave the header highlighting the right entry.
|
||||
* `/templates/list` and `/templates/fields` both resolve to `/templates`.
|
||||
* `/templates/list` and `/templates/fields` both resolve to `/templates`, and
|
||||
* `/references/tags` resolves to `/references`.
|
||||
*/
|
||||
const activeTop = computed(() => {
|
||||
const match = TOP_MENU.find(
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
import http from './client'
|
||||
import type { BatchDeleteResult, PageQuery, PageResult } from './types'
|
||||
|
||||
/**
|
||||
* Reference tags (文献标签) — the writer's own labels on the literature.
|
||||
*
|
||||
* A tag is *made first and applied second*: a reference is created with
|
||||
* `tag_ids`, never with tag names, so a typo cannot invent a label. This module
|
||||
* is the first half of that flow; `references.ts` is the second.
|
||||
*
|
||||
* A tag never prints in a reference list — it exists so a library of a few
|
||||
* hundred entries can be narrowed to the handful that matter for the paragraph
|
||||
* being written. That is why it is a separate table from the document's own
|
||||
* 关键词, which are transcribed from the article and do print.
|
||||
*/
|
||||
|
||||
/** A tag as the pickers and the chips need it: no counts, no timestamps. */
|
||||
export interface ReferenceTagRef {
|
||||
id: number
|
||||
name: string
|
||||
/** Canonical `#RRGGBB`, normalised by the API on write. */
|
||||
color: string
|
||||
}
|
||||
|
||||
/** A tag as the tag table shows it. */
|
||||
export interface ReferenceTag extends ReferenceTagRef {
|
||||
note: string | null
|
||||
/** How many references carry this label. Computed on read. */
|
||||
reference_count: number
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface ReferenceTagPayload {
|
||||
name: string
|
||||
color: string
|
||||
note: string | null
|
||||
}
|
||||
|
||||
export interface ReferenceTagQuery extends PageQuery {
|
||||
page?: number
|
||||
page_size?: number
|
||||
}
|
||||
|
||||
/**
|
||||
* The colours the picker offers.
|
||||
*
|
||||
* Chips are the only place a tag colour is ever read, and a table of labels is
|
||||
* read at a glance — so the palette is a small set of hues that stay legible
|
||||
* against the tag's own tinted background, plus two greys for labels that are
|
||||
* meant to recede.
|
||||
*/
|
||||
export const TAG_COLOR_PRESETS = [
|
||||
'#409EFF',
|
||||
'#67C23A',
|
||||
'#E6A23C',
|
||||
'#F56C6C',
|
||||
'#9B59B6',
|
||||
'#14B8A6',
|
||||
'#8C8C8C',
|
||||
'#1F1F1F',
|
||||
] as const
|
||||
|
||||
/** The label a tag with no colour of its own gets. */
|
||||
export const DEFAULT_TAG_COLOR = '#409EFF'
|
||||
|
||||
export async function listReferenceTags(
|
||||
query: ReferenceTagQuery = {},
|
||||
): Promise<PageResult<ReferenceTag>> {
|
||||
const params: Record<string, unknown> = {}
|
||||
if (query.keyword) params.keyword = query.keyword
|
||||
if (query.page) params.page = query.page
|
||||
if (query.page_size) params.page_size = query.page_size
|
||||
|
||||
const { data } = await http.get<PageResult<ReferenceTag>>('/reference-tags', { params })
|
||||
return data
|
||||
}
|
||||
|
||||
/** The API caps `page_size` at 500; a picker wants every label, so it loops. */
|
||||
const TAG_PAGE_SIZE = 200
|
||||
|
||||
/**
|
||||
* Fetch every tag, following pagination.
|
||||
*
|
||||
* The reference form and the shell's rail both want the whole library: a picker
|
||||
* that showed one page would hide the label the writer is looking for, and the
|
||||
* rail would show a partial list that looks complete.
|
||||
*/
|
||||
export async function fetchAllReferenceTags(keyword?: string): Promise<ReferenceTag[]> {
|
||||
const all: ReferenceTag[] = []
|
||||
let page = 1
|
||||
|
||||
for (;;) {
|
||||
const result = await listReferenceTags({ keyword, page, page_size: TAG_PAGE_SIZE })
|
||||
all.push(...result.items)
|
||||
if (page >= result.pages || result.items.length === 0) {
|
||||
return all
|
||||
}
|
||||
page += 1
|
||||
}
|
||||
}
|
||||
|
||||
export async function createReferenceTag(
|
||||
payload: ReferenceTagPayload,
|
||||
): Promise<ReferenceTag> {
|
||||
const { data } = await http.post<ReferenceTag>('/reference-tags', payload)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function updateReferenceTag(
|
||||
id: number,
|
||||
payload: Partial<ReferenceTagPayload>,
|
||||
): Promise<ReferenceTag> {
|
||||
const { data } = await http.patch<ReferenceTag>(`/reference-tags/${id}`, payload)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function deleteReferenceTag(id: number): Promise<void> {
|
||||
await http.delete(`/reference-tags/${id}`)
|
||||
}
|
||||
|
||||
export async function batchDeleteReferenceTags(
|
||||
ids: number[],
|
||||
): Promise<BatchDeleteResult> {
|
||||
const { data } = await http.post<BatchDeleteResult>('/reference-tags/batch-delete', {
|
||||
ids,
|
||||
})
|
||||
return data
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
import http from './client'
|
||||
import type { ReferenceTagRef } from './referenceTags'
|
||||
import type { BatchDeleteResult, PageQuery, PageResult } from './types'
|
||||
|
||||
/**
|
||||
* The reference library (参考文献) — the literature a paper cites.
|
||||
*
|
||||
* One row is one document the writer has read: a journal article, a book, a
|
||||
* patent, a standard, a dataset. It is **global**, not owned by a paper, because
|
||||
* the same article is cited from several papers; the citation itself (which
|
||||
* sentence quotes which passage) lives on the paper side.
|
||||
*
|
||||
* The fields are the intersection of the formats a Chinese journal paper has to
|
||||
* survive — CSL JSON, GB/T 7714-2015, BibTeX/RIS — which is what the labels on
|
||||
* the form mirror. Contributors arrive as an ordered list and replace the stored
|
||||
* list wholesale, exactly like a template's placements.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The document types this library holds.
|
||||
*
|
||||
* `marker` is the GB/T 7714 文献类型标志 a reference list prints after the
|
||||
* title, which is why it is carried here rather than derived per view.
|
||||
*/
|
||||
export const REFERENCE_TYPE_OPTIONS = [
|
||||
{ value: 'journal-article', label: '期刊论文', marker: 'J' },
|
||||
{ value: 'book', label: '专著', marker: 'M' },
|
||||
{ value: 'book-chapter', label: '析出文献', marker: 'M' },
|
||||
{ value: 'conference-paper', label: '会议论文', marker: 'C' },
|
||||
{ value: 'thesis', label: '学位论文', marker: 'D' },
|
||||
{ value: 'patent', label: '专利', marker: 'P' },
|
||||
{ value: 'standard', label: '标准', marker: 'S' },
|
||||
{ value: 'report', label: '报告', marker: 'R' },
|
||||
{ value: 'newspaper-article', label: '报纸文章', marker: 'N' },
|
||||
{ value: 'web-page', label: '网页', marker: 'EB/OL' },
|
||||
{ value: 'dataset', label: '数据集', marker: 'DS' },
|
||||
{ value: 'software', label: '计算机程序', marker: 'CP' },
|
||||
{ value: 'preprint', label: '预印本', marker: 'EB/OL' },
|
||||
{ value: 'other', label: '其他', marker: 'Z' },
|
||||
] as const
|
||||
|
||||
export type ReferenceType = (typeof REFERENCE_TYPE_OPTIONS)[number]['value']
|
||||
|
||||
const TYPE_LABELS = new Map<string, string>(
|
||||
REFERENCE_TYPE_OPTIONS.map((option) => [option.value as string, option.label]),
|
||||
)
|
||||
const TYPE_MARKERS = new Map<string, string>(
|
||||
REFERENCE_TYPE_OPTIONS.map((option) => [option.value as string, option.marker]),
|
||||
)
|
||||
|
||||
/** The Chinese name of a type token, falling back to the token itself. */
|
||||
export function referenceTypeLabel(type: string): string {
|
||||
return TYPE_LABELS.get(type) ?? type
|
||||
}
|
||||
|
||||
/** The GB/T 7714 marker of a type token, or `''` for one we do not know. */
|
||||
export function referenceTypeMarker(type: string): string {
|
||||
return TYPE_MARKERS.get(type) ?? ''
|
||||
}
|
||||
|
||||
/** 语种 — decides which of the two titles a style prints first. */
|
||||
export const REFERENCE_LANGUAGE_OPTIONS = [
|
||||
{ value: 'zh', label: '中文' },
|
||||
{ value: 'en', label: '英文' },
|
||||
{ value: 'ja', label: '日文' },
|
||||
{ value: 'other', label: '其他' },
|
||||
] as const
|
||||
|
||||
/** 责任者角色 — what prints after a name (编 / 译 / 主编). */
|
||||
export const REFERENCE_AUTHOR_ROLE_OPTIONS = [
|
||||
{ value: 'author', label: '作者' },
|
||||
{ value: 'editor', label: '编者' },
|
||||
{ value: 'translator', label: '译者' },
|
||||
{ value: 'compiler', label: '汇编' },
|
||||
] as const
|
||||
|
||||
/** A stored contributor of a reference. */
|
||||
export interface ReferenceAuthor {
|
||||
id: number
|
||||
/** Print order, ascending. */
|
||||
sort: number
|
||||
/** What prints: 「张三」, "John Smith", 「世界卫生组织」. */
|
||||
name: string
|
||||
/** Optional halves, for styles that invert or initialise a name. */
|
||||
family_name: string | null
|
||||
given_name: string | null
|
||||
role: string
|
||||
}
|
||||
|
||||
/** A contributor as the form sends it. */
|
||||
export interface ReferenceAuthorInput {
|
||||
name: string
|
||||
family_name: string | null
|
||||
given_name: string | null
|
||||
role: string
|
||||
sort?: number | null
|
||||
}
|
||||
|
||||
/** A reference as it appears in the library table. */
|
||||
export interface ReferenceListItem {
|
||||
id: number
|
||||
type: string
|
||||
title: string
|
||||
subtitle: string | null
|
||||
container_title: string | null
|
||||
/** 出版者 — the "where" for a book, a thesis or a report, which has no container. */
|
||||
publisher: string | null
|
||||
publication_year: number | null
|
||||
volume: string | null
|
||||
issue: string | null
|
||||
pages: string | null
|
||||
doi: string | null
|
||||
/** The printed author line, already truncated for a row by the API. */
|
||||
authors_line: string
|
||||
author_count: number
|
||||
tags: ReferenceTagRef[]
|
||||
/** How many sentences cite it. */
|
||||
citation_count: number
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
/**
|
||||
* A reference with everything the table does not need.
|
||||
*
|
||||
* The list row deliberately drops the abstract, the note and the contributor
|
||||
* rows; the form needs them, so editing fetches this shape by id.
|
||||
*/
|
||||
export interface ReferenceDetail {
|
||||
id: number
|
||||
type: string
|
||||
title: string
|
||||
subtitle: string | null
|
||||
title_translated: string | null
|
||||
title_short: string | null
|
||||
container_title: string | null
|
||||
container_title_short: string | null
|
||||
series_title: string | null
|
||||
series_number: string | null
|
||||
edition: string | null
|
||||
volume: string | null
|
||||
issue: string | null
|
||||
pages: string | null
|
||||
article_number: string | null
|
||||
publisher: string | null
|
||||
publisher_place: string | null
|
||||
event_title: string | null
|
||||
event_place: string | null
|
||||
event_date: string | null
|
||||
publication_year: number | null
|
||||
publication_month: number | null
|
||||
publication_day: number | null
|
||||
accessed_date: string | null
|
||||
doi: string | null
|
||||
isbn: string | null
|
||||
issn: string | null
|
||||
url: string | null
|
||||
patent_country: string | null
|
||||
patent_number: string | null
|
||||
standard_number: string | null
|
||||
report_number: string | null
|
||||
arxiv_id: string | null
|
||||
abstract: string | null
|
||||
keywords: string | null
|
||||
note: string | null
|
||||
citation_key: string | null
|
||||
language: string | null
|
||||
authors: ReferenceAuthor[]
|
||||
tags: ReferenceTagRef[]
|
||||
citation_count: number
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
/** One sentence that cites a reference — the reverse lookup. */
|
||||
export interface ReferenceCitation {
|
||||
citation_id: number
|
||||
sentence_id: number
|
||||
sentence_content: string
|
||||
/** 引用内容 — the passage the sentence quotes. */
|
||||
quote: string
|
||||
paper_id: number
|
||||
paper_title: string
|
||||
paper_template_filed_sort: number
|
||||
/** The heading the paper's template puts at that position, if any. */
|
||||
paragraph_name: string | null
|
||||
}
|
||||
|
||||
/** Everything a reference may carry. Only `title` is required. */
|
||||
export interface ReferencePayload {
|
||||
type: string
|
||||
title: string
|
||||
subtitle: string | null
|
||||
title_translated: string | null
|
||||
title_short: string | null
|
||||
container_title: string | null
|
||||
container_title_short: string | null
|
||||
series_title: string | null
|
||||
series_number: string | null
|
||||
edition: string | null
|
||||
volume: string | null
|
||||
issue: string | null
|
||||
pages: string | null
|
||||
article_number: string | null
|
||||
publisher: string | null
|
||||
publisher_place: string | null
|
||||
event_title: string | null
|
||||
event_place: string | null
|
||||
event_date: string | null
|
||||
publication_year: number | null
|
||||
publication_month: number | null
|
||||
publication_day: number | null
|
||||
accessed_date: string | null
|
||||
doi: string | null
|
||||
isbn: string | null
|
||||
issn: string | null
|
||||
url: string | null
|
||||
patent_country: string | null
|
||||
patent_number: string | null
|
||||
standard_number: string | null
|
||||
report_number: string | null
|
||||
arxiv_id: string | null
|
||||
abstract: string | null
|
||||
keywords: string | null
|
||||
note: string | null
|
||||
citation_key: string | null
|
||||
language: string | null
|
||||
authors: ReferenceAuthorInput[]
|
||||
tag_ids: number[]
|
||||
}
|
||||
|
||||
export interface ReferenceQuery extends PageQuery {
|
||||
type?: string | null
|
||||
year?: number | null
|
||||
/** `true` only what is already cited, `false` only what is not. */
|
||||
cited?: boolean | null
|
||||
/** Tag ids; more than one narrows to the rows carrying all of them. */
|
||||
tag_ids?: number[]
|
||||
}
|
||||
|
||||
export async function listReferences(
|
||||
query: ReferenceQuery = {},
|
||||
): Promise<PageResult<ReferenceListItem>> {
|
||||
// Built as a `URLSearchParams` rather than a plain object because the tag
|
||||
// filter repeats its key: `tag=1&tag=2` means "carries both labels", while
|
||||
// the default array serialisation would send `tag[]=1`.
|
||||
const search = new URLSearchParams()
|
||||
const set = (
|
||||
key: string,
|
||||
value: string | number | boolean | null | undefined,
|
||||
): void => {
|
||||
if (value == null || value === '') return
|
||||
search.set(key, String(value))
|
||||
}
|
||||
|
||||
set('keyword', query.keyword)
|
||||
set('type', query.type)
|
||||
set('year', query.year)
|
||||
set('cited', query.cited)
|
||||
set('page', query.page)
|
||||
set('page_size', query.page_size)
|
||||
for (const tagId of query.tag_ids ?? []) search.append('tag', String(tagId))
|
||||
|
||||
const { data } = await http.get<PageResult<ReferenceListItem>>('/references', {
|
||||
params: search,
|
||||
})
|
||||
return data
|
||||
}
|
||||
|
||||
export async function getReference(id: number): Promise<ReferenceDetail> {
|
||||
const { data } = await http.get<ReferenceDetail>(`/references/${id}`)
|
||||
return data
|
||||
}
|
||||
|
||||
/** Every sentence that cites this reference, with the paper it sits in. */
|
||||
export async function listReferenceCitations(id: number): Promise<ReferenceCitation[]> {
|
||||
const { data } = await http.get<ReferenceCitation[]>(`/references/${id}/citations`)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function createReference(payload: ReferencePayload): Promise<ReferenceDetail> {
|
||||
const { data } = await http.post<ReferenceDetail>('/references', payload)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function updateReference(
|
||||
id: number,
|
||||
payload: Partial<ReferencePayload>,
|
||||
): Promise<ReferenceDetail> {
|
||||
const { data } = await http.patch<ReferenceDetail>(`/references/${id}`, payload)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function deleteReference(id: number): Promise<void> {
|
||||
await http.delete(`/references/${id}`)
|
||||
}
|
||||
|
||||
export async function batchDeleteReferences(ids: number[]): Promise<BatchDeleteResult> {
|
||||
const { data } = await http.post<BatchDeleteResult>('/references/batch-delete', { ids })
|
||||
return data
|
||||
}
|
||||
@@ -4,22 +4,36 @@
|
||||
*
|
||||
* It is driven by `route.meta.section`, so the menu a URL belongs to is a
|
||||
* property of the route table rather than of component state — deep linking to
|
||||
* `/templates/fields` or `/papers/12` shows the right menu on first paint, and
|
||||
* the aside disappears on routes that declare no section (the welcome page).
|
||||
* `/templates/fields`, `/papers/12` or `/references?tag=3` shows the right menu
|
||||
* on first paint, and the aside disappears on routes that declare no section
|
||||
* (the welcome page).
|
||||
*
|
||||
* The 论文 menu is the exception to the static list: it carries the papers
|
||||
* themselves, so it is read from the store rather than written here. Every page
|
||||
* that creates, renames or deletes a paper reloads that store, which is what
|
||||
* keeps the menu and the table showing the same thing.
|
||||
* Two menus are exceptions to the static list, and both carry real data rather
|
||||
* than links: 论文 lists the papers themselves, and 参考文献 lists the tags, so
|
||||
* either can be opened straight from the rail. Each is read from its store, and
|
||||
* every page that changes one reloads that store, which is what keeps the rail
|
||||
* and the table showing the same thing.
|
||||
*/
|
||||
import { computed, onMounted, ref, watch, type Component } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { Document, Expand, Files, Fold, Plus, Search, Setting } from '@element-plus/icons-vue'
|
||||
import {
|
||||
Collection,
|
||||
Document,
|
||||
Expand,
|
||||
Files,
|
||||
Fold,
|
||||
Plus,
|
||||
PriceTag,
|
||||
Search,
|
||||
Setting,
|
||||
} from '@element-plus/icons-vue'
|
||||
|
||||
import type { PaperListItem } from '@/api/papers'
|
||||
import type { ReferenceTag } from '@/api/referenceTags'
|
||||
import { ASIDE_INSET, asideWidth } from '@/layout'
|
||||
import { useAppStore } from '@/stores/app'
|
||||
import { usePapersStore } from '@/stores/papers'
|
||||
import { useReferenceTagsStore } from '@/stores/referenceTags'
|
||||
|
||||
interface AsideItem {
|
||||
index: string
|
||||
@@ -38,6 +52,7 @@ const props = defineProps<{ section: string }>()
|
||||
const route = useRoute()
|
||||
const appStore = useAppStore()
|
||||
const papersStore = usePapersStore()
|
||||
const tagsStore = useReferenceTagsStore()
|
||||
|
||||
const MENUS: Record<string, AsideMenu> = {
|
||||
papers: {
|
||||
@@ -56,6 +71,17 @@ const MENUS: Record<string, AsideMenu> = {
|
||||
{ index: '/templates/fields', label: '字段管理', icon: Setting },
|
||||
],
|
||||
},
|
||||
// 标签管理 is listed as a page of this section rather than as a fourth
|
||||
// top-level entry: a tag exists to file the literature, so it is managed next
|
||||
// to it.
|
||||
references: {
|
||||
title: '参考文献',
|
||||
items: [
|
||||
{ index: '/references', label: '文献列表', icon: Collection },
|
||||
{ index: '/references?new=1', label: '新增文献', icon: Plus },
|
||||
{ index: '/references/tags', label: '标签管理', icon: PriceTag },
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
const menu = computed<AsideMenu | null>(() => MENUS[props.section] ?? null)
|
||||
@@ -68,13 +94,18 @@ const inset = ASIDE_INSET
|
||||
/** Filter for the paper list: a rail this narrow cannot show every paper. */
|
||||
const paperFilter = ref('')
|
||||
|
||||
/** The same problem for the tag list, which grows with the library. */
|
||||
const tagFilter = ref('')
|
||||
|
||||
const papers = computed<PaperListItem[]>(() => papersStore.items)
|
||||
const tags = computed<ReferenceTag[]>(() => tagsStore.items)
|
||||
|
||||
/**
|
||||
* The filter appears only once the list is long enough to need it. Below that
|
||||
* it would occupy a menu item's worth of height to hide nothing.
|
||||
* A filter appears only once the list is long enough to need it. Below that it
|
||||
* would occupy a menu item's worth of height to hide nothing.
|
||||
*/
|
||||
const filterable = computed(() => papers.value.length > 6)
|
||||
const tagsFilterable = computed(() => tags.value.length > 6)
|
||||
|
||||
const filteredPapers = computed(() => {
|
||||
const keyword = paperFilter.value.trim().toLowerCase()
|
||||
@@ -82,19 +113,41 @@ const filteredPapers = computed(() => {
|
||||
return papers.value.filter((paper) => paper.title.toLowerCase().includes(keyword))
|
||||
})
|
||||
|
||||
/** The active entry: either a static one or the paper currently open. */
|
||||
const activeIndex = computed(() =>
|
||||
route.path === '/papers' && route.query.new ? '/papers?new=1' : route.path,
|
||||
)
|
||||
const filteredTags = computed(() => {
|
||||
const keyword = tagFilter.value.trim().toLowerCase()
|
||||
if (!keyword) return tags.value
|
||||
return tags.value.filter((tag) => tag.name.toLowerCase().includes(keyword))
|
||||
})
|
||||
|
||||
/** Load the menu's list the first time the 论文 section is opened. */
|
||||
function ensurePapers(): void {
|
||||
if (props.section !== 'papers') return
|
||||
if (!papersStore.loaded && !papersStore.loading) void papersStore.reload()
|
||||
/**
|
||||
* The active entry.
|
||||
*
|
||||
* The two list menus are entered through a query parameter that *is* the view —
|
||||
* 新建论文 opens the create dialog, a tag narrows the library — so the highlight
|
||||
* has to follow the parameter rather than the path alone.
|
||||
*/
|
||||
const activeIndex = computed(() => {
|
||||
if (props.section === 'papers' && route.path === '/papers' && route.query.new) {
|
||||
return '/papers?new=1'
|
||||
}
|
||||
if (props.section === 'references' && route.path === '/references' && route.query.tag) {
|
||||
return `/references?tag=${route.query.tag}`
|
||||
}
|
||||
return route.path
|
||||
})
|
||||
|
||||
/** Load the menu's list the first time its section is opened. */
|
||||
function ensureLists(): void {
|
||||
if (props.section === 'papers' && !papersStore.loaded && !papersStore.loading) {
|
||||
void papersStore.reload()
|
||||
}
|
||||
if (props.section === 'references') {
|
||||
void tagsStore.ensureLoaded()
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => props.section, ensurePapers)
|
||||
onMounted(ensurePapers)
|
||||
watch(() => props.section, ensureLists)
|
||||
onMounted(ensureLists)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -184,6 +237,60 @@ onMounted(ensurePapers)
|
||||
没有匹配的论文。
|
||||
</p>
|
||||
</template>
|
||||
|
||||
<!-- 参考文献 carries the labels themselves: picking one filters the
|
||||
library, which is the whole reason the tags exist. -->
|
||||
<template v-if="section === 'references'">
|
||||
<div v-if="tagsFilterable && !collapsed" class="aside-filter">
|
||||
<el-input
|
||||
v-model="tagFilter"
|
||||
size="small"
|
||||
placeholder="筛选标签"
|
||||
clearable
|
||||
:prefix-icon="Search"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<el-menu
|
||||
:default-active="activeIndex"
|
||||
:collapse="collapsed"
|
||||
:collapse-transition="false"
|
||||
router
|
||||
class="aside-menu aside-menu--tags"
|
||||
>
|
||||
<el-menu-item
|
||||
v-for="tag in filteredTags"
|
||||
:key="tag.id"
|
||||
:index="`/references?tag=${tag.id}`"
|
||||
>
|
||||
<el-icon><PriceTag /></el-icon>
|
||||
<template #title>
|
||||
<el-tooltip
|
||||
:content="`${tag.name}(${tag.reference_count} 篇文献)`"
|
||||
placement="right"
|
||||
:show-after="400"
|
||||
:disabled="collapsed"
|
||||
>
|
||||
<span class="aside-tag">
|
||||
<span
|
||||
class="aside-tag-dot"
|
||||
:style="{ backgroundColor: tag.color }"
|
||||
/>
|
||||
<span class="aside-tag-name">{{ tag.name }}</span>
|
||||
<span class="aside-tag-count">{{ tag.reference_count }}</span>
|
||||
</span>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-menu-item>
|
||||
</el-menu>
|
||||
|
||||
<p v-if="!collapsed && tags.length === 0" class="aside-empty">
|
||||
还没有标签。先在「标签管理」里建几个,用来给文献归档。
|
||||
</p>
|
||||
<p v-else-if="!collapsed && filteredTags.length === 0" class="aside-empty">
|
||||
没有匹配的标签。
|
||||
</p>
|
||||
</template>
|
||||
</div>
|
||||
</el-aside>
|
||||
</template>
|
||||
@@ -249,6 +356,12 @@ onMounted(ensurePapers)
|
||||
border-top: 1px solid var(--el-border-color-lighter);
|
||||
}
|
||||
|
||||
.aside-menu--tags {
|
||||
margin-top: 4px;
|
||||
padding-top: 4px;
|
||||
border-top: 1px solid var(--el-border-color-lighter);
|
||||
}
|
||||
|
||||
/* A collapsed el-menu keeps a fixed 64px width that no longer matches the
|
||||
56px rail, so the items would sit off-centre. */
|
||||
.aside-menu.el-menu--collapse {
|
||||
@@ -302,6 +415,42 @@ onMounted(ensurePapers)
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* A tag in the rail: its colour, its name, and how much carries it — the count
|
||||
is what tells the writer whether a label is worth keeping. */
|
||||
.aside-tag {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.aside-tag-dot {
|
||||
flex: 0 0 auto;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.aside-tag-name {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.aside-tag-count {
|
||||
margin-left: auto;
|
||||
padding-left: 6px;
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-placeholder);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.aside-menu--tags :deep(.el-menu-item > span) {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.aside-empty {
|
||||
margin: 8px 12px;
|
||||
font-size: 12px;
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
<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>
|
||||
@@ -0,0 +1,875 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* Create / edit dialog for one reference in the library.
|
||||
*
|
||||
* The form is the field set of :mod:`app.models.reference` grouped the way a
|
||||
* citation is read — what it is, who wrote it, where it was published, how to
|
||||
* find it again — rather than one flat list of forty inputs. Everything except
|
||||
* the title is optional, because the same schema has to hold a one-line journal
|
||||
* article and a patent with a country, a number and a 公告日期.
|
||||
*
|
||||
* Two behaviours are deliberate:
|
||||
*
|
||||
* * **Tags are chosen, not typed into existence.** The picker offers the labels
|
||||
* that exist; typing a new name is allowed, but the label is created through
|
||||
* the tag API *before* the reference is saved, so a reference can never be
|
||||
* stored pointing at a label that does not exist. Creating it first is also
|
||||
* what lets the same label be applied to the next document from the list.
|
||||
* * **Editing fetches the full row.** The table's shape deliberately drops the
|
||||
* contributors, the abstract and the note, so the dialog asks for the detail
|
||||
* rather than editing a list item and losing what it never carried.
|
||||
*/
|
||||
import { computed, reactive, ref, watch } from 'vue'
|
||||
import { ArrowDown, ArrowUp, Delete, Plus } from '@element-plus/icons-vue'
|
||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||||
|
||||
import { errorMessage } from '@/api/client'
|
||||
import {
|
||||
createReference,
|
||||
getReference,
|
||||
updateReference,
|
||||
REFERENCE_AUTHOR_ROLE_OPTIONS,
|
||||
REFERENCE_LANGUAGE_OPTIONS,
|
||||
REFERENCE_TYPE_OPTIONS,
|
||||
referenceTypeLabel,
|
||||
referenceTypeMarker,
|
||||
type ReferenceListItem,
|
||||
type ReferencePayload,
|
||||
} from '@/api/references'
|
||||
import {
|
||||
createReferenceTag,
|
||||
TAG_COLOR_PRESETS,
|
||||
type ReferenceTag,
|
||||
} from '@/api/referenceTags'
|
||||
import { useReferenceTagsStore } from '@/stores/referenceTags'
|
||||
|
||||
const props = defineProps<{
|
||||
/** Visibility, used with `v-model`. */
|
||||
modelValue: boolean
|
||||
/** The reference being edited, or `null` to add a new one. */
|
||||
reference: ReferenceListItem | null
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: boolean]
|
||||
/** Emitted after a successful write, so the table and the rail can refresh. */
|
||||
saved: []
|
||||
}>()
|
||||
|
||||
const tagsStore = useReferenceTagsStore()
|
||||
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (value: boolean) => emit('update:modelValue', value),
|
||||
})
|
||||
|
||||
/** One contributor row as the form edits it. */
|
||||
interface AuthorRow {
|
||||
name: string
|
||||
family_name: string
|
||||
given_name: string
|
||||
role: string
|
||||
}
|
||||
|
||||
/** The text fields, all of them strings, `''` standing for "not filled in". */
|
||||
interface FormState {
|
||||
type: string
|
||||
title: string
|
||||
subtitle: string
|
||||
title_translated: string
|
||||
title_short: string
|
||||
container_title: string
|
||||
container_title_short: string
|
||||
series_title: string
|
||||
series_number: string
|
||||
edition: string
|
||||
volume: string
|
||||
issue: string
|
||||
pages: string
|
||||
article_number: string
|
||||
publisher: string
|
||||
publisher_place: string
|
||||
event_title: string
|
||||
event_place: string
|
||||
event_date: string
|
||||
doi: string
|
||||
isbn: string
|
||||
issn: string
|
||||
url: string
|
||||
patent_country: string
|
||||
patent_number: string
|
||||
standard_number: string
|
||||
report_number: string
|
||||
arxiv_id: string
|
||||
abstract: string
|
||||
keywords: string
|
||||
note: string
|
||||
citation_key: string
|
||||
language: string
|
||||
}
|
||||
|
||||
function emptyForm(): FormState {
|
||||
return {
|
||||
type: 'journal-article',
|
||||
title: '',
|
||||
subtitle: '',
|
||||
title_translated: '',
|
||||
title_short: '',
|
||||
container_title: '',
|
||||
container_title_short: '',
|
||||
series_title: '',
|
||||
series_number: '',
|
||||
edition: '',
|
||||
volume: '',
|
||||
issue: '',
|
||||
pages: '',
|
||||
article_number: '',
|
||||
publisher: '',
|
||||
publisher_place: '',
|
||||
event_title: '',
|
||||
event_place: '',
|
||||
event_date: '',
|
||||
doi: '',
|
||||
isbn: '',
|
||||
issn: '',
|
||||
url: '',
|
||||
patent_country: '',
|
||||
patent_number: '',
|
||||
standard_number: '',
|
||||
report_number: '',
|
||||
arxiv_id: '',
|
||||
abstract: '',
|
||||
keywords: '',
|
||||
note: '',
|
||||
citation_key: '',
|
||||
language: '',
|
||||
}
|
||||
}
|
||||
|
||||
const formRef = ref<FormInstance>()
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const activeTab = ref('basic')
|
||||
|
||||
const form = reactive<FormState>(emptyForm())
|
||||
const authors = ref<AuthorRow[]>([])
|
||||
/** Year / month / day are independently optional, exactly as the API stores them. */
|
||||
const dates = reactive<{
|
||||
year: number | undefined
|
||||
month: number | undefined
|
||||
day: number | undefined
|
||||
accessed: string | null
|
||||
}>({ year: undefined, month: undefined, day: undefined, accessed: null })
|
||||
|
||||
/**
|
||||
* The chosen labels.
|
||||
*
|
||||
* A number is a tag that exists; a string is a name typed into the picker that
|
||||
* has no id yet. The distinction is resolved on save, where a missing label is
|
||||
* created first — which is what keeps "the tag exists" true for every stored
|
||||
* reference.
|
||||
*/
|
||||
const tagValues = ref<(number | string)[]>([])
|
||||
|
||||
const rules: FormRules = {
|
||||
title: [{ required: true, message: '请填写文献题名', trigger: 'blur' }],
|
||||
}
|
||||
|
||||
const title = computed(() => (props.reference ? '编辑文献' : '新增文献'))
|
||||
|
||||
const tags = computed<ReferenceTag[]>(() => tagsStore.items)
|
||||
|
||||
/** An online resource is identified by its location and nothing else. */
|
||||
const needsUrl = computed(() => form.type === 'web-page' || form.type === 'dataset')
|
||||
|
||||
/** What the chosen type prints after the title, so the writer can see the shape. */
|
||||
const typeHint = computed(() => {
|
||||
const marker = referenceTypeMarker(form.type)
|
||||
const label = referenceTypeLabel(form.type)
|
||||
return marker ? `${label} · GB/T 7714 标志 [${marker}]` : label
|
||||
})
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
async (open) => {
|
||||
if (!open) return
|
||||
|
||||
formRef.value?.clearValidate()
|
||||
Object.assign(form, emptyForm())
|
||||
authors.value = []
|
||||
Object.assign(dates, { year: undefined, month: undefined, day: undefined, accessed: null })
|
||||
tagValues.value = []
|
||||
activeTab.value = 'basic'
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
void tagsStore.ensureLoaded()
|
||||
|
||||
if (props.reference) {
|
||||
const detail = await getReference(props.reference.id)
|
||||
Object.assign(form, {
|
||||
type: detail.type,
|
||||
title: detail.title,
|
||||
subtitle: detail.subtitle ?? '',
|
||||
title_translated: detail.title_translated ?? '',
|
||||
title_short: detail.title_short ?? '',
|
||||
container_title: detail.container_title ?? '',
|
||||
container_title_short: detail.container_title_short ?? '',
|
||||
series_title: detail.series_title ?? '',
|
||||
series_number: detail.series_number ?? '',
|
||||
edition: detail.edition ?? '',
|
||||
volume: detail.volume ?? '',
|
||||
issue: detail.issue ?? '',
|
||||
pages: detail.pages ?? '',
|
||||
article_number: detail.article_number ?? '',
|
||||
publisher: detail.publisher ?? '',
|
||||
publisher_place: detail.publisher_place ?? '',
|
||||
event_title: detail.event_title ?? '',
|
||||
event_place: detail.event_place ?? '',
|
||||
event_date: detail.event_date ?? '',
|
||||
doi: detail.doi ?? '',
|
||||
isbn: detail.isbn ?? '',
|
||||
issn: detail.issn ?? '',
|
||||
url: detail.url ?? '',
|
||||
patent_country: detail.patent_country ?? '',
|
||||
patent_number: detail.patent_number ?? '',
|
||||
standard_number: detail.standard_number ?? '',
|
||||
report_number: detail.report_number ?? '',
|
||||
arxiv_id: detail.arxiv_id ?? '',
|
||||
abstract: detail.abstract ?? '',
|
||||
keywords: detail.keywords ?? '',
|
||||
note: detail.note ?? '',
|
||||
citation_key: detail.citation_key ?? '',
|
||||
language: detail.language ?? '',
|
||||
})
|
||||
authors.value = detail.authors.map((author) => ({
|
||||
name: author.name,
|
||||
family_name: author.family_name ?? '',
|
||||
given_name: author.given_name ?? '',
|
||||
role: author.role,
|
||||
}))
|
||||
dates.year = detail.publication_year ?? undefined
|
||||
dates.month = detail.publication_month ?? undefined
|
||||
dates.day = detail.publication_day ?? undefined
|
||||
dates.accessed = detail.accessed_date
|
||||
tagValues.value = detail.tags.map((tag) => tag.id)
|
||||
} else {
|
||||
// A journal article is what most additions are, and it is already the
|
||||
// API's default; one contributor row is the minimum that reads as a
|
||||
// form rather than an empty table.
|
||||
authors.value = [{ name: '', family_name: '', given_name: '', role: 'author' }]
|
||||
}
|
||||
} catch (error) {
|
||||
ElMessage.error(errorMessage(error))
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
function addAuthor(): void {
|
||||
authors.value.push({ name: '', family_name: '', given_name: '', role: 'author' })
|
||||
}
|
||||
|
||||
function removeAuthor(index: number): void {
|
||||
authors.value.splice(index, 1)
|
||||
}
|
||||
|
||||
/** Move a contributor one place, because the printed order is the stored order. */
|
||||
function moveAuthor(index: number, delta: number): void {
|
||||
const target = index + delta
|
||||
const row = authors.value[index]
|
||||
if (!row || target < 0 || target >= authors.value.length) return
|
||||
authors.value.splice(index, 1)
|
||||
authors.value.splice(target, 0, row)
|
||||
}
|
||||
|
||||
/** A colour for a label created from the picker, cycling the shared palette. */
|
||||
function nextTagColor(): string {
|
||||
const preset = TAG_COLOR_PRESETS[tagsStore.items.length % TAG_COLOR_PRESETS.length]
|
||||
return preset ?? '#409EFF'
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn the picker's values into tag ids, creating labels that do not exist yet.
|
||||
*
|
||||
* Runs before the reference is written, so a failure here leaves nothing
|
||||
* half-saved. A label that turns out to exist after all — typed twice, or added
|
||||
* in another tab while this dialog was open — is matched by name instead of
|
||||
* being reported as a conflict.
|
||||
*/
|
||||
async function resolveTagIds(values: (number | string)[]): Promise<number[]> {
|
||||
const ids: number[] = []
|
||||
|
||||
for (const value of values) {
|
||||
if (typeof value === 'number') {
|
||||
ids.push(value)
|
||||
continue
|
||||
}
|
||||
|
||||
const name = value.trim()
|
||||
if (!name) continue
|
||||
|
||||
const known = tagsStore.byName(name)
|
||||
if (known) {
|
||||
ids.push(known.id)
|
||||
continue
|
||||
}
|
||||
|
||||
try {
|
||||
const created = await createReferenceTag({
|
||||
name,
|
||||
color: nextTagColor(),
|
||||
note: null,
|
||||
})
|
||||
ids.push(created.id)
|
||||
await tagsStore.reload()
|
||||
} catch (error) {
|
||||
await tagsStore.reload()
|
||||
const raced = tagsStore.byName(name)
|
||||
if (!raced) throw error
|
||||
ids.push(raced.id)
|
||||
}
|
||||
}
|
||||
|
||||
// A label cannot be applied twice, and two ids can name the same row only by
|
||||
// mistake — de-duplicate rather than sending a list the API would store once.
|
||||
return [...new Set(ids)]
|
||||
}
|
||||
|
||||
function optional(value: string): string | null {
|
||||
const text = value.trim()
|
||||
return text ? text : null
|
||||
}
|
||||
|
||||
async function submit(): Promise<void> {
|
||||
const valid = await formRef.value?.validate().catch(() => false)
|
||||
if (!valid) return
|
||||
|
||||
const named = authors.value.filter((author) => author.name.trim())
|
||||
const blank = authors.value.length - named.length
|
||||
if (blank > 0) {
|
||||
ElMessage.warning('有责任者还没填姓名,请补全或删掉那一行')
|
||||
activeTab.value = 'authors'
|
||||
return
|
||||
}
|
||||
|
||||
saving.value = true
|
||||
try {
|
||||
const payload: ReferencePayload = {
|
||||
type: form.type,
|
||||
title: form.title.trim(),
|
||||
subtitle: optional(form.subtitle),
|
||||
title_translated: optional(form.title_translated),
|
||||
title_short: optional(form.title_short),
|
||||
container_title: optional(form.container_title),
|
||||
container_title_short: optional(form.container_title_short),
|
||||
series_title: optional(form.series_title),
|
||||
series_number: optional(form.series_number),
|
||||
edition: optional(form.edition),
|
||||
volume: optional(form.volume),
|
||||
issue: optional(form.issue),
|
||||
pages: optional(form.pages),
|
||||
article_number: optional(form.article_number),
|
||||
publisher: optional(form.publisher),
|
||||
publisher_place: optional(form.publisher_place),
|
||||
event_title: optional(form.event_title),
|
||||
event_place: optional(form.event_place),
|
||||
event_date: optional(form.event_date),
|
||||
publication_year: dates.year ?? null,
|
||||
publication_month: dates.month ?? null,
|
||||
publication_day: dates.day ?? null,
|
||||
accessed_date: dates.accessed || null,
|
||||
doi: optional(form.doi),
|
||||
isbn: optional(form.isbn),
|
||||
issn: optional(form.issn),
|
||||
url: optional(form.url),
|
||||
patent_country: optional(form.patent_country),
|
||||
patent_number: optional(form.patent_number),
|
||||
standard_number: optional(form.standard_number),
|
||||
report_number: optional(form.report_number),
|
||||
arxiv_id: optional(form.arxiv_id),
|
||||
abstract: optional(form.abstract),
|
||||
keywords: optional(form.keywords),
|
||||
note: optional(form.note),
|
||||
citation_key: optional(form.citation_key),
|
||||
language: form.language || null,
|
||||
authors: named.map((author, index) => ({
|
||||
name: author.name.trim(),
|
||||
family_name: optional(author.family_name),
|
||||
given_name: optional(author.given_name),
|
||||
role: author.role,
|
||||
sort: index + 1,
|
||||
})),
|
||||
tag_ids: await resolveTagIds(tagValues.value),
|
||||
}
|
||||
|
||||
if (props.reference) {
|
||||
await updateReference(props.reference.id, payload)
|
||||
ElMessage.success('文献已更新')
|
||||
} else {
|
||||
await createReference(payload)
|
||||
ElMessage.success('文献已加入库中')
|
||||
}
|
||||
emit('saved')
|
||||
visible.value = false
|
||||
} catch (error) {
|
||||
ElMessage.error(errorMessage(error))
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="visible"
|
||||
:title="title"
|
||||
width="min(880px, 95vw)"
|
||||
:close-on-click-modal="false"
|
||||
append-to-body
|
||||
class="reference-dialog"
|
||||
>
|
||||
<el-alert
|
||||
v-if="needsUrl"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
show-icon
|
||||
title="网页、数据集类型的文献必须至少填 URL 或 DOI"
|
||||
class="form-alert"
|
||||
/>
|
||||
|
||||
<el-form
|
||||
ref="formRef"
|
||||
v-loading="loading"
|
||||
:model="form"
|
||||
:rules="rules"
|
||||
label-width="96px"
|
||||
label-position="right"
|
||||
>
|
||||
<el-tabs v-model="activeTab" class="form-tabs">
|
||||
<el-tab-pane label="基本信息" name="basic">
|
||||
<div class="grid">
|
||||
<el-form-item label="文献类型">
|
||||
<el-select v-model="form.type" class="full">
|
||||
<el-option
|
||||
v-for="option in REFERENCE_TYPE_OPTIONS"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
:label="`${option.label} [${option.marker}]`"
|
||||
/>
|
||||
</el-select>
|
||||
<div class="field-hint">{{ typeHint }}</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="语种">
|
||||
<el-select v-model="form.language" clearable placeholder="未指定" class="full">
|
||||
<el-option
|
||||
v-for="option in REFERENCE_LANGUAGE_OPTIONS"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
:label="option.label"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</div>
|
||||
|
||||
<el-form-item label="文献题名" prop="title">
|
||||
<el-input
|
||||
v-model="form.title"
|
||||
placeholder="如 技术惯性与冲量的耦合机制"
|
||||
maxlength="512"
|
||||
show-word-limit
|
||||
clearable
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<div class="grid">
|
||||
<el-form-item label="副题名">
|
||||
<el-input v-model="form.subtitle" placeholder="冒号后的那半句" clearable />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="并列题名">
|
||||
<el-input v-model="form.title_translated" placeholder="另一个语种的题名" clearable />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="简称">
|
||||
<el-input v-model="form.title_short" placeholder="正文里简称它什么" clearable />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="文献关键词">
|
||||
<el-input
|
||||
v-model="form.keywords"
|
||||
placeholder="逗号分隔,如 技术演化, 惯性"
|
||||
clearable
|
||||
/>
|
||||
</el-form-item>
|
||||
</div>
|
||||
|
||||
<el-form-item label="标签">
|
||||
<el-select
|
||||
v-model="tagValues"
|
||||
multiple
|
||||
filterable
|
||||
allow-create
|
||||
default-first-option
|
||||
:reserve-keyword="false"
|
||||
placeholder="选择已有标签,或直接输入新名称"
|
||||
class="full"
|
||||
>
|
||||
<el-option
|
||||
v-for="tag in tags"
|
||||
:key="tag.id"
|
||||
:value="tag.id"
|
||||
:label="tag.name"
|
||||
>
|
||||
<span class="tag-option">
|
||||
<span class="tag-dot" :style="{ backgroundColor: tag.color }" />
|
||||
<span>{{ tag.name }}</span>
|
||||
<span v-if="tag.note" class="tag-option-note">{{ tag.note }}</span>
|
||||
</span>
|
||||
</el-option>
|
||||
</el-select>
|
||||
<div class="field-hint">
|
||||
标签是给自己归档用的,不会出现在参考文献表里;输入库里没有的名称会在保存时自动建好。
|
||||
也可以先去
|
||||
<RouterLink to="/references/tags">标签管理</RouterLink>
|
||||
里整理。
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane label="责任者" name="authors">
|
||||
<div class="authors-head">
|
||||
<span class="authors-hint">
|
||||
按引用时打印的顺序排列;姓名是必填的,姓 / 名供需要缩写或倒装的格式使用。
|
||||
</span>
|
||||
<el-button :icon="Plus" size="small" @click="addAuthor">添加责任者</el-button>
|
||||
</div>
|
||||
|
||||
<div v-if="authors.length === 0" class="authors-empty">
|
||||
还没有责任者。机构作者(如 世界卫生组织)直接填姓名即可。
|
||||
</div>
|
||||
|
||||
<div v-for="(author, index) in authors" :key="index" class="author-row">
|
||||
<span class="author-order">{{ index + 1 }}</span>
|
||||
<el-input v-model="author.name" placeholder="姓名,如 张三" class="author-name" />
|
||||
<el-input v-model="author.family_name" placeholder="姓" class="author-part" />
|
||||
<el-input v-model="author.given_name" placeholder="名" class="author-part" />
|
||||
<el-select v-model="author.role" class="author-role">
|
||||
<el-option
|
||||
v-for="option in REFERENCE_AUTHOR_ROLE_OPTIONS"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
:label="option.label"
|
||||
/>
|
||||
</el-select>
|
||||
<div class="author-actions">
|
||||
<el-button
|
||||
link
|
||||
:icon="ArrowUp"
|
||||
:disabled="index === 0"
|
||||
@click="moveAuthor(index, -1)"
|
||||
/>
|
||||
<el-button
|
||||
link
|
||||
:icon="ArrowDown"
|
||||
:disabled="index === authors.length - 1"
|
||||
@click="moveAuthor(index, 1)"
|
||||
/>
|
||||
<el-button link type="danger" :icon="Delete" @click="removeAuthor(index)" />
|
||||
</div>
|
||||
</div>
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane label="出版信息" name="publish">
|
||||
<div class="grid">
|
||||
<el-form-item label="刊名/书名">
|
||||
<el-input v-model="form.container_title" placeholder="期刊名、论文集名、报纸名" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="刊名缩写">
|
||||
<el-input v-model="form.container_title_short" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="丛书名">
|
||||
<el-input v-model="form.series_title" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="丛书号">
|
||||
<el-input v-model="form.series_number" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="版本">
|
||||
<el-input v-model="form.edition" placeholder="如 3版 / 2nd ed." clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="文章编号">
|
||||
<el-input v-model="form.article_number" placeholder="没有页码时用" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="卷">
|
||||
<el-input v-model="form.volume" placeholder="如 198、S1" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="期">
|
||||
<el-input v-model="form.issue" placeholder="如 3、Suppl." clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="页码">
|
||||
<el-input v-model="form.pages" placeholder="如 122-141" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="出版者">
|
||||
<el-input v-model="form.publisher" placeholder="出版社 / 学校 / 发布机构" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="出版地">
|
||||
<el-input v-model="form.publisher_place" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="引用日期">
|
||||
<el-date-picker
|
||||
v-model="dates.accessed"
|
||||
type="date"
|
||||
value-format="YYYY-MM-DD"
|
||||
placeholder="在线资源的访问日期"
|
||||
class="full"
|
||||
/>
|
||||
</el-form-item>
|
||||
</div>
|
||||
|
||||
<div class="grid grid--dates">
|
||||
<el-form-item label="出版年">
|
||||
<el-input-number
|
||||
v-model="dates.year"
|
||||
:min="1"
|
||||
:max="2999"
|
||||
:controls="false"
|
||||
placeholder="2024"
|
||||
class="full"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="月">
|
||||
<el-input-number
|
||||
v-model="dates.month"
|
||||
:min="1"
|
||||
:max="12"
|
||||
:controls="false"
|
||||
placeholder="月"
|
||||
class="full"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="日">
|
||||
<el-input-number
|
||||
v-model="dates.day"
|
||||
:min="1"
|
||||
:max="31"
|
||||
:controls="false"
|
||||
placeholder="日"
|
||||
class="full"
|
||||
/>
|
||||
</el-form-item>
|
||||
</div>
|
||||
<p class="tab-note">
|
||||
年月日各自独立,知道多少填多少:书通常只有年份,报纸文章有日期,专利填公告日期。
|
||||
</p>
|
||||
|
||||
<el-divider content-position="left">会议(会议论文填这里)</el-divider>
|
||||
<div class="grid">
|
||||
<el-form-item label="会议名称">
|
||||
<el-input v-model="form.event_title" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="会议地点">
|
||||
<el-input v-model="form.event_place" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="会期">
|
||||
<el-input v-model="form.event_date" placeholder="如 2024-05-01/03" clearable />
|
||||
</el-form-item>
|
||||
</div>
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane label="标识与链接" name="ids">
|
||||
<div class="grid">
|
||||
<el-form-item label="DOI">
|
||||
<el-input
|
||||
v-model="form.doi"
|
||||
placeholder="10.1016/j.techfore.2024.123456"
|
||||
clearable
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="URL">
|
||||
<el-input v-model="form.url" placeholder="https://…" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="ISBN">
|
||||
<el-input v-model="form.isbn" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="ISSN">
|
||||
<el-input v-model="form.issn" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="专利国别">
|
||||
<el-input v-model="form.patent_country" placeholder="如 中国" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="专利号">
|
||||
<el-input v-model="form.patent_number" placeholder="如 CN114000000A" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="标准编号">
|
||||
<el-input v-model="form.standard_number" placeholder="如 GB/T 7714-2015" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="报告编号">
|
||||
<el-input v-model="form.report_number" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="arXiv">
|
||||
<el-input v-model="form.arxiv_id" placeholder="如 arXiv:2405.12345" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="引用键">
|
||||
<el-input v-model="form.citation_key" placeholder="BibTeX key,供导出用" clearable />
|
||||
</el-form-item>
|
||||
</div>
|
||||
<p class="tab-note">
|
||||
DOI 会按规范存成不带 <code>https://doi.org/</code> 前缀的形式,粘贴时带前缀也没关系。
|
||||
</p>
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane label="摘要与备注" name="notes">
|
||||
<el-form-item label="摘要">
|
||||
<el-input
|
||||
v-model="form.abstract"
|
||||
type="textarea"
|
||||
:rows="5"
|
||||
placeholder="文献摘要,选填"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注">
|
||||
<el-input
|
||||
v-model="form.note"
|
||||
type="textarea"
|
||||
:rows="4"
|
||||
placeholder="为什么留这篇、PDF 放在哪、要引用哪一段……"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</el-form>
|
||||
|
||||
<template #footer>
|
||||
<el-button @click="visible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="saving" @click="submit">
|
||||
{{ reference ? '保存修改' : '加入文献库' }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.form-alert {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
/* The tab strip stays put; only the fields scroll, so the footer never moves
|
||||
out of reach on a form this long. */
|
||||
.form-tabs :deep(.el-tabs__content) {
|
||||
max-height: min(62vh, 620px);
|
||||
overflow-y: auto;
|
||||
padding-right: 4px;
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
|
||||
/* Two fields per row on a wide dialog, one on a narrow one, without a media
|
||||
query: `auto-fit` collapses the columns when there is no room for two. */
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||
gap: 0 16px;
|
||||
}
|
||||
|
||||
.grid--dates {
|
||||
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
|
||||
}
|
||||
|
||||
.full {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.field-hint {
|
||||
width: 100%;
|
||||
margin-top: 4px;
|
||||
font-size: 12px;
|
||||
line-height: 1.6;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.tab-note {
|
||||
margin: 0 0 8px;
|
||||
font-size: 12px;
|
||||
line-height: 1.7;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.tag-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.tag-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.tag-option-note {
|
||||
margin-left: auto;
|
||||
padding-left: 12px;
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-placeholder);
|
||||
}
|
||||
|
||||
.authors-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.authors-hint {
|
||||
font-size: 12px;
|
||||
line-height: 1.6;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.authors-empty {
|
||||
padding: 12px;
|
||||
font-size: 13px;
|
||||
color: var(--el-text-color-placeholder);
|
||||
border: 1px dashed var(--el-border-color);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.author-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.author-order {
|
||||
flex: 0 0 auto;
|
||||
width: 20px;
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-placeholder);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.author-name {
|
||||
flex: 2 1 0;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.author-part {
|
||||
flex: 1 1 0;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.author-role {
|
||||
flex: 0 0 92px;
|
||||
}
|
||||
|
||||
.author-actions {
|
||||
flex: 0 0 auto;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,59 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* One tag painted as a chip.
|
||||
*
|
||||
* The colour comes from the tag row itself rather than from a class map, because
|
||||
* the palette is the writer's: a label is created with whatever hue they picked,
|
||||
* and the chip has to be that hue in the table, in the rail and in the picker.
|
||||
* The tint is derived from the colour with an alpha suffix instead of a second
|
||||
* stored value, so there is nothing to keep in step.
|
||||
*/
|
||||
import { computed } from 'vue'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
name: string
|
||||
color: string
|
||||
/** `small` in a table row, `default` where the chip carries the meaning. */
|
||||
size?: 'small' | 'default'
|
||||
/** How many references carry the label, shown as a suffix when > 0. */
|
||||
count?: number | null
|
||||
}>(),
|
||||
{ size: 'small', count: null },
|
||||
)
|
||||
|
||||
const style = computed(() => ({
|
||||
color: props.color,
|
||||
borderColor: props.color,
|
||||
backgroundColor: `${props.color}1A`,
|
||||
}))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-tag :size="size" effect="plain" :style="style" class="tag-chip">
|
||||
<span class="tag-chip-dot" :style="{ backgroundColor: color }" />
|
||||
{{ name }}<span v-if="count" class="tag-chip-count">{{ count }}</span>
|
||||
</el-tag>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.tag-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.tag-chip-dot {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.tag-chip-count {
|
||||
margin-left: 4px;
|
||||
opacity: 0.75;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,200 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* Create / edit dialog for one reference tag.
|
||||
*
|
||||
* The live chip underneath the form is the point of the dialog: a tag is only
|
||||
* ever read as a coloured chip in a table, and neither the name nor the colour
|
||||
* alone tells the writer whether the label will be recognisable at a glance.
|
||||
*/
|
||||
import { computed, reactive, ref, watch } from 'vue'
|
||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||||
|
||||
import { errorMessage } from '@/api/client'
|
||||
import {
|
||||
createReferenceTag,
|
||||
updateReferenceTag,
|
||||
DEFAULT_TAG_COLOR,
|
||||
TAG_COLOR_PRESETS,
|
||||
type ReferenceTag,
|
||||
type ReferenceTagPayload,
|
||||
} from '@/api/referenceTags'
|
||||
import { normalizeHexColor } from '@/utils/format'
|
||||
|
||||
const props = defineProps<{
|
||||
/** Visibility, used with `v-model`. */
|
||||
modelValue: boolean
|
||||
/** The tag being edited, or `null` to create a new one. */
|
||||
tag: ReferenceTag | null
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: boolean]
|
||||
/** Emitted after a successful write, so the table and the rail can refresh. */
|
||||
saved: []
|
||||
}>()
|
||||
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (value: boolean) => emit('update:modelValue', value),
|
||||
})
|
||||
|
||||
const formRef = ref<FormInstance>()
|
||||
const saving = ref(false)
|
||||
|
||||
const form = reactive<ReferenceTagPayload>({
|
||||
name: '',
|
||||
color: DEFAULT_TAG_COLOR,
|
||||
note: null,
|
||||
})
|
||||
|
||||
const rules: FormRules<ReferenceTagPayload> = {
|
||||
name: [
|
||||
{ required: true, message: '请填写标签名称', trigger: 'blur' },
|
||||
{ max: 64, message: '标签名称最多 64 个字符', trigger: 'blur' },
|
||||
],
|
||||
}
|
||||
|
||||
const title = computed(() => (props.tag ? '编辑标签' : '新建标签'))
|
||||
|
||||
// Re-seed the form each time the dialog opens, so a cancelled edit never leaks
|
||||
// into the next one.
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(open) => {
|
||||
if (!open) return
|
||||
formRef.value?.clearValidate()
|
||||
|
||||
form.name = props.tag?.name ?? ''
|
||||
form.color = props.tag?.color ?? DEFAULT_TAG_COLOR
|
||||
form.note = props.tag?.note ?? null
|
||||
},
|
||||
)
|
||||
|
||||
/** Tidy a hand-typed colour when the input loses focus. */
|
||||
function commitColor(): void {
|
||||
const normalized = normalizeHexColor(form.color)
|
||||
if (normalized) {
|
||||
form.color = normalized
|
||||
return
|
||||
}
|
||||
ElMessage.warning('颜色格式无效,请使用 #RRGGBB 或 rgb(r,g,b)')
|
||||
form.color = props.tag?.color ?? DEFAULT_TAG_COLOR
|
||||
}
|
||||
|
||||
async function submit(): Promise<void> {
|
||||
const valid = await formRef.value?.validate().catch(() => false)
|
||||
if (!valid) return
|
||||
|
||||
saving.value = true
|
||||
try {
|
||||
const payload: ReferenceTagPayload = {
|
||||
name: form.name.trim(),
|
||||
color: form.color,
|
||||
note: form.note?.trim() ? form.note.trim() : null,
|
||||
}
|
||||
|
||||
if (props.tag) {
|
||||
await updateReferenceTag(props.tag.id, payload)
|
||||
ElMessage.success('标签已更新,打过它的文献会同步显示新名称')
|
||||
} else {
|
||||
await createReferenceTag(payload)
|
||||
ElMessage.success('标签已创建,可以在文献里选用了')
|
||||
}
|
||||
emit('saved')
|
||||
visible.value = false
|
||||
} catch (error) {
|
||||
ElMessage.error(errorMessage(error))
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-dialog v-model="visible" :title="title" width="min(520px, 94vw)" append-to-body>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="88px">
|
||||
<el-form-item label="标签名称" prop="name">
|
||||
<el-input
|
||||
v-model="form.name"
|
||||
placeholder="如 综述、方法、必读"
|
||||
maxlength="64"
|
||||
show-word-limit
|
||||
clearable
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="颜色">
|
||||
<div class="color-row">
|
||||
<el-color-picker v-model="form.color" :predefine="[...TAG_COLOR_PRESETS]" />
|
||||
<el-input
|
||||
v-model="form.color"
|
||||
class="color-input"
|
||||
placeholder="#RRGGBB 或 rgb(r,g,b)"
|
||||
@blur="commitColor"
|
||||
/>
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="备注">
|
||||
<el-input
|
||||
v-model="form.note"
|
||||
placeholder="这个标签是干什么用的,选填"
|
||||
maxlength="255"
|
||||
show-word-limit
|
||||
clearable
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="预览">
|
||||
<div class="preview">
|
||||
<el-tag
|
||||
:style="{
|
||||
color: form.color,
|
||||
borderColor: form.color,
|
||||
backgroundColor: `${form.color}1A`,
|
||||
}"
|
||||
effect="plain"
|
||||
>
|
||||
{{ form.name || '(未命名标签)' }}
|
||||
</el-tag>
|
||||
<span class="preview-meta">文献表里就长这样</span>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<template #footer>
|
||||
<el-button @click="visible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="saving" @click="submit">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.color-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.color-input {
|
||||
width: 180px;
|
||||
}
|
||||
|
||||
.preview {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
width: 100%;
|
||||
min-height: 40px;
|
||||
padding: 4px 12px;
|
||||
border: 1px dashed var(--el-border-color);
|
||||
border-radius: 6px;
|
||||
background-color: var(--el-fill-color-lighter);
|
||||
}
|
||||
|
||||
.preview-meta {
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
</style>
|
||||
@@ -3,9 +3,9 @@ import { createRouter, createWebHistory } from 'vue-router'
|
||||
/**
|
||||
* Route table.
|
||||
*
|
||||
* `meta.section` groups a route under one of the two top-level entries in the
|
||||
* `meta.section` groups a route under one of the top-level entries in the
|
||||
* header. The shell reads it to decide whether — and which — second-level menu
|
||||
* to render on the right, so a new page only has to declare where it belongs.
|
||||
* to render on the left, so a new page only has to declare where it belongs.
|
||||
*/
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
@@ -48,6 +48,22 @@ const router = createRouter({
|
||||
component: () => import('@/views/templates/FieldManageView.vue'),
|
||||
meta: { title: '字段管理', section: 'templates' },
|
||||
},
|
||||
{
|
||||
// The reference library, reached from the header button to the right of
|
||||
// 论文 and 模板. `?tag=<id>` is a supported state of this page rather than
|
||||
// a separate route: the rail lists the labels and links straight to the
|
||||
// filtered library, and the table's own filter writes the same parameter.
|
||||
path: '/references',
|
||||
name: 'references',
|
||||
component: () => import('@/views/references/ReferenceListView.vue'),
|
||||
meta: { title: '参考文献', section: 'references' },
|
||||
},
|
||||
{
|
||||
path: '/references/tags',
|
||||
name: 'reference-tags',
|
||||
component: () => import('@/views/references/TagManageView.vue'),
|
||||
meta: { title: '标签管理', section: 'references' },
|
||||
},
|
||||
{
|
||||
path: '/:pathMatch(.*)*',
|
||||
name: 'not-found',
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
|
||||
import { errorMessage } from '@/api/client'
|
||||
import { fetchAllReferenceTags, type ReferenceTag } from '@/api/referenceTags'
|
||||
|
||||
/**
|
||||
* The tag library, shared by the second-level menu and the pages that change it.
|
||||
*
|
||||
* Same arrangement as the paper list and for the same reason: the rail in the
|
||||
* application shell shows the labels and the reference pages apply them, so
|
||||
* neither owns the list. A page that creates, renames or deletes a tag calls
|
||||
* `reload()` and the rail follows, without the two knowing about each other.
|
||||
*
|
||||
* The reference form reads it too, because a picker wants every label at once —
|
||||
* the API pages the list, this holds the whole of it.
|
||||
*
|
||||
* Deliberately *not* persisted: it is server data, and a stale copy restored
|
||||
* from localStorage would offer labels that no longer exist.
|
||||
*/
|
||||
export const useReferenceTagsStore = defineStore('referenceTags', () => {
|
||||
const items = ref<ReferenceTag[]>([])
|
||||
const loading = ref(false)
|
||||
/** Whether a load has ever finished, so an empty list can be told from unloaded. */
|
||||
const loaded = ref(false)
|
||||
const error = ref<string | null>(null)
|
||||
|
||||
/** Reload the whole library. Concurrent callers share one request. */
|
||||
let inFlight: Promise<void> | null = null
|
||||
|
||||
async function reload(): Promise<void> {
|
||||
if (inFlight) return inFlight
|
||||
|
||||
loading.value = true
|
||||
inFlight = (async () => {
|
||||
try {
|
||||
items.value = await fetchAllReferenceTags()
|
||||
error.value = null
|
||||
loaded.value = true
|
||||
} catch (cause) {
|
||||
error.value = errorMessage(cause)
|
||||
} finally {
|
||||
loading.value = false
|
||||
inFlight = null
|
||||
}
|
||||
})()
|
||||
return inFlight
|
||||
}
|
||||
|
||||
/** Load the library once, unless it is already loaded or loading. */
|
||||
async function ensureLoaded(): Promise<void> {
|
||||
if (loaded.value || loading.value) return
|
||||
await reload()
|
||||
}
|
||||
|
||||
/** The tag with this id, or `undefined` — for painting a chip from an id. */
|
||||
function byId(id: number): ReferenceTag | undefined {
|
||||
return items.value.find((tag) => tag.id === id)
|
||||
}
|
||||
|
||||
/** The tag with this exact name, or `undefined` — used when applying labels. */
|
||||
function byName(name: string): ReferenceTag | undefined {
|
||||
return items.value.find((tag) => tag.name === name)
|
||||
}
|
||||
|
||||
function reset(): void {
|
||||
items.value = []
|
||||
loaded.value = false
|
||||
error.value = null
|
||||
}
|
||||
|
||||
return { items, loading, loaded, error, reload, ensureLoaded, byId, byName, reset }
|
||||
})
|
||||
@@ -0,0 +1,568 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 参考文献 — the library table.
|
||||
*
|
||||
* One row per document, with the whole CRUD surface around it. Two things here
|
||||
* are the reason the table exists in this shape:
|
||||
*
|
||||
* * **The tag column is a filter as much as a column.** The rail lists the labels
|
||||
* and links to `/references?tag=<id>`; the select in the toolbar writes the
|
||||
* same query parameter back, so the URL is the single source of truth for the
|
||||
* filter and a filtered view can be pasted to someone else.
|
||||
* * **The citation count is a door, not a number.** "Which of my sentences use
|
||||
* this?" is the question that decides whether an entry is safe to delete, and
|
||||
* answering it is one click rather than a different page.
|
||||
*/
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { ChatLineSquare, Delete, Edit, Plus, Refresh, Search } from '@element-plus/icons-vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
|
||||
import { errorMessage } from '@/api/client'
|
||||
import {
|
||||
batchDeleteReferences,
|
||||
deleteReference,
|
||||
listReferences,
|
||||
REFERENCE_TYPE_OPTIONS,
|
||||
referenceTypeLabel,
|
||||
referenceTypeMarker,
|
||||
type ReferenceListItem,
|
||||
type ReferenceType,
|
||||
} from '@/api/references'
|
||||
import ReferenceCitationsDialog from '@/components/references/ReferenceCitationsDialog.vue'
|
||||
import ReferenceFormDialog from '@/components/references/ReferenceFormDialog.vue'
|
||||
import TagChip from '@/components/references/TagChip.vue'
|
||||
import { useReferenceTagsStore } from '@/stores/referenceTags'
|
||||
import { formatDateTime } from '@/utils/format'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const tagsStore = useReferenceTagsStore()
|
||||
|
||||
const loading = ref(false)
|
||||
const rows = ref<ReferenceListItem[]>([])
|
||||
const total = ref(0)
|
||||
const selection = ref<ReferenceListItem[]>([])
|
||||
|
||||
const query = reactive({
|
||||
keyword: '',
|
||||
type: null as ReferenceType | null,
|
||||
year: undefined as number | undefined,
|
||||
cited: null as boolean | null,
|
||||
page: 1,
|
||||
page_size: 20,
|
||||
})
|
||||
|
||||
const dialogVisible = ref(false)
|
||||
const editing = ref<ReferenceListItem | null>(null)
|
||||
|
||||
const citationsVisible = ref(false)
|
||||
const citationsTarget = ref<ReferenceListItem | null>(null)
|
||||
|
||||
const CITED_FILTERS = [
|
||||
{ value: null, label: '全部文献' },
|
||||
{ value: true, label: '已被引用' },
|
||||
{ value: false, label: '还没引用' },
|
||||
]
|
||||
|
||||
const tags = computed(() => tagsStore.items)
|
||||
|
||||
/**
|
||||
* The tag filter lives in the URL, not in this component.
|
||||
*
|
||||
* The rail links to a filtered library and the toolbar changes the same filter,
|
||||
* so one of them has to own it — and the URL is the one both can read. That is
|
||||
* also why the rail can highlight the label you are looking at.
|
||||
*/
|
||||
const tagFilter = computed<number | null>({
|
||||
get: () => {
|
||||
const raw = route.query.tag
|
||||
const value = Array.isArray(raw) ? raw[0] : raw
|
||||
const parsed = value ? Number(value) : null
|
||||
return parsed != null && Number.isFinite(parsed) ? parsed : null
|
||||
},
|
||||
set: (value) => {
|
||||
void router.replace({
|
||||
path: '/references',
|
||||
query: value == null ? {} : { tag: String(value) },
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
async function load(): Promise<void> {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await listReferences({
|
||||
keyword: query.keyword,
|
||||
type: query.type,
|
||||
year: query.year ?? null,
|
||||
cited: query.cited,
|
||||
tag_ids: tagFilter.value == null ? [] : [tagFilter.value],
|
||||
page: query.page,
|
||||
page_size: query.page_size,
|
||||
})
|
||||
rows.value = result.items
|
||||
total.value = result.total
|
||||
|
||||
// A delete can empty the last page. Stepping back keeps the table from
|
||||
// showing "no data" while the pager still claims a page beyond 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.type = null
|
||||
query.year = undefined
|
||||
query.cited = null
|
||||
query.page = 1
|
||||
tagFilter.value = null
|
||||
void load()
|
||||
}
|
||||
|
||||
function onCreate(): void {
|
||||
editing.value = null
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
function onEdit(row: ReferenceListItem): void {
|
||||
editing.value = row
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
function onShowCitations(row: ReferenceListItem): void {
|
||||
citationsTarget.value = row
|
||||
citationsVisible.value = true
|
||||
}
|
||||
|
||||
/** Refresh the table and the rail's tag counts, which this page can change. */
|
||||
async function refreshAll(): Promise<void> {
|
||||
await Promise.all([load(), tagsStore.reload()])
|
||||
}
|
||||
|
||||
async function onDelete(row: ReferenceListItem): Promise<void> {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定从文献库删除「${row.title}」?`, '删除文献', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '删除',
|
||||
cancelButtonText: '取消',
|
||||
})
|
||||
} catch {
|
||||
return // dismissed
|
||||
}
|
||||
|
||||
try {
|
||||
await deleteReference(row.id)
|
||||
ElMessage.success('已删除')
|
||||
await refreshAll()
|
||||
} catch (error) {
|
||||
// A cited entry is refused with the count, which is worth showing whole.
|
||||
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 batchDeleteReferences(ids)
|
||||
ElMessage.success(`已删除 ${result.deleted} 篇文献`)
|
||||
selection.value = []
|
||||
await refreshAll()
|
||||
} catch (error) {
|
||||
ElMessage.error(errorMessage(error))
|
||||
}
|
||||
}
|
||||
|
||||
/** The heading a row prints: the type's Chinese name, with its GB/T marker. */
|
||||
function typeLabel(row: ReferenceListItem): string {
|
||||
const marker = referenceTypeMarker(row.type)
|
||||
const label = referenceTypeLabel(row.type)
|
||||
return marker ? `${label} [${marker}]` : label
|
||||
}
|
||||
|
||||
/** Where it was published, as one column: the container, else the publisher. */
|
||||
function sourceLine(row: ReferenceListItem): string {
|
||||
const parts = [row.container_title ?? row.publisher ?? ''].filter(Boolean)
|
||||
if (row.volume) parts.push(`第 ${row.volume} 卷`)
|
||||
if (row.issue) parts.push(`第 ${row.issue} 期`)
|
||||
if (row.pages) parts.push(row.pages)
|
||||
return parts.join(' · ')
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the add dialog when the rail'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: '/references', query: route.query.tag ? { tag: route.query.tag } : {} })
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
// The tag filter is read from the URL, so a change to it is a change of view.
|
||||
watch(
|
||||
() => route.query.tag,
|
||||
() => {
|
||||
query.page = 1
|
||||
void load()
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
onMounted(() => {
|
||||
void tagsStore.ensureLoaded()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page page--fill">
|
||||
<el-card shadow="never" class="card--fill">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<div>
|
||||
<span class="card-title">参考文献库</span>
|
||||
<span class="card-subtitle">
|
||||
文献是全局的,可以被任意多篇论文引用;标签用来给自己归档
|
||||
</span>
|
||||
</div>
|
||||
<el-tag type="info" effect="plain">共 {{ total }} 篇</el-tag>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="toolbar">
|
||||
<el-input
|
||||
v-model="query.keyword"
|
||||
placeholder="搜索题名、刊名、作者、DOI、关键词"
|
||||
clearable
|
||||
class="search"
|
||||
@keyup.enter="search"
|
||||
@clear="search"
|
||||
>
|
||||
<template #prefix><el-icon><Search /></el-icon></template>
|
||||
</el-input>
|
||||
|
||||
<el-select
|
||||
v-model="query.type"
|
||||
placeholder="全部类型"
|
||||
clearable
|
||||
class="type-filter"
|
||||
@change="search"
|
||||
>
|
||||
<el-option
|
||||
v-for="option in REFERENCE_TYPE_OPTIONS"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
:label="`${option.label} [${option.marker}]`"
|
||||
/>
|
||||
</el-select>
|
||||
|
||||
<el-select
|
||||
v-model="tagFilter"
|
||||
placeholder="全部标签"
|
||||
clearable
|
||||
class="tag-filter"
|
||||
@change="search"
|
||||
>
|
||||
<el-option v-for="tag in tags" :key="tag.id" :value="tag.id" :label="tag.name">
|
||||
<span class="tag-option">
|
||||
<span class="tag-dot" :style="{ backgroundColor: tag.color }" />
|
||||
<span>{{ tag.name }}</span>
|
||||
<span class="tag-option-count">{{ tag.reference_count }}</span>
|
||||
</span>
|
||||
</el-option>
|
||||
</el-select>
|
||||
|
||||
<el-select
|
||||
v-model="query.cited"
|
||||
placeholder="引用情况"
|
||||
clearable
|
||||
class="cited-filter"
|
||||
@change="search"
|
||||
>
|
||||
<el-option
|
||||
v-for="option in CITED_FILTERS"
|
||||
:key="String(option.value)"
|
||||
:value="option.value"
|
||||
:label="option.label"
|
||||
/>
|
||||
</el-select>
|
||||
|
||||
<el-input-number
|
||||
v-model="query.year"
|
||||
:min="1"
|
||||
:max="2999"
|
||||
:controls="false"
|
||||
placeholder="年份"
|
||||
class="year-filter"
|
||||
@change="search"
|
||||
/>
|
||||
|
||||
<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-button type="primary" :icon="Plus" @click="onCreate">新增文献</el-button>
|
||||
</div>
|
||||
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="rows"
|
||||
row-key="id"
|
||||
stripe
|
||||
class="table table-fill"
|
||||
height="100%"
|
||||
@selection-change="(value: ReferenceListItem[]) => (selection = value)"
|
||||
>
|
||||
<el-table-column type="selection" width="46" reserve-selection />
|
||||
|
||||
<el-table-column label="题名" min-width="260">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" class="title-link" @click="onEdit(row)">
|
||||
{{ row.title }}
|
||||
</el-button>
|
||||
<div v-if="row.subtitle" class="subtitle">{{ row.subtitle }}</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="类型" width="120">
|
||||
<template #default="{ row }">
|
||||
<el-tag size="small" effect="plain">{{ typeLabel(row) }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="责任者" min-width="150" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
<span v-if="row.authors_line">{{ row.authors_line }}</span>
|
||||
<span v-else class="muted">—</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="出版信息" min-width="180" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
<span v-if="sourceLine(row)">{{ sourceLine(row) }}</span>
|
||||
<span v-else class="muted">—</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="年份" width="80" align="center">
|
||||
<template #default="{ row }">
|
||||
<span v-if="row.publication_year">{{ row.publication_year }}</span>
|
||||
<span v-else class="muted">—</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="标签" min-width="180">
|
||||
<template #default="{ row }">
|
||||
<template v-if="row.tags.length">
|
||||
<TagChip
|
||||
v-for="tag in row.tags.slice(0, 3)"
|
||||
:key="tag.id"
|
||||
:name="tag.name"
|
||||
:color="tag.color"
|
||||
class="row-tag"
|
||||
@click="tagFilter = tag.id"
|
||||
/>
|
||||
<span v-if="row.tags.length > 3" class="muted">
|
||||
+{{ row.tags.length - 3 }}
|
||||
</span>
|
||||
</template>
|
||||
<span v-else class="muted">—</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="引用" width="90" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-button
|
||||
v-if="row.citation_count"
|
||||
link
|
||||
type="primary"
|
||||
@click="onShowCitations(row)"
|
||||
>
|
||||
{{ row.citation_count }} 处
|
||||
</el-button>
|
||||
<span v-else class="muted">—</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="更新时间" width="150">
|
||||
<template #default="{ row }">{{ formatDateTime(row.updated_at) }}</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="操作" width="210" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" :icon="Edit" @click="onEdit(row)">编辑</el-button>
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
:icon="ChatLineSquare"
|
||||
@click="onShowCitations(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.type || tagFilter != null
|
||||
? '没有匹配的文献'
|
||||
: '文献库还是空的,先加一篇'
|
||||
"
|
||||
>
|
||||
<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>
|
||||
|
||||
<ReferenceFormDialog
|
||||
v-model="dialogVisible"
|
||||
:reference="editing"
|
||||
@saved="refreshAll"
|
||||
/>
|
||||
|
||||
<ReferenceCitationsDialog v-model="citationsVisible" :reference="citationsTarget" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.card-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.card-title {
|
||||
font-weight: 600;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.card-subtitle {
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.search {
|
||||
width: 240px;
|
||||
}
|
||||
|
||||
.type-filter {
|
||||
width: 150px;
|
||||
}
|
||||
|
||||
.tag-filter {
|
||||
width: 150px;
|
||||
}
|
||||
|
||||
.cited-filter {
|
||||
width: 130px;
|
||||
}
|
||||
|
||||
.year-filter {
|
||||
width: 100px;
|
||||
}
|
||||
|
||||
.table {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.title-link {
|
||||
font-weight: 600;
|
||||
padding: 0;
|
||||
height: auto;
|
||||
text-align: left;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.row-tag {
|
||||
margin: 0 4px 4px 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.muted {
|
||||
color: var(--el-text-color-placeholder);
|
||||
}
|
||||
|
||||
.tag-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.tag-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.tag-option-count {
|
||||
margin-left: auto;
|
||||
padding-left: 12px;
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-placeholder);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,303 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 标签管理 — the label library the reference module draws on.
|
||||
*
|
||||
* This page is the first half of the tagging flow: labels are **made here and
|
||||
* applied in the reference form**, so a reference is never stored pointing at a
|
||||
* label that does not exist. The library is global, so a label means the same
|
||||
* thing in every paper.
|
||||
*
|
||||
* Deleting is not guarded the way deleting a library field is. A tag is the
|
||||
* writer's own filing rather than something the document claims, so removing it
|
||||
* removes labels and leaves the literature where it was — the confirmation says
|
||||
* how many entries will lose the label, which is the honest form of that
|
||||
* warning.
|
||||
*/
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { Delete, Edit, Plus, Refresh, Search } from '@element-plus/icons-vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
|
||||
import { errorMessage } from '@/api/client'
|
||||
import {
|
||||
batchDeleteReferenceTags,
|
||||
deleteReferenceTag,
|
||||
listReferenceTags,
|
||||
type ReferenceTag,
|
||||
} from '@/api/referenceTags'
|
||||
import TagChip from '@/components/references/TagChip.vue'
|
||||
import TagFormDialog from '@/components/references/TagFormDialog.vue'
|
||||
import { useReferenceTagsStore } from '@/stores/referenceTags'
|
||||
import { formatDateTime } from '@/utils/format'
|
||||
|
||||
const tagsStore = useReferenceTagsStore()
|
||||
|
||||
const loading = ref(false)
|
||||
const rows = ref<ReferenceTag[]>([])
|
||||
const total = ref(0)
|
||||
const selection = ref<ReferenceTag[]>([])
|
||||
|
||||
const query = reactive({
|
||||
keyword: '',
|
||||
page: 1,
|
||||
page_size: 20,
|
||||
})
|
||||
|
||||
const dialogVisible = ref(false)
|
||||
const editing = ref<ReferenceTag | null>(null)
|
||||
|
||||
async function load(): Promise<void> {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await listReferenceTags(query)
|
||||
rows.value = result.items
|
||||
total.value = result.total
|
||||
|
||||
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 onCreate(): void {
|
||||
editing.value = null
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
function onEdit(row: ReferenceTag): void {
|
||||
editing.value = row
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh this table and the shared library together.
|
||||
*
|
||||
* The rail lists the same labels and the reference form picks from them, so a
|
||||
* page that renames or deletes one has to reload the store as well or the two
|
||||
* would disagree until the next navigation.
|
||||
*/
|
||||
async function refreshAll(): Promise<void> {
|
||||
await Promise.all([load(), tagsStore.reload()])
|
||||
}
|
||||
|
||||
async function onDelete(row: ReferenceTag): Promise<void> {
|
||||
const warning = row.reference_count
|
||||
? `「${row.name}」正被 ${row.reference_count} 篇文献使用,删除后这些文献会失去这个标签(文献本身不会删)。`
|
||||
: `确定删除标签「${row.name}」?`
|
||||
|
||||
try {
|
||||
await ElMessageBox.confirm(warning, '删除标签', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '删除',
|
||||
cancelButtonText: '取消',
|
||||
})
|
||||
} catch {
|
||||
return // dismissed
|
||||
}
|
||||
|
||||
try {
|
||||
await deleteReferenceTag(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
|
||||
|
||||
const labels = selection.value
|
||||
.reduce((sum, row) => sum + row.reference_count, 0)
|
||||
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确定删除选中的 ${ids.length} 个标签?相关文献会失去这些标签(文献本身不会删)。` +
|
||||
(labels ? `涉及 ${labels} 处标注。` : ''),
|
||||
'批量删除',
|
||||
{ type: 'warning', confirmButtonText: '删除', cancelButtonText: '取消' },
|
||||
)
|
||||
} catch {
|
||||
return // dismissed
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await batchDeleteReferenceTags(ids)
|
||||
ElMessage.success(`已删除 ${result.deleted} 个标签`)
|
||||
selection.value = []
|
||||
await refreshAll()
|
||||
} catch (error) {
|
||||
ElMessage.error(errorMessage(error))
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await load()
|
||||
void tagsStore.reload()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page page--fill">
|
||||
<el-card shadow="never" class="card--fill">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<div>
|
||||
<span class="card-title">标签库</span>
|
||||
<span class="card-subtitle">
|
||||
先在这里建好标签,再在文献里勾选;标签是给自己归档用的,不会出现在参考文献表里
|
||||
</span>
|
||||
</div>
|
||||
<el-tag type="info" effect="plain">共 {{ total }} 个</el-tag>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<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-button @click="search">查询</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-button type="primary" :icon="Plus" @click="onCreate">新建标签</el-button>
|
||||
</div>
|
||||
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="rows"
|
||||
row-key="id"
|
||||
stripe
|
||||
class="table table-fill"
|
||||
height="100%"
|
||||
@selection-change="(value: ReferenceTag[]) => (selection = value)"
|
||||
>
|
||||
<el-table-column type="selection" width="46" reserve-selection />
|
||||
|
||||
<el-table-column label="标签" min-width="200">
|
||||
<template #default="{ row }">
|
||||
<TagChip :name="row.name" :color="row.color" size="default" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="备注" min-width="240" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
<span v-if="row.note">{{ row.note }}</span>
|
||||
<span v-else class="muted">—</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="文献数" width="110" align="center">
|
||||
<template #default="{ row }">
|
||||
<RouterLink
|
||||
v-if="row.reference_count"
|
||||
:to="{ path: '/references', query: { tag: String(row.id) } }"
|
||||
class="count-link"
|
||||
>
|
||||
{{ row.reference_count }} 篇
|
||||
</RouterLink>
|
||||
<span v-else class="muted">未使用</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="更新时间" width="170">
|
||||
<template #default="{ row }">{{ formatDateTime(row.updated_at) }}</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="操作" width="150" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<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 ? '没有匹配的标签' : '还没有标签,先建一个再给文献打标'"
|
||||
>
|
||||
<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>
|
||||
|
||||
<TagFormDialog v-model="dialogVisible" :tag="editing" @saved="refreshAll" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.card-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.card-title {
|
||||
font-weight: 600;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.card-subtitle {
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.search {
|
||||
width: 240px;
|
||||
}
|
||||
|
||||
.table {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.count-link {
|
||||
color: var(--el-color-primary);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.muted {
|
||||
color: var(--el-text-color-placeholder);
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user