Files

62 lines
1.5 KiB
JavaScript

const { ROUTES, openStaticRoute } = require('../../../../utils/static-ux/route-map')
const SEARCH_CATALOG = Object.freeze([
{
key: 'classic-a',
title: '滴天髓',
subtitle: '命理经典结果',
aliases: ['滴天', '天髓'],
route: `${ROUTES.mingli.bookDetail}?scene=classic-a`
},
{
key: 'classic-b',
title: '穷通宝鉴',
subtitle: '格局与用神',
aliases: ['穷通', '宝鉴'],
route: `${ROUTES.mingli.bookDetail}?scene=classic-b`
}
])
function createMingliSearchBooksPageData(keyword) {
const normalizedKeyword = (keyword || '').trim()
const results = normalizedKeyword
? SEARCH_CATALOG.filter(item => {
return (
item.title.includes(normalizedKeyword) ||
item.aliases.some(alias => alias.includes(normalizedKeyword))
)
}).map(item => ({ ...item }))
: []
return {
title: '搜索易学典籍',
keyword: normalizedKeyword,
history: ['滴天髓', '穷通宝鉴', '子平真诠'],
results
}
}
function showNavigate(route) {
openStaticRoute(route, wx)
}
Page({
data: createMingliSearchBooksPageData(''),
onLoad(options) {
this.setData(createMingliSearchBooksPageData(options.keyword || options.q))
},
handleHistoryTap(event) {
this.setData(createMingliSearchBooksPageData(event.currentTarget.dataset.keyword))
},
handleResultTap(event) {
showNavigate(event.currentTarget.dataset.route)
}
})
module.exports = {
createMingliSearchBooksPageData
}