feat(admin): 添加列表显示字段配置功能

- 新增 list_field_config 表及后端接口,支持查询、保存、恢复默认字段配置
- 管理后台新增“列表字段配置”页签,可增删字段、调整顺序、修改显示名与可见性
- version_resource 表新增作者单位、来源资源库名字段及升级脚本
- 引入 xlsx 依赖以支持列表导出
This commit is contained in:
SUNJIAJINGS
2026-10-22 17:33:34 +08:00
parent 46be7346a2
commit 3626939ccb
14 changed files with 891 additions and 63 deletions
+151 -1
View File
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { onMounted, reactive, ref } from 'vue'
import { computed, onMounted, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
const activeTab = ref('words')
@@ -9,7 +9,10 @@ import {
createResourceNode,
createSensitiveWord,
handleHitAction,
listFields,
listResourceNodes,
resetListFields,
saveListFields,
pageHits,
pageSensitiveWords,
removeResourceNode,
@@ -18,6 +21,7 @@ import {
updateResourceNode,
updateSensitiveWord,
type HitAction,
type ListFieldConfig,
type ResourceNode,
type SensitiveHit,
type SensitiveWord,
@@ -267,11 +271,111 @@ async function batchDeleteNodes() {
fetchNodes()
}
// ==================== 列表显示字段配置 ====================
/** 可选字段池:新增字段行时从此处挑选 */
const fieldPool: { key: string; label: string }[] = [
{ key: 'title', label: '文献题名' },
{ key: 'publishYear', label: '发行时间' },
{ key: 'publishDate', label: '出版日期' },
{ key: 'author', label: '作者' },
{ key: 'authorOrg', label: '作者单位' },
{ key: 'publisher', label: '来源刊名/出版社' },
{ key: 'mediaType', label: '资源类型' },
{ key: 'sourceLibrary', label: '来源院校' },
{ key: 'sourceRepo', label: '来源资源库名' },
{ key: 'clcCode', label: '中图分类' },
{ key: 'keywords', label: '关键词' },
{ key: 'isbn', label: 'ISBN' },
{ key: 'format', label: '格式' },
{ key: 'language', label: '语种' },
{ key: 'pageCount', label: '页码' },
{ key: 'summary', label: '摘要' },
{ key: 'cdoi', label: 'CDOI' },
{ key: 'governStatus', label: '治理状态' }
]
const fieldScene = 'SEARCH'
const fieldList = ref<ListFieldConfig[]>([])
const fieldLoading = ref(false)
const fieldSaving = ref(false)
const addingKey = ref('')
async function fetchFields() {
fieldLoading.value = true
try {
fieldList.value = await listFields(fieldScene)
} finally {
fieldLoading.value = false
}
}
/** 上移 / 下移调整展示顺序 */
function moveField(idx: number, delta: number) {
const target = idx + delta
if (target < 0 || target >= fieldList.value.length) return
const arr = [...fieldList.value]
;[arr[idx], arr[target]] = [arr[target], arr[idx]]
arr.forEach((f, i) => (f.sortNo = (i + 1) * 10))
fieldList.value = arr
}
function removeField(idx: number) {
fieldList.value.splice(idx, 1)
fieldList.value.forEach((f, i) => (f.sortNo = (i + 1) * 10))
}
/** 从字段池新增一行(已存在的字段不可重复添加) */
function addField() {
if (!addingKey.value) return
if (fieldList.value.some((f) => f.fieldKey === addingKey.value)) {
ElMessage.warning('该字段已在列表中')
return
}
const src = fieldPool.find((f) => f.key === addingKey.value)
fieldList.value.push({
fieldKey: src!.key,
fieldLabel: src!.label,
sortNo: (fieldList.value.length + 1) * 10,
visible: 1
})
addingKey.value = ''
}
const availableOptions = computed(() =>
fieldPool.filter((f) => !fieldList.value.some((c) => c.fieldKey === f.key))
)
async function saveFields() {
if (!fieldList.value.length) {
ElMessage.warning('至少保留一个展示字段')
return
}
if (fieldList.value.some((f) => !f.fieldLabel?.trim())) {
ElMessage.warning('请填写完整的显示名')
return
}
fieldSaving.value = true
try {
await saveListFields(fieldScene, fieldList.value)
ElMessage.success('字段配置已保存,检索结果列表即时生效')
} finally {
fieldSaving.value = false
}
}
async function resetFields() {
await ElMessageBox.confirm('确认恢复默认的展示字段配置?', '提示', { type: 'warning' })
fieldList.value = await resetListFields(fieldScene)
ElMessage.success('已恢复默认配置')
}
onMounted(() => {
fetchWords()
fetchHits()
fetchNodes()
fetchStats()
fetchFields()
})
</script>
@@ -477,6 +581,52 @@ onMounted(() => {
</div>
</div>
</el-tab-pane>
<!-- ==================== 列表显示字段配置 ==================== -->
<el-tab-pane label="列表字段配置" name="fields">
<el-alert
class="hint"
type="info"
:closable="false"
title="配置检索结果列表显示哪些元数据字段:可新增、删除、上下调整顺序、修改显示名,或临时隐藏。保存后对全部用户的检索结果列表与导出字段即时生效。"
/>
<div class="toolbar">
<el-select v-model="addingKey" placeholder="选择要新增的字段" style="width: 240px" clearable>
<el-option v-for="f in availableOptions" :key="f.key" :label="f.label" :value="f.key" />
</el-select>
<el-button type="primary" plain :disabled="!addingKey" @click="addField">新增字段</el-button>
<el-button @click="resetFields">恢复默认</el-button>
<el-button type="primary" :loading="fieldSaving" @click="saveFields">保存配置</el-button>
</div>
<el-table v-loading="fieldLoading" :data="fieldList" border stripe max-height="520">
<el-table-column label="顺序" width="110" align="center">
<template #default="{ $index }">
<el-button-group>
<el-button size="small" :disabled="$index === 0" @click="moveField($index, -1)">↑</el-button>
<el-button size="small" :disabled="$index === fieldList.length - 1" @click="moveField($index, 1)">↓</el-button>
</el-button-group>
</template>
</el-table-column>
<el-table-column prop="fieldKey" label="字段键" width="150" />
<el-table-column label="显示名" min-width="200">
<template #default="{ row }">
<el-input v-model="row.fieldLabel" size="small" maxlength="32" />
</template>
</el-table-column>
<el-table-column label="是否显示" width="100" align="center">
<template #default="{ row }">
<el-switch v-model="row.visible" :active-value="1" :inactive-value="0" />
</template>
</el-table-column>
<el-table-column label="操作" width="100" align="center">
<template #default="{ $index }">
<el-button link type="danger" size="small" @click="removeField($index)">删除</el-button>
</template>
</el-table-column>
</el-table>
</el-tab-pane>
</el-tabs>
<!-- 敏感词 新增/编辑 弹窗 -->