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 {
|
||||
|
||||
Reference in New Issue
Block a user