项目框架
This commit is contained in:
@@ -0,0 +1,247 @@
|
||||
<script setup lang="ts">
|
||||
import { 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'
|
||||
|
||||
const route = useRoute()
|
||||
const loading = ref(false)
|
||||
const searched = ref(false)
|
||||
const rows = ref<VersionResource[]>([])
|
||||
const total = ref(0)
|
||||
const costMs = ref(0)
|
||||
const mediaFacets = ref<FacetItem[]>([])
|
||||
const libraryFacets = ref<FacetItem[]>([])
|
||||
|
||||
const query = reactive<SearchQuery>({
|
||||
current: 1,
|
||||
size: 20,
|
||||
keyword: '',
|
||||
mediaType: ''
|
||||
})
|
||||
|
||||
const field = ref('题名')
|
||||
const fields = ['题名', '责任者', '关键词', '出版社', 'ISBN']
|
||||
|
||||
async function doSearch() {
|
||||
loading.value = true
|
||||
searched.value = true
|
||||
try {
|
||||
const res = await unifiedSearch({ ...query })
|
||||
rows.value = res.page?.records || []
|
||||
total.value = res.page?.total || 0
|
||||
costMs.value = res.costMs || 0
|
||||
mediaFacets.value = res.mediaTypeFacets || []
|
||||
libraryFacets.value = res.sourceLibraryFacets || []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function pick(type: 'mediaType' | 'sourceLibrary', v: string) {
|
||||
query[type] = v
|
||||
query.current = 1
|
||||
doSearch()
|
||||
}
|
||||
|
||||
function goPage(p: number) {
|
||||
query.current = p
|
||||
doSearch()
|
||||
}
|
||||
|
||||
const drawer = ref(false)
|
||||
const detail = ref<VersionResource | null>(null)
|
||||
const similar = ref<VersionResource[]>([])
|
||||
|
||||
async function openDetail(row: VersionResource) {
|
||||
detail.value = row
|
||||
similar.value = []
|
||||
drawer.value = true
|
||||
const d = await getSearchDetail(row.id as number)
|
||||
if (d) detail.value = d
|
||||
similar.value = await getSimilar(row.id as number, 6)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
const kw = route.query.keyword as string
|
||||
if (kw) {
|
||||
query.keyword = kw
|
||||
doSearch()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="search-page">
|
||||
<div class="bar">
|
||||
<el-input v-model="query.keyword" size="large" placeholder="请输入检索词" clearable @keyup.enter="doSearch">
|
||||
<template #prepend>
|
||||
<el-select v-model="field" style="width: 96px">
|
||||
<el-option v-for="f in fields" :key="f" :label="f" :value="f" />
|
||||
</el-select>
|
||||
</template>
|
||||
<template #append><el-button type="primary" @click="doSearch">检索</el-button></template>
|
||||
</el-input>
|
||||
</div>
|
||||
|
||||
<div class="body" v-if="searched">
|
||||
<aside class="side">
|
||||
<div class="side-title">资源类型</div>
|
||||
<div v-for="f in mediaFacets" :key="f.name" class="side-item"
|
||||
:class="{ on: query.mediaType === f.name }" @click="pick('mediaType', f.name)">
|
||||
<span>{{ f.name }}</span><em>{{ f.value }}</em>
|
||||
</div>
|
||||
<div class="side-title">来源院校</div>
|
||||
<div v-for="f in libraryFacets" :key="f.name" class="side-item"
|
||||
:class="{ on: query.sourceLibrary === f.name }" @click="pick('sourceLibrary', f.name)">
|
||||
<span>{{ f.name }}</span><em>{{ f.value }}</em>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<section class="list">
|
||||
<div class="meta">共 <b>{{ total }}</b> 条,耗时 {{ costMs }} ms</div>
|
||||
<div v-loading="loading" class="cards">
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
<el-pagination class="pager" background layout="prev, pager, next" :total="total"
|
||||
:current-page="query.current" :page-size="query.size" @current-change="goPage" />
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<el-empty v-else description="请输入检索词开始检索" />
|
||||
|
||||
<el-drawer v-model="drawer" title="文献细览" size="46%">
|
||||
<template v-if="detail">
|
||||
<h3 class="dt">{{ detail.title }}</h3>
|
||||
<el-descriptions :column="1" border size="small">
|
||||
<el-descriptions-item label="责任者">{{ detail.author || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="出版者">{{ detail.publisher || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="出版年份">{{ detail.publishYear || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="媒体类型">{{ detail.mediaType || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="中图分类">{{ detail.clcCode || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="来源院校">{{ detail.sourceLibrary || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="关键词">{{ detail.keywords || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="摘要">{{ detail.summary || '-' }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
<div style="margin: 14px 0">
|
||||
<el-button v-if="detail.fulltextUrl" type="primary" tag="a" :href="detail.fulltextUrl" target="_blank">下载全文</el-button>
|
||||
<el-button v-else type="primary" disabled>暂无全文地址</el-button>
|
||||
</div>
|
||||
<div v-if="similar.length" class="sim">
|
||||
<div class="side-title">相似文献推荐</div>
|
||||
<div v-for="s in similar" :key="s.id" class="sim-item" @click="openDetail(s)">{{ s.title }}</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-drawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.bar {
|
||||
max-width: 860px;
|
||||
margin: 8px auto 20px;
|
||||
|
||||
:deep(.el-input-group__append) {
|
||||
background: var(--brand-primary);
|
||||
border-color: var(--brand-primary);
|
||||
color: #fff;
|
||||
padding: 0;
|
||||
|
||||
.el-button {
|
||||
background: transparent;
|
||||
color: #fff;
|
||||
border: none;
|
||||
height: 100%;
|
||||
padding: 0 22px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.body {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
max-width: 1240px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.side {
|
||||
width: 210px;
|
||||
flex: none;
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
padding: 12px;
|
||||
height: fit-content;
|
||||
|
||||
.side-title {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
margin: 10px 0 6px;
|
||||
}
|
||||
|
||||
.side-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
font-size: 13px;
|
||||
color: #5b6472;
|
||||
padding: 4px 6px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover { background: var(--brand-light); }
|
||||
&.on { background: var(--brand-light); color: var(--brand-primary); }
|
||||
em { color: #9aa3b2; font-style: normal; }
|
||||
}
|
||||
}
|
||||
|
||||
.list { flex: 1; }
|
||||
.meta { font-size: 13px; color: #6b7280; margin-bottom: 10px; }
|
||||
|
||||
.cards {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.card {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
padding: 14px;
|
||||
cursor: pointer;
|
||||
transition: box-shadow 0.2s;
|
||||
|
||||
&:hover { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1); }
|
||||
}
|
||||
|
||||
.cover {
|
||||
width: 56px;
|
||||
height: 76px;
|
||||
flex: none;
|
||||
border-radius: 4px;
|
||||
background: var(--brand-primary);
|
||||
color: #fff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.info {
|
||||
min-width: 0;
|
||||
|
||||
.t { font-size: 14px; font-weight: 600; color: #1f2937; margin-bottom: 6px; }
|
||||
.d { font-size: 12px; color: #8b93a1; }
|
||||
}
|
||||
|
||||
.pager { margin-top: 18px; justify-content: center; }
|
||||
.dt { margin: 0 0 12px; font-size: 17px; }
|
||||
.sim-item { font-size: 13px; padding: 6px 0; border-bottom: 1px dashed #eee; cursor: pointer; }
|
||||
</style>
|
||||
Reference in New Issue
Block a user