feat: 新增后台管理入口与资源新增功能
- 首页齿轮按钮以新标签页打开后台管理,新增 Admin 路由与视图 - 资源列表支持新增版本资源,复用编辑抽屉 - 主页检索按字段映射到检索页途径(题名/关键词/责任者/出版社/综合) - 检索支持多词分词 OR 匹配,并过滤已屏蔽/下架记录 - 聚同算法改为 ISBN 优先、无 ISBN 时四要素判定,并前后端统一抽取分组逻辑 - 数据库主键改为自增序列,新增敏感词库与院校资源节点表,补充特藏与管理状态字段及样例数据序列同步
This commit is contained in:
@@ -98,8 +98,19 @@ function resume() {
|
||||
reset()
|
||||
}
|
||||
|
||||
/** 主页途径 → 检索页途径命名映射 */
|
||||
const fieldToSearchField: Record<string, string> = {
|
||||
题名: '题名',
|
||||
关键词: '关键词',
|
||||
作者: '责任者',
|
||||
出版机构: '出版社'
|
||||
}
|
||||
|
||||
function doSearch() {
|
||||
router.push({ path: '/search', query: { keyword: keyword.value } })
|
||||
router.push({
|
||||
path: '/search',
|
||||
query: { keyword: keyword.value, field: fieldToSearchField[field.value] || '综合' }
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
@@ -0,0 +1,613 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
|
||||
const activeTab = ref('words')
|
||||
import {
|
||||
batchRemoveResourceNodes,
|
||||
batchRemoveSensitiveWords,
|
||||
createResourceNode,
|
||||
createSensitiveWord,
|
||||
handleHitAction,
|
||||
listResourceNodes,
|
||||
pageHits,
|
||||
pageSensitiveWords,
|
||||
removeResourceNode,
|
||||
removeSensitiveWord,
|
||||
resourceStats,
|
||||
updateResourceNode,
|
||||
updateSensitiveWord,
|
||||
type HitAction,
|
||||
type ResourceNode,
|
||||
type SensitiveHit,
|
||||
type SensitiveWord,
|
||||
} from '@/api/admin'
|
||||
|
||||
// ==================== 敏感词库 ====================
|
||||
const wordQuery = reactive({ current: 1, size: 10, keyword: '' })
|
||||
const wordList = ref<SensitiveWord[]>([])
|
||||
const wordTotal = ref(0)
|
||||
const wordLoading = ref(false)
|
||||
const wordSelection = ref<SensitiveWord[]>([])
|
||||
const wordDialog = ref(false)
|
||||
const wordSaving = ref(false)
|
||||
const wordForm = reactive<{ id?: number; word: string; pinyin: string }>({ word: '', pinyin: '' })
|
||||
|
||||
async function fetchWords() {
|
||||
wordLoading.value = true
|
||||
try {
|
||||
const page = await pageSensitiveWords({
|
||||
current: wordQuery.current,
|
||||
size: wordQuery.size,
|
||||
keyword: wordQuery.keyword || undefined,
|
||||
})
|
||||
wordList.value = page.records
|
||||
wordTotal.value = page.total
|
||||
} finally {
|
||||
wordLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function searchWords() {
|
||||
wordQuery.current = 1
|
||||
fetchWords()
|
||||
}
|
||||
|
||||
function openWordCreate() {
|
||||
wordForm.id = undefined
|
||||
wordForm.word = ''
|
||||
wordForm.pinyin = ''
|
||||
wordDialog.value = true
|
||||
}
|
||||
|
||||
function openWordEdit(row: SensitiveWord) {
|
||||
wordForm.id = row.id
|
||||
wordForm.word = row.word
|
||||
wordForm.pinyin = row.pinyin || ''
|
||||
wordDialog.value = true
|
||||
}
|
||||
|
||||
async function saveWord() {
|
||||
if (!wordForm.word.trim()) {
|
||||
ElMessage.warning('请输入敏感词')
|
||||
return
|
||||
}
|
||||
wordSaving.value = true
|
||||
try {
|
||||
const data = { word: wordForm.word.trim(), pinyin: wordForm.pinyin.trim() || undefined }
|
||||
if (wordForm.id) {
|
||||
await updateSensitiveWord(wordForm.id, data)
|
||||
} else {
|
||||
await createSensitiveWord(data)
|
||||
}
|
||||
ElMessage.success('保存成功')
|
||||
wordDialog.value = false
|
||||
fetchWords()
|
||||
} finally {
|
||||
wordSaving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteWord(row: SensitiveWord) {
|
||||
await ElMessageBox.confirm(`确认删除敏感词「${row.word}」?`, '提示', { type: 'warning' })
|
||||
await removeSensitiveWord(row.id!)
|
||||
ElMessage.success('删除成功')
|
||||
fetchWords()
|
||||
}
|
||||
|
||||
async function batchDeleteWords() {
|
||||
const ids = wordSelection.value.map((r) => r.id!)
|
||||
if (!ids.length) {
|
||||
ElMessage.warning('请先勾选要删除的敏感词')
|
||||
return
|
||||
}
|
||||
await ElMessageBox.confirm(`确认批量删除选中的 ${ids.length} 个敏感词?`, '提示', { type: 'warning' })
|
||||
await batchRemoveSensitiveWords(ids)
|
||||
ElMessage.success('批量删除成功')
|
||||
fetchWords()
|
||||
}
|
||||
|
||||
// ==================== 敏感词命中处置 ====================
|
||||
const hitQuery = reactive({ current: 1, size: 10 })
|
||||
const hitList = ref<SensitiveHit[]>([])
|
||||
const hitTotal = ref(0)
|
||||
const hitLoading = ref(false)
|
||||
const hitSelection = ref<SensitiveHit[]>([])
|
||||
|
||||
const manageStatusText: Record<number, string> = { 0: '正常', 1: '已屏蔽', 2: '已下架' }
|
||||
const manageStatusTag: Record<number, 'success' | 'warning' | 'danger'> = {
|
||||
0: 'success',
|
||||
1: 'danger',
|
||||
2: 'warning',
|
||||
}
|
||||
|
||||
async function fetchHits() {
|
||||
hitLoading.value = true
|
||||
try {
|
||||
const page = await pageHits({ current: hitQuery.current, size: hitQuery.size })
|
||||
hitList.value = page.records
|
||||
hitTotal.value = page.total
|
||||
} finally {
|
||||
hitLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function doHitAction(ids: number[], action: HitAction, label: string) {
|
||||
const count = await handleHitAction(ids, action)
|
||||
ElMessage.success(`${label}成功,共 ${count} 条`)
|
||||
fetchHits()
|
||||
}
|
||||
|
||||
async function handleHit(row: SensitiveHit, action: HitAction, label: string) {
|
||||
if (action === 'DELETE') {
|
||||
await ElMessageBox.confirm(`确认删除「${row.title}」?删除后不可恢复。`, '提示', { type: 'warning' })
|
||||
}
|
||||
await doHitAction([row.id], action, label)
|
||||
}
|
||||
|
||||
async function batchHit(action: HitAction, label: string) {
|
||||
const ids = hitSelection.value.map((r) => r.id)
|
||||
if (!ids.length) {
|
||||
ElMessage.warning('请先勾选要处置的记录')
|
||||
return
|
||||
}
|
||||
if (action === 'DELETE') {
|
||||
await ElMessageBox.confirm(`确认批量删除选中的 ${ids.length} 条记录?删除后不可恢复。`, '提示', {
|
||||
type: 'warning',
|
||||
})
|
||||
}
|
||||
await doHitAction(ids, action, `批量${label}`)
|
||||
}
|
||||
|
||||
// ==================== 院校资源库 ====================
|
||||
const nodeLoading = ref(false)
|
||||
const nodeList = ref<ResourceNode[]>([])
|
||||
const nodeSelection = ref<ResourceNode[]>([])
|
||||
const nodeDialog = ref(false)
|
||||
const nodeSaving = ref(false)
|
||||
const nodeForm = reactive<{
|
||||
id?: number
|
||||
name: string
|
||||
nodeType: string
|
||||
category: string
|
||||
linkUrl: string
|
||||
sortNo: number
|
||||
status: number
|
||||
}>({ name: '', nodeType: '', category: '', linkUrl: '', sortNo: 0, status: 1 })
|
||||
|
||||
const statDim = ref<'sourceLibrary' | 'mediaType' | 'title'>('sourceLibrary')
|
||||
const statLoading = ref(false)
|
||||
const statList = ref<{ name: string; count: number }[]>([])
|
||||
const statDims = [
|
||||
{ value: 'sourceLibrary', label: '按来源院校' },
|
||||
{ value: 'mediaType', label: '按资源类型' },
|
||||
{ value: 'title', label: '按资源名称' },
|
||||
] as const
|
||||
|
||||
async function fetchNodes() {
|
||||
nodeLoading.value = true
|
||||
try {
|
||||
nodeList.value = await listResourceNodes()
|
||||
} finally {
|
||||
nodeLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchStats() {
|
||||
statLoading.value = true
|
||||
try {
|
||||
statList.value = await resourceStats(statDim.value, 50)
|
||||
} finally {
|
||||
statLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function openNodeCreate() {
|
||||
Object.assign(nodeForm, { id: undefined, name: '', nodeType: '', category: '', linkUrl: '', sortNo: 0, status: 1 })
|
||||
nodeDialog.value = true
|
||||
}
|
||||
|
||||
function openNodeEdit(row: ResourceNode) {
|
||||
Object.assign(nodeForm, {
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
nodeType: row.nodeType || '',
|
||||
category: row.category || '',
|
||||
linkUrl: row.linkUrl || '',
|
||||
sortNo: row.sortNo ?? 0,
|
||||
status: row.status ?? 1,
|
||||
})
|
||||
nodeDialog.value = true
|
||||
}
|
||||
|
||||
async function saveNode() {
|
||||
if (!nodeForm.name.trim()) {
|
||||
ElMessage.warning('请输入资源节点名称')
|
||||
return
|
||||
}
|
||||
nodeSaving.value = true
|
||||
try {
|
||||
const data: ResourceNode = {
|
||||
name: nodeForm.name.trim(),
|
||||
nodeType: nodeForm.nodeType.trim() || undefined,
|
||||
category: nodeForm.category.trim() || undefined,
|
||||
linkUrl: nodeForm.linkUrl.trim() || undefined,
|
||||
sortNo: nodeForm.sortNo,
|
||||
status: nodeForm.status,
|
||||
}
|
||||
if (nodeForm.id) {
|
||||
await updateResourceNode(nodeForm.id, data)
|
||||
} else {
|
||||
await createResourceNode(data)
|
||||
}
|
||||
ElMessage.success('保存成功')
|
||||
nodeDialog.value = false
|
||||
fetchNodes()
|
||||
} finally {
|
||||
nodeSaving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteNode(row: ResourceNode) {
|
||||
await ElMessageBox.confirm(`确认删除资源节点「${row.name}」?`, '提示', { type: 'warning' })
|
||||
await removeResourceNode(row.id!)
|
||||
ElMessage.success('删除成功')
|
||||
fetchNodes()
|
||||
}
|
||||
|
||||
async function batchDeleteNodes() {
|
||||
const ids = nodeSelection.value.map((r) => r.id!)
|
||||
if (!ids.length) {
|
||||
ElMessage.warning('请先勾选要删除的资源节点')
|
||||
return
|
||||
}
|
||||
await ElMessageBox.confirm(`确认批量删除选中的 ${ids.length} 个资源节点?`, '提示', { type: 'warning' })
|
||||
await batchRemoveResourceNodes(ids)
|
||||
ElMessage.success('批量删除成功')
|
||||
fetchNodes()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchWords()
|
||||
fetchHits()
|
||||
fetchNodes()
|
||||
fetchStats()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="admin-page">
|
||||
<h2 class="page-title">后台管理</h2>
|
||||
|
||||
<el-tabs v-model="activeTab" class="admin-tabs">
|
||||
<!-- ==================== 敏感词库 ==================== -->
|
||||
<el-tab-pane label="敏感词库" name="words">
|
||||
<div class="toolbar">
|
||||
<el-input
|
||||
v-model="wordQuery.keyword"
|
||||
placeholder="按敏感词 / 拼音搜索"
|
||||
clearable
|
||||
style="width: 240px"
|
||||
@keyup.enter="searchWords"
|
||||
@clear="searchWords"
|
||||
/>
|
||||
<el-button type="primary" @click="searchWords">查询</el-button>
|
||||
<el-button type="success" @click="openWordCreate">新增敏感词</el-button>
|
||||
<el-button type="danger" plain :disabled="!wordSelection.length" @click="batchDeleteWords">
|
||||
批量删除
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<el-table
|
||||
v-loading="wordLoading"
|
||||
:data="wordList"
|
||||
border
|
||||
stripe
|
||||
@selection-change="(rows: SensitiveWord[]) => (wordSelection = rows)"
|
||||
>
|
||||
<el-table-column type="selection" width="45" />
|
||||
<el-table-column prop="word" label="敏感词(中文)" min-width="180" />
|
||||
<el-table-column prop="pinyin" label="拼音" min-width="160" />
|
||||
<el-table-column prop="createTime" label="创建时间" width="180" />
|
||||
<el-table-column label="操作" width="140" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" size="small" @click="openWordEdit(row)">编辑</el-button>
|
||||
<el-button link type="danger" size="small" @click="deleteWord(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<el-pagination
|
||||
class="pager"
|
||||
background
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
:total="wordTotal"
|
||||
v-model:current-page="wordQuery.current"
|
||||
v-model:page-size="wordQuery.size"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
@current-change="fetchWords"
|
||||
@size-change="fetchWords"
|
||||
/>
|
||||
</el-tab-pane>
|
||||
|
||||
<!-- ==================== 敏感词命中处置 ==================== -->
|
||||
<el-tab-pane label="敏感词命中处置" name="hits">
|
||||
<el-alert
|
||||
class="hint"
|
||||
type="info"
|
||||
:closable="false"
|
||||
title="以下元数据(题名/摘要/主题词/附注)命中了敏感词库中的词。可对单条或批量记录执行:屏蔽(检索与索引中隐藏)、下架、恢复正常、删除。"
|
||||
/>
|
||||
|
||||
<div class="toolbar">
|
||||
<el-button type="danger" plain :disabled="!hitSelection.length" @click="batchHit('MASK', '屏蔽')">
|
||||
批量屏蔽
|
||||
</el-button>
|
||||
<el-button type="warning" plain :disabled="!hitSelection.length" @click="batchHit('OFFLINE', '下架')">
|
||||
批量下架
|
||||
</el-button>
|
||||
<el-button type="success" plain :disabled="!hitSelection.length" @click="batchHit('RESTORE', '恢复正常')">
|
||||
批量恢复
|
||||
</el-button>
|
||||
<el-button type="danger" :disabled="!hitSelection.length" @click="batchHit('DELETE', '删除')">
|
||||
批量删除
|
||||
</el-button>
|
||||
<el-button @click="fetchHits">刷新</el-button>
|
||||
</div>
|
||||
|
||||
<el-table
|
||||
v-loading="hitLoading"
|
||||
:data="hitList"
|
||||
border
|
||||
stripe
|
||||
@selection-change="(rows: SensitiveHit[]) => (hitSelection = rows)"
|
||||
>
|
||||
<el-table-column type="selection" width="45" />
|
||||
<el-table-column prop="title" label="正题名" min-width="200" show-overflow-tooltip />
|
||||
<el-table-column prop="author" label="责任者" width="120" show-overflow-tooltip />
|
||||
<el-table-column prop="sourceLibrary" label="来源馆" width="150" show-overflow-tooltip />
|
||||
<el-table-column prop="mediaType" label="媒体类型" width="90" />
|
||||
<el-table-column label="命中敏感词" min-width="150">
|
||||
<template #default="{ row }">
|
||||
<el-tag v-for="w in row.matchedWords" :key="w" size="small" type="danger" class="hit-tag">
|
||||
{{ w }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="管理状态" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-tag size="small" :type="manageStatusTag[row.manageStatus ?? 0]">
|
||||
{{ manageStatusText[row.manageStatus ?? 0] }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="200" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="danger" size="small" @click="handleHit(row, 'MASK', '屏蔽')">屏蔽</el-button>
|
||||
<el-button link type="warning" size="small" @click="handleHit(row, 'OFFLINE', '下架')">下架</el-button>
|
||||
<el-button link type="success" size="small" @click="handleHit(row, 'RESTORE', '恢复正常')">恢复</el-button>
|
||||
<el-button link type="danger" size="small" @click="handleHit(row, 'DELETE', '删除')">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<el-pagination
|
||||
class="pager"
|
||||
background
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
:total="hitTotal"
|
||||
v-model:current-page="hitQuery.current"
|
||||
v-model:page-size="hitQuery.size"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
@current-change="fetchHits"
|
||||
@size-change="fetchHits"
|
||||
/>
|
||||
</el-tab-pane>
|
||||
|
||||
<!-- ==================== 院校资源库 ==================== -->
|
||||
<el-tab-pane label="院校资源库" name="library">
|
||||
<div class="library-grid">
|
||||
<!-- 资源数量统计 -->
|
||||
<div class="panel">
|
||||
<div class="panel-head">
|
||||
<span class="panel-title">资源数量统计</span>
|
||||
<el-radio-group v-model="statDim" size="small" @change="fetchStats">
|
||||
<el-radio-button v-for="d in statDims" :key="d.value" :value="d.value">
|
||||
{{ d.label }}
|
||||
</el-radio-button>
|
||||
</el-radio-group>
|
||||
</div>
|
||||
<el-table v-loading="statLoading" :data="statList" border stripe max-height="480">
|
||||
<el-table-column type="index" label="#" width="50" />
|
||||
<el-table-column prop="name" label="名称" min-width="200" show-overflow-tooltip />
|
||||
<el-table-column prop="count" label="资源数量" width="100" align="right" />
|
||||
</el-table>
|
||||
</div>
|
||||
|
||||
<!-- 资源节点与链接管理 -->
|
||||
<div class="panel">
|
||||
<div class="panel-head">
|
||||
<span class="panel-title">资源节点与访问链接</span>
|
||||
<div>
|
||||
<el-button type="success" size="small" @click="openNodeCreate">新增节点</el-button>
|
||||
<el-button
|
||||
type="danger"
|
||||
size="small"
|
||||
plain
|
||||
:disabled="!nodeSelection.length"
|
||||
@click="batchDeleteNodes"
|
||||
>
|
||||
批量删除
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<el-table
|
||||
v-loading="nodeLoading"
|
||||
:data="nodeList"
|
||||
border
|
||||
stripe
|
||||
max-height="480"
|
||||
@selection-change="(rows: ResourceNode[]) => (nodeSelection = rows)"
|
||||
>
|
||||
<el-table-column type="selection" width="45" />
|
||||
<el-table-column prop="sortNo" label="顺序" width="65" align="center" />
|
||||
<el-table-column prop="name" label="节点名称" min-width="150" show-overflow-tooltip />
|
||||
<el-table-column prop="nodeType" label="资源类型" width="100" show-overflow-tooltip />
|
||||
<el-table-column prop="category" label="类别归属" width="110" show-overflow-tooltip />
|
||||
<el-table-column label="访问链接" min-width="160" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
<a v-if="row.linkUrl" :href="row.linkUrl" target="_blank" class="link">{{ row.linkUrl }}</a>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" width="80">
|
||||
<template #default="{ row }">
|
||||
<el-tag size="small" :type="row.status === 1 ? 'success' : 'info'">
|
||||
{{ row.status === 1 ? '启用' : '停用' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="130" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" size="small" @click="openNodeEdit(row)">编辑</el-button>
|
||||
<el-button link type="danger" size="small" @click="deleteNode(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
</div>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
|
||||
<!-- 敏感词 新增/编辑 弹窗 -->
|
||||
<el-dialog v-model="wordDialog" :title="wordForm.id ? '编辑敏感词' : '新增敏感词'" width="420px">
|
||||
<el-form label-width="90px">
|
||||
<el-form-item label="敏感词" required>
|
||||
<el-input v-model="wordForm.word" placeholder="中文敏感词" maxlength="100" />
|
||||
</el-form-item>
|
||||
<el-form-item label="拼音">
|
||||
<el-input v-model="wordForm.pinyin" placeholder="如 migan(建议全小写无声调)" maxlength="200" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="wordDialog = false">取消</el-button>
|
||||
<el-button type="primary" :loading="wordSaving" @click="saveWord">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 资源节点 新增/编辑 弹窗 -->
|
||||
<el-dialog v-model="nodeDialog" :title="nodeForm.id ? '编辑资源节点' : '新增资源节点'" width="520px">
|
||||
<el-form label-width="90px">
|
||||
<el-form-item label="节点名称" required>
|
||||
<el-input v-model="nodeForm.name" maxlength="200" />
|
||||
</el-form-item>
|
||||
<el-form-item label="资源类型">
|
||||
<el-input v-model="nodeForm.nodeType" placeholder="如 古籍善本 / 电子文献" maxlength="50" />
|
||||
</el-form-item>
|
||||
<el-form-item label="类别归属">
|
||||
<el-input v-model="nodeForm.category" placeholder="如 军事理论类" maxlength="100" />
|
||||
</el-form-item>
|
||||
<el-form-item label="访问链接">
|
||||
<el-input v-model="nodeForm.linkUrl" placeholder="http://..." maxlength="500" />
|
||||
</el-form-item>
|
||||
<el-form-item label="展示顺序">
|
||||
<el-input-number v-model="nodeForm.sortNo" :min="0" :max="9999" />
|
||||
<span class="form-tip">数值小的靠前展示</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-switch v-model="nodeForm.status" :active-value="1" :inactive-value="0" active-text="启用" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="nodeDialog = false">取消</el-button>
|
||||
<el-button type="primary" :loading="nodeSaving" @click="saveNode">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.admin-page {
|
||||
max-width: 1400px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
margin: 0 0 12px;
|
||||
font-family: 'Noto Serif SC', 'Songti SC', 'SimSun', serif;
|
||||
font-size: 22px;
|
||||
letter-spacing: 2px;
|
||||
color: #1d3a2a;
|
||||
}
|
||||
|
||||
.admin-tabs {
|
||||
background: #fff;
|
||||
border-radius: 10px;
|
||||
padding: 8px 20px 20px;
|
||||
box-shadow: 0 2px 10px rgba(20, 45, 30, 0.06);
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-bottom: 14px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.hint {
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.pager {
|
||||
margin-top: 14px;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.hit-tag {
|
||||
margin: 2px 4px 2px 0;
|
||||
}
|
||||
|
||||
.library-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1.2fr;
|
||||
gap: 20px;
|
||||
|
||||
@media (max-width: 1100px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.panel {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.panel-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
margin-bottom: 12px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.panel-title {
|
||||
font-weight: 600;
|
||||
color: #1d3a2a;
|
||||
}
|
||||
|
||||
.link {
|
||||
color: var(--el-color-primary);
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.form-tip {
|
||||
margin-left: 10px;
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
}
|
||||
</style>
|
||||
@@ -84,6 +84,20 @@ async function openEdit(row: VersionResource) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 新增:复用编辑抽屉,空表单(不带 id,保存时后端走新增) */
|
||||
function openCreate() {
|
||||
editForm.value = {
|
||||
title: '',
|
||||
governStatus: 'RAW',
|
||||
abnormalFlag: 0,
|
||||
sensitiveFlag: 0,
|
||||
manageStatus: 0,
|
||||
isSpecial: 0
|
||||
} as VersionResource
|
||||
detailLoading.value = false
|
||||
drawerVisible.value = true
|
||||
}
|
||||
|
||||
async function saveEdit() {
|
||||
if (!formRef.value) return
|
||||
await formRef.value.validate()
|
||||
@@ -129,6 +143,7 @@ onMounted(fetchData)
|
||||
<el-form-item>
|
||||
<el-button type="primary" :icon="Search" @click="handleSearch">查询</el-button>
|
||||
<el-button :icon="Refresh" @click="handleReset">重置</el-button>
|
||||
<el-button type="danger" plain @click="openCreate">新增</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
@@ -187,7 +202,7 @@ onMounted(fetchData)
|
||||
<!-- 编辑抽屉:完整元数据 + 是否特藏版本 -->
|
||||
<el-drawer
|
||||
v-model="drawerVisible"
|
||||
:title="editForm.id ? '编辑版本资源' : '版本资源'"
|
||||
:title="editForm.id ? '编辑版本资源' : '新增版本资源'"
|
||||
size="720px"
|
||||
>
|
||||
<div v-loading="detailLoading">
|
||||
|
||||
@@ -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) => ({ '&': '&', '<': '<', '>': '>', '"': '"' })[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>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { Download } from '@element-plus/icons-vue'
|
||||
import { getResource } from '@/api/resource'
|
||||
import { getRecommend, type SpecialRecommendItem } from '@/api/special'
|
||||
import { getResource, updateSpecialFlag } from '@/api/resource'
|
||||
import { getRecommend, removeSpecial as removeSpecialResource, type SpecialRecommendItem } from '@/api/special'
|
||||
|
||||
const route = useRoute()
|
||||
|
||||
@@ -17,6 +17,7 @@ interface Detail {
|
||||
author?: string
|
||||
publishYear?: string
|
||||
fulltextUrl?: string
|
||||
cover?: string
|
||||
}
|
||||
|
||||
const dialogVisible = ref(false)
|
||||
@@ -54,10 +55,13 @@ async function openDetail(item: SpecialRecommendItem) {
|
||||
note: noteOf(item),
|
||||
author: item.author,
|
||||
publishYear: item.publishYear,
|
||||
fulltextUrl: urlOf(item)
|
||||
fulltextUrl: urlOf(item),
|
||||
cover: item.coverUrl
|
||||
}
|
||||
// 只有来自 version_resource 的记录才有 title,可据此补拉完整著录
|
||||
if (item.id && item.title) {
|
||||
// 仅 version_resource 来源(source=VERSION)补拉完整著录;
|
||||
// special_resource 手工特藏(source=MANUAL)的 id 属于特藏表,
|
||||
// 拿去查 /resource/{id} 会错表错行,直接用列表行数据展示
|
||||
if (item.id && item.source === 'VERSION') {
|
||||
try {
|
||||
const full = await getResource(item.id)
|
||||
current.value = {
|
||||
@@ -65,7 +69,8 @@ async function openDetail(item: SpecialRecommendItem) {
|
||||
note: full.note,
|
||||
author: full.author,
|
||||
publishYear: full.publishYear,
|
||||
fulltextUrl: full.fulltextUrl
|
||||
fulltextUrl: full.fulltextUrl,
|
||||
cover: item.coverUrl
|
||||
}
|
||||
} catch {
|
||||
/* 保留列表行数据兜底 */
|
||||
@@ -83,6 +88,26 @@ function download(item: SpecialRecommendItem) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 从特藏推荐中移除:按数据来源分流 */
|
||||
async function removeSpecial(item: SpecialRecommendItem) {
|
||||
if (!item.id) return
|
||||
if (item.source === 'VERSION') {
|
||||
// version_resource 特藏:取消 is_special 标记,资源保留在资源管理中
|
||||
await ElMessageBox.confirm(
|
||||
`确认将「${titleOf(item)}」从特藏推荐中移除?资源本身仍保留在资源管理中。`,
|
||||
'提示',
|
||||
{ type: 'warning' }
|
||||
)
|
||||
await updateSpecialFlag(item.id, 0)
|
||||
} else {
|
||||
// special_resource 手工维护的特藏:逻辑删除(deleted=1)
|
||||
await ElMessageBox.confirm(`确认删除特藏「${titleOf(item)}」?`, '提示', { type: 'warning' })
|
||||
await removeSpecialResource(item.id)
|
||||
}
|
||||
ElMessage.success('删除成功')
|
||||
fetchList()
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await fetchList()
|
||||
// 从首页书架点书进来:自动打开对应特藏的详情
|
||||
@@ -126,6 +151,7 @@ onMounted(async () => {
|
||||
<el-icon :size="14"><Download /></el-icon>
|
||||
下载
|
||||
</span>
|
||||
<span v-if="it.id && it.title" class="op del" @click.stop="removeSpecial(it)">删除</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -134,6 +160,7 @@ onMounted(async () => {
|
||||
<!-- 细览弹窗 -->
|
||||
<el-dialog v-model="dialogVisible" :title="current?.title || '特藏细览'" width="620px">
|
||||
<template v-if="current">
|
||||
<img v-if="current.cover" :src="current.cover" class="dialog-cover" :alt="current.title" />
|
||||
<el-descriptions :column="1" border size="small">
|
||||
<el-descriptions-item label="正题名">{{ current.title || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="责任者">{{ current.author || '-' }}</el-descriptions-item>
|
||||
@@ -165,6 +192,16 @@ onMounted(async () => {
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
|
||||
/* 细览弹窗封面图 */
|
||||
.dialog-cover {
|
||||
display: block;
|
||||
max-width: 200px;
|
||||
max-height: 260px;
|
||||
margin: 0 auto 16px;
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 4px 14px rgba(60, 45, 10, 0.2);
|
||||
}
|
||||
|
||||
/* ---------- 列表(参考站外资源展示样式:图左 · 题名 · 描述 · 右侧入口) ---------- */
|
||||
.special-list {
|
||||
display: flex;
|
||||
@@ -283,6 +320,15 @@ onMounted(async () => {
|
||||
color: #8a6d3b;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* 删除:红色示警 */
|
||||
&.del {
|
||||
color: #c0392b;
|
||||
|
||||
&:hover {
|
||||
color: #96281b;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user