mirror of
https://github.com/ZiuChen/ClipboardManager.git
synced 2025-06-07 22:04:06 +08:00
fix: 修复了检索时展示了未过滤数据的问题
This commit is contained in:
parent
cfd6585828
commit
f748b56e3b
@ -37,6 +37,27 @@ const filterText = ref('') // 搜索框绑定值
|
||||
const list = ref([]) // 全部数据
|
||||
const showList = ref([]) // 展示的数据
|
||||
|
||||
const textFilterCallBack = (item) => {
|
||||
// filterText & item
|
||||
if (filterText.value.trim()) {
|
||||
if (filterText.value.trim().indexOf(' ') !== -1) {
|
||||
// 有过滤词 有空格
|
||||
const hitArray = []
|
||||
for (const f of filterText.value.trim().split(' ')) {
|
||||
hitArray.push(item.data.toLowerCase().indexOf(f.toLowerCase()) !== -1)
|
||||
}
|
||||
// 只返回全命中的 只要存在 false即不返回
|
||||
return hitArray.indexOf(false) === -1
|
||||
} else {
|
||||
// 有过滤词 无空格 不区分大小写检索
|
||||
return item.data.toLowerCase().indexOf(filterText.value.trim().toLowerCase()) !== -1
|
||||
}
|
||||
} else {
|
||||
// 无过滤词 返回全部
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
const updateShowList = (type) => {
|
||||
// 更新显示列表
|
||||
showList.value = list.value
|
||||
@ -44,25 +65,7 @@ const updateShowList = (type) => {
|
||||
type === 'collect' ? item.collect === true : type === 'all' ? item : item.type === type
|
||||
) // 是 collect则返回所有收藏 否则按照 type返回
|
||||
.filter((item) => (filterText.value ? item.type !== 'image' : item)) // 有过滤词 排除掉图片 DataURL
|
||||
.filter((item) => {
|
||||
if (filterText.value.trim()) {
|
||||
if (filterText.value.trim().indexOf(' ') !== -1) {
|
||||
// 有过滤词 有空格
|
||||
const hitArray = []
|
||||
for (const f of filterText.value.trim().split(' ')) {
|
||||
hitArray.push(item.data.toLowerCase().indexOf(f.toLowerCase()) !== -1)
|
||||
}
|
||||
// 只返回全命中的 只要存在 false即不返回
|
||||
return hitArray.indexOf(false) === -1
|
||||
} else {
|
||||
// 有过滤词 无空格 不区分大小写检索
|
||||
return item.data.toLowerCase().indexOf(filterText.value.trim().toLowerCase()) !== -1
|
||||
}
|
||||
} else {
|
||||
// 无过滤词 返回全部
|
||||
return true
|
||||
}
|
||||
})
|
||||
.filter((item) => textFilterCallBack(item))
|
||||
.slice(0, GAP) // 重新切分懒加载列表
|
||||
window.toTop()
|
||||
}
|
||||
@ -125,9 +128,11 @@ onMounted(() => {
|
||||
offset.value += GAP
|
||||
let addition = []
|
||||
if (activeTab.value !== 'all') {
|
||||
addition = list.value.filter((item) => item.type === activeTab.value)
|
||||
} else {
|
||||
addition = list.value
|
||||
.filter((item) => item.type === activeTab.value)
|
||||
.filter((item) => textFilterCallBack(item))
|
||||
} else {
|
||||
addition = list.value.filter((item) => textFilterCallBack(item))
|
||||
}
|
||||
addition = addition.slice(offset.value, offset.value + GAP)
|
||||
if (addition.length) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user