feat: migrate static pages to native tabbar
This commit is contained in:
61
packages/mingli/pages/search-books/index.js
Normal file
61
packages/mingli/pages/search-books/index.js
Normal file
@@ -0,0 +1,61 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user