feat: 第二次优化迭代
- Links 后端分页+前端分页器 - 搜索关键词高亮(mark标签) - 搜索防抖200ms,支持描述搜索 - 移除不可用的 type-check 脚本 - 更新 README 项目文档
This commit is contained in:
@@ -53,8 +53,8 @@
|
||||
/>
|
||||
<div v-else class="link-icon default-icon">{{ link.title[0] }}</div>
|
||||
<div class="link-info">
|
||||
<div class="link-title">{{ link.title }}</div>
|
||||
<div class="link-desc">{{ link.description }}</div>
|
||||
<div class="link-title" v-html="highlight(link.title, search)"></div>
|
||||
<div class="link-desc" v-html="highlight(link.description, search)"></div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
@@ -74,6 +74,7 @@ import { siteApi } from '@/api'
|
||||
const data = reactive({ categories: [] as any[], settings: {} as any, links: [] as any[] })
|
||||
const search = ref('')
|
||||
const filteredLinks = ref<any[]>([])
|
||||
const searchTimer = ref<ReturnType<typeof setTimeout>>()
|
||||
|
||||
const filteredCategories = computed(() => {
|
||||
return data.categories.filter((cat: any) =>
|
||||
@@ -86,10 +87,20 @@ function linksInCat(catId: number) {
|
||||
}
|
||||
|
||||
function filterLinks() {
|
||||
const q = search.value.trim()
|
||||
filteredLinks.value = q
|
||||
? data.links.filter((l: any) => l.title.toLowerCase().includes(q))
|
||||
: [...data.links]
|
||||
if (searchTimer.value) clearTimeout(searchTimer.value)
|
||||
searchTimer.value = setTimeout(() => {
|
||||
const q = search.value.trim().toLowerCase()
|
||||
filteredLinks.value = q
|
||||
? data.links.filter((l: any) => l.title.toLowerCase().includes(q) || l.description.toLowerCase().includes(q))
|
||||
: [...data.links]
|
||||
}, 200)
|
||||
}
|
||||
|
||||
function highlight(text: string, keyword: string) {
|
||||
if (!keyword.trim()) return text
|
||||
const idx = text.toLowerCase().indexOf(keyword.toLowerCase())
|
||||
if (idx === -1) return text
|
||||
return text.slice(0, idx) + '<mark>' + text.slice(idx, idx + keyword.length) + '</mark>' + text.slice(idx + keyword.length)
|
||||
}
|
||||
|
||||
async function loadData() {
|
||||
@@ -243,7 +254,9 @@ loadData()
|
||||
|
||||
.link-info { flex: 1; min-width: 0; }
|
||||
.link-title { font-weight: 500; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.link-title :deep(mark) { background: #fef08a; color: #333; padding: 0 2px; border-radius: 2px; }
|
||||
.link-desc { font-size: 12px; color: #888; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.link-desc :deep(mark) { background: #fef08a; color: #333; padding: 0 2px; border-radius: 2px; }
|
||||
}
|
||||
|
||||
.footer {
|
||||
|
||||
@@ -47,6 +47,15 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div v-if="total > pageSize" class="pagination-wrap">
|
||||
<el-pagination
|
||||
v-model:current-page="currentPage"
|
||||
:page-size="pageSize"
|
||||
:total="total"
|
||||
layout="prev, pager, next"
|
||||
@current-change="loadLinks"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
@@ -95,6 +104,9 @@ const links = ref([])
|
||||
const categories = ref([])
|
||||
const keyword = ref('')
|
||||
const catFilter = ref('')
|
||||
const currentPage = ref(1)
|
||||
const pageSize = ref(20)
|
||||
const total = ref(0)
|
||||
const dialogVisible = ref(false)
|
||||
const editId = ref(null)
|
||||
const form = ref({ title: '', url: '', categoryId: '', description: '', iconUrl: '', sort: 0, isShow: true })
|
||||
@@ -103,7 +115,10 @@ const dialogWidth = computed(() => window.innerWidth < 500 ? '92%' : '500px')
|
||||
async function loadLinks() {
|
||||
loading.value = true
|
||||
try {
|
||||
links.value = (await adminApi.getLinks({ keyword: keyword.value || undefined, categoryId: catFilter.value || undefined })).result.data
|
||||
const res = await adminApi.getLinks({ keyword: keyword.value || undefined, categoryId: catFilter.value || undefined, page: currentPage.value, pageSize: pageSize.value })
|
||||
const d = res.result.data
|
||||
links.value = d.list
|
||||
total.value = d.total
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
@@ -145,6 +160,7 @@ onMounted(async () => { await loadLinks(); await loadCats() })
|
||||
.page-header h2 { font-size: 20px; font-weight: 600; }
|
||||
.table-wrap { overflow-x: auto; }
|
||||
.loading-wrap { padding: 20px; }
|
||||
.pagination-wrap { display: flex; justify-content: center; margin-top: 20px; }
|
||||
.link-icon-preview {
|
||||
display: inline-flex;
|
||||
width: 32px;
|
||||
|
||||
Reference in New Issue
Block a user