feat: migrate static pages to native tabbar
This commit is contained in:
125
packages/tcm/pages/book-detail/index.js
Normal file
125
packages/tcm/pages/book-detail/index.js
Normal file
@@ -0,0 +1,125 @@
|
||||
const { resolveScene } = require('../../../../utils/static-ux/shared')
|
||||
const { ROUTES, openStaticRoute } = require('../../../../utils/static-ux/route-map')
|
||||
|
||||
const BOOK_DETAIL_SURFACES = Object.freeze({
|
||||
'classic-a': {
|
||||
coverText: '黄',
|
||||
title: '黄帝内经素问',
|
||||
subtitle: '传世中医典籍 · 学习阅读入口',
|
||||
tags: ['经典', '入门'],
|
||||
description: '当前典籍详情页只保留封面、简介、目录和推荐区块,不迁移旧项目的详情接口。',
|
||||
progressText: '已读到:上古天真论',
|
||||
primaryRoute: `${ROUTES.tcm.section}?scene=reader-a`,
|
||||
catalog: [
|
||||
{
|
||||
key: 'chapter-1',
|
||||
title: '上古天真论',
|
||||
route: `${ROUTES.tcm.section}?scene=reader-a`,
|
||||
children: ['节录一', '节录二']
|
||||
},
|
||||
{
|
||||
key: 'chapter-2',
|
||||
title: '四气调神大论',
|
||||
route: `${ROUTES.tcm.section}?scene=reader-a`,
|
||||
children: ['节录一', '节录二']
|
||||
}
|
||||
],
|
||||
recommends: [
|
||||
{
|
||||
key: 'recommend-b',
|
||||
title: '伤寒论',
|
||||
route: `${ROUTES.tcm.bookDetail}?scene=classic-b`
|
||||
}
|
||||
]
|
||||
},
|
||||
'classic-b': {
|
||||
coverText: '伤',
|
||||
title: '伤寒论',
|
||||
subtitle: '经方经典 · 学习阅读入口',
|
||||
tags: ['经方', '进阶'],
|
||||
description: '静态详情页保留目录结构和推荐卡片,为后续新数据层留出清晰接口边界。',
|
||||
progressText: '已读到:太阳病篇',
|
||||
primaryRoute: `${ROUTES.tcm.section}?scene=reader-b`,
|
||||
catalog: [
|
||||
{
|
||||
key: 'chapter-1',
|
||||
title: '太阳病篇',
|
||||
route: `${ROUTES.tcm.section}?scene=reader-b`,
|
||||
children: ['条文一', '条文二']
|
||||
},
|
||||
{
|
||||
key: 'chapter-2',
|
||||
title: '阳明病篇',
|
||||
route: `${ROUTES.tcm.section}?scene=reader-b`,
|
||||
children: ['条文一', '条文二']
|
||||
}
|
||||
],
|
||||
recommends: [
|
||||
{
|
||||
key: 'recommend-a',
|
||||
title: '黄帝内经素问',
|
||||
route: `${ROUTES.tcm.bookDetail}?scene=classic-a`
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
function cloneCatalog(items) {
|
||||
return items.map(item => ({
|
||||
...item,
|
||||
children: [...item.children]
|
||||
}))
|
||||
}
|
||||
|
||||
function cloneItems(items) {
|
||||
return items.map(item => ({ ...item }))
|
||||
}
|
||||
|
||||
function createTcmBookDetailPageData(rawScene) {
|
||||
const scene = resolveScene(rawScene, ['classic-a', 'classic-b'], 'classic-a')
|
||||
const surface = BOOK_DETAIL_SURFACES[scene]
|
||||
|
||||
return {
|
||||
title: '典籍详情',
|
||||
scene,
|
||||
coverText: surface.coverText,
|
||||
book: {
|
||||
title: surface.title,
|
||||
subtitle: surface.subtitle
|
||||
},
|
||||
tags: [...surface.tags],
|
||||
description: surface.description,
|
||||
progressText: surface.progressText,
|
||||
primaryRoute: surface.primaryRoute,
|
||||
catalog: cloneCatalog(surface.catalog),
|
||||
recommends: cloneItems(surface.recommends)
|
||||
}
|
||||
}
|
||||
|
||||
function showNavigate(route) {
|
||||
openStaticRoute(route, wx)
|
||||
}
|
||||
|
||||
Page({
|
||||
data: createTcmBookDetailPageData('classic-a'),
|
||||
|
||||
onLoad(options) {
|
||||
this.setData(createTcmBookDetailPageData(options.scene))
|
||||
},
|
||||
|
||||
handlePrimaryTap() {
|
||||
showNavigate(this.data.primaryRoute)
|
||||
},
|
||||
|
||||
handleCatalogTap(event) {
|
||||
showNavigate(event.currentTarget.dataset.route)
|
||||
},
|
||||
|
||||
handleRecommendTap(event) {
|
||||
showNavigate(event.currentTarget.dataset.route)
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = {
|
||||
createTcmBookDetailPageData
|
||||
}
|
||||
Reference in New Issue
Block a user