feat: 产品筛选器的模糊搜索功能
- 引入纯前端依赖Fuse.js用于模糊匹配 - 新增Utils-fuzzyFilter封装Fuse的初始化与匹配 - 在前端将字符串匹配改为模糊匹配
This commit is contained in:
@ -74,7 +74,12 @@
|
||||
});
|
||||
|
||||
const filteredQuestions = computed(() => {
|
||||
return questions.value.filter((question: QuestionListView) => {
|
||||
const fuzzyMatchedQuestions = fuzzyMatch(questions.value, {
|
||||
keyword: filters.keyword,
|
||||
keys: ['title', 'content'],
|
||||
threshold: 0.2,
|
||||
});
|
||||
return fuzzyMatchedQuestions.filter((question: QuestionListView) => {
|
||||
const matchProduct = filters.selectedProduct
|
||||
? question.products?.some(
|
||||
(product: QuestionListProduct) =>
|
||||
@ -87,12 +92,7 @@
|
||||
)
|
||||
: true;
|
||||
|
||||
const matchKeyword = filters.keyword
|
||||
? (question.title && question.title.includes(filters.keyword)) ||
|
||||
(question.content && question.content.includes(filters.keyword))
|
||||
: true;
|
||||
|
||||
return matchProduct && matchKeyword;
|
||||
return matchProduct;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user