fix: 修复了检索时展示了未过滤数据的问题

This commit is contained in:
ZiuChen 2022-09-08 18:08:18 +08:00
parent cfd6585828
commit f748b56e3b

View File

@ -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) {