chore: initialize frontend miniapp repository
This commit is contained in:
81
src/utils/search.ts
Normal file
81
src/utils/search.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* 搜索工具函数
|
||||
*/
|
||||
|
||||
import type { Exhibit, Hall, Facility } from '@/types'
|
||||
|
||||
/**
|
||||
* 搜索展品
|
||||
* @param exhibits 展品列表
|
||||
* @param keyword 关键词
|
||||
* @returns 匹配的展品列表
|
||||
*/
|
||||
export const searchExhibits = (exhibits: Exhibit[], keyword: string): Exhibit[] => {
|
||||
if (!keyword) return []
|
||||
|
||||
const lowerKeyword = keyword.toLowerCase()
|
||||
return exhibits.filter(exhibit => {
|
||||
return (
|
||||
exhibit.name.toLowerCase().includes(lowerKeyword) ||
|
||||
exhibit.artist?.toLowerCase().includes(lowerKeyword) ||
|
||||
exhibit.description.toLowerCase().includes(lowerKeyword)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索展厅
|
||||
* @param halls 展厅列表
|
||||
* @param keyword 关键词
|
||||
* @returns 匹配的展厅列表
|
||||
*/
|
||||
export const searchHalls = (halls: Hall[], keyword: string): Hall[] => {
|
||||
if (!keyword) return []
|
||||
|
||||
const lowerKeyword = keyword.toLowerCase()
|
||||
return halls.filter(hall => {
|
||||
return (
|
||||
hall.name.toLowerCase().includes(lowerKeyword) ||
|
||||
hall.description.toLowerCase().includes(lowerKeyword)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索设施
|
||||
* @param facilities 设施列表
|
||||
* @param keyword 关键词
|
||||
* @returns 匹配的设施列表
|
||||
*/
|
||||
export const searchFacilities = (facilities: Facility[], keyword: string): Facility[] => {
|
||||
if (!keyword) return []
|
||||
|
||||
const lowerKeyword = keyword.toLowerCase()
|
||||
return facilities.filter(facility => {
|
||||
return (
|
||||
facility.name.toLowerCase().includes(lowerKeyword) ||
|
||||
facility.location.toLowerCase().includes(lowerKeyword)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 综合搜索
|
||||
* @param exhibits 展品列表
|
||||
* @param halls 展厅列表
|
||||
* @param facilities 设施列表
|
||||
* @param keyword 关键词
|
||||
* @returns 搜索结果
|
||||
*/
|
||||
export const searchAll = (
|
||||
exhibits: Exhibit[],
|
||||
halls: Hall[],
|
||||
facilities: Facility[],
|
||||
keyword: string
|
||||
) => {
|
||||
return {
|
||||
exhibits: searchExhibits(exhibits, keyword),
|
||||
halls: searchHalls(halls, keyword),
|
||||
facilities: searchFacilities(facilities, keyword)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user