feat: 新增后台管理入口与资源新增功能

- 首页齿轮按钮以新标签页打开后台管理,新增 Admin 路由与视图
- 资源列表支持新增版本资源,复用编辑抽屉
- 主页检索按字段映射到检索页途径(题名/关键词/责任者/出版社/综合)
- 检索支持多词分词 OR 匹配,并过滤已屏蔽/下架记录
- 聚同算法改为 ISBN 优先、无 ISBN 时四要素判定,并前后端统一抽取分组逻辑
- 数据库主键改为自增序列,新增敏感词库与院校资源节点表,补充特藏与管理状态字段及样例数据序列同步
This commit is contained in:
SUNJIAJINGS
2026-10-21 16:25:28 +08:00
parent e9c83e0be0
commit 46be7346a2
40 changed files with 2014 additions and 102 deletions
+150 -16
View File
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { onMounted, reactive, ref } from 'vue'
import { computed, onMounted, reactive, ref } from 'vue'
import { useRoute } from 'vue-router'
import { getSearchDetail, getSimilar, unifiedSearch, type FacetItem, type SearchQuery } from '@/api/search'
import type { VersionResource } from '@/api/resource'
@@ -15,17 +15,92 @@ const libraryFacets = ref<FacetItem[]>([])
const query = reactive<SearchQuery>({
current: 1,
size: 20,
keyword: '',
size: 50,
mediaType: ''
})
const field = ref('题名')
const fields = ['题名', '责任者', '关键词', '出版社', 'ISBN']
/** 概览页每页条数选项(默认 50,可切 100/200;20 便于数据量小时演示翻页) */
const pageSizes = [20, 50, 100, 200]
/** 输入框内容(与查询参数分离,避免按途径分发后被清空) */
const input = ref('')
const field = ref('综合')
const fields = ['综合', '题名', '责任者', '关键词', '出版社', 'ISBN']
/** 检索途径 → 查询参数字段 */
const fieldParamMap: Record<string, 'keyword' | 'title' | 'author' | 'publisher' | 'isbn'> = {
综合: 'keyword',
题名: 'title',
责任者: 'author',
关键词: 'keyword',
出版社: 'publisher',
ISBN: 'isbn'
}
// ==================== 命中位置标注与高亮 ====================
/** 各检索途径对应的检查字段(综合途经覆盖全部文本字段) */
const hitFieldMap: Record<string, string[]> = {
综合: ['title', 'author', 'keywords', 'summary', 'publisher'],
题名: ['title'],
责任者: ['author'],
关键词: ['keywords'],
出版社: ['publisher'],
ISBN: ['isbn']
}
const fieldLabels: Record<string, string> = {
title: '正题名',
author: '责任者',
keywords: '关键词',
summary: '摘要',
publisher: '出版者',
isbn: 'ISBN'
}
/** 当前检索词(空格分词) */
const terms = computed(() => input.value.trim().split(/\s+/).filter(Boolean))
function escapeHtml(s: string) {
return s.replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' })[c] as string)
}
/** 文本高亮:命中的关键词包一层 span(先转义再包裹,避免注入) */
function highlight(text?: string): string {
if (!text || !terms.value.length) return escapeHtml(text || '')
let out = escapeHtml(text)
for (const t of terms.value) {
const esc = escapeHtml(t)
if (esc) out = out.split(esc).join(`<span class="hl">${esc}</span>`)
}
return out
}
/** 命中字段的上下文摘录(标题外命中时展示,如「出版者:…军事科学出版社…」) */
function snippets(row: VersionResource): { label: string; html: string }[] {
const keys = (hitFieldMap[field.value] || []).filter((k) => k !== 'title')
const out: { label: string; html: string }[] = []
for (const k of keys) {
const v = (row as unknown as Record<string, string | undefined>)[k]
if (!v) continue
const hit = terms.value.find((t) => v.includes(t))
if (!hit) continue
const idx = v.indexOf(hit)
const start = Math.max(0, idx - 12)
const end = Math.min(v.length, idx + hit.length + 28)
const text = (start > 0 ? '…' : '') + v.slice(start, end) + (end < v.length ? '…' : '')
out.push({ label: fieldLabels[k], html: highlight(text) })
}
return out
}
async function doSearch() {
loading.value = true
searched.value = true
// 按所选途径分发检索词;多词用空格分隔,词与词之间为 AND
const kw = input.value.trim()
query.title = query.author = query.publisher = query.isbn = query.keyword = ''
;(query as unknown as Record<string, string>)[fieldParamMap[field.value]] = kw
try {
const res = await unifiedSearch({ ...query })
rows.value = res.page?.records || []
@@ -47,6 +122,20 @@ function pick(type: 'mediaType' | 'sourceLibrary', v: string) {
function goPage(p: number) {
query.current = p
doSearch()
scrollToListTop()
}
/** 切换每页条数:回到第一页重新检索 */
function goSize(s: number) {
query.size = s
query.current = 1
doSearch()
scrollToListTop()
}
/** 翻页后回到结果列表顶部,避免停在长列表中间 */
function scrollToListTop() {
window.scrollTo({ top: 0, behavior: 'smooth' })
}
const drawer = ref(false)
@@ -64,8 +153,13 @@ async function openDetail(row: VersionResource) {
onMounted(() => {
const kw = route.query.keyword as string
const f = route.query.field as string
// 主页带来的检索途径(题名/责任者/…),合法则沿用
if (f && fields.includes(f)) {
field.value = f
}
if (kw) {
query.keyword = kw
input.value = kw
doSearch()
}
})
@@ -74,9 +168,9 @@ onMounted(() => {
<template>
<div class="search-page">
<div class="bar">
<el-input v-model="query.keyword" size="large" placeholder="请输入检索词" clearable @keyup.enter="doSearch">
<el-input v-model="input" size="large" placeholder="请输入检索词,支持多词检索(空格分隔,命中任一词即返回)" clearable @keyup.enter="doSearch">
<template #prepend>
<el-select v-model="field" style="width: 96px">
<el-select v-model="field" style="width: 96px" @change="searched && doSearch()">
<el-option v-for="f in fields" :key="f" :label="f" :value="f" />
</el-select>
</template>
@@ -104,14 +198,27 @@ onMounted(() => {
<div v-for="r in rows" :key="r.id" class="card" @click="openDetail(r)">
<div class="cover">{{ (r.title || '').slice(0, 2) }}</div>
<div class="info">
<div class="t">{{ r.title }}</div>
<div class="d">{{ r.author || '-' }} · {{ r.publishYear || '-' }} · {{ r.mediaType || '-' }}</div>
<div class="d">{{ r.sourceLibrary || '-' }}</div>
<div class="t" v-html="highlight(r.title)"></div>
<div class="d">
<span v-html="highlight(r.author || '-')"></span> · {{ r.publishYear || '-' }} · {{ r.mediaType || '-' }}
</div>
<div class="d" v-html="highlight(r.sourceLibrary || '-')"></div>
<div v-for="s in snippets(r)" :key="s.label" class="snippet">
<span class="snippet-label">{{ s.label }}:</span>
<span v-html="s.html"></span>
</div>
</div>
</div>
</div>
<el-pagination class="pager" background layout="prev, pager, next" :total="total"
:current-page="query.current" :page-size="query.size" @current-change="goPage" />
<el-pagination class="pager" background
layout="total, sizes, prev, pager, next, jumper"
:total="total"
:current-page="query.current"
:page-size="query.size"
:page-sizes="pageSizes"
:pager-count="7"
@current-change="goPage"
@size-change="goSize" />
</section>
</div>
@@ -205,8 +312,8 @@ onMounted(() => {
.meta { font-size: 13px; color: #6b7280; margin-bottom: 10px; }
.cards {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
display: flex;
flex-direction: column;
gap: 14px;
}
@@ -243,7 +350,34 @@ onMounted(() => {
.d { font-size: 12px; color: #8b93a1; }
}
.pager { margin-top: 18px; justify-content: center; }
/* 命中关键词高亮(v-html 动态插入的节点不带 scoped 属性,需用 :deep 穿透) */
:deep(.hl) {
background: #ffe6a3;
color: #8a4b00;
border-radius: 2px;
padding: 0 1px;
}
.snippet {
margin-top: 4px;
font-size: 12px;
color: #7b8493;
line-height: 1.5;
word-break: break-all;
}
.snippet-label {
color: #4b5563;
}
.pager {
margin-top: 18px;
justify-content: center;
flex-wrap: wrap;
/* 页码较多时自动换行,保证页码按钮与跳转框都能点到 */
:deep(.el-pagination__jump) { margin-left: 12px; }
}
.dt { margin: 0 0 12px; font-size: 17px; }
.sim-item { font-size: 13px; padding: 6px 0; border-bottom: 1px dashed #eee; cursor: pointer; }
</style>