feat: migrate static pages to native tabbar
This commit is contained in:
@@ -1,93 +1,205 @@
|
||||
const { getRuntimeConfig } = require('../../config/env')
|
||||
const { sessionStore } = require('../../stores')
|
||||
const { maskToken } = require('../../utils/util')
|
||||
const { ROUTES, openStaticRoute } = require('../../utils/static-ux/route-map')
|
||||
const { createTcmHomeHubCards } = require('../../utils/static-ux/tcm')
|
||||
|
||||
const QUICK_ENTRIES = [
|
||||
{
|
||||
title: '登录主包',
|
||||
description: '演示主包内的认证入口、全局会话同步和基础 UI 组件封装。',
|
||||
badge: '主包',
|
||||
actionText: '打开登录页',
|
||||
actionPath: '/pages/login/index'
|
||||
},
|
||||
{
|
||||
title: '业务工作台',
|
||||
description: '演示分包页面,只在需要时加载,保持主包轻量和首页启动稳定。',
|
||||
badge: '分包',
|
||||
actionText: '进入工作台',
|
||||
actionPath: '/packages/demo/pages/workbench/index'
|
||||
}
|
||||
]
|
||||
const HOME_PAGE_BLUEPRINT = Object.freeze({
|
||||
brandName: '玄知中医',
|
||||
greeting: '晚上好',
|
||||
subtitle: '今天想学点什么?从典籍、工具或养生主题开始。',
|
||||
searchPlaceholder: '搜索典籍、术语、AI问答...',
|
||||
searchBadge: 'AI',
|
||||
searchRoute: ROUTES.tcm.searchBooks,
|
||||
portalTitle: '学习入口',
|
||||
encyclopediaTitle: '中医百科',
|
||||
encyclopediaCards: [
|
||||
{
|
||||
key: 'classic',
|
||||
icon: '书',
|
||||
title: '经典书城',
|
||||
route: ROUTES.tabs.library
|
||||
},
|
||||
{
|
||||
key: 'meridian',
|
||||
icon: '穴',
|
||||
title: '经络穴位',
|
||||
status: '待开放'
|
||||
},
|
||||
{
|
||||
key: 'disease',
|
||||
icon: '病',
|
||||
title: '疾病百科',
|
||||
status: '待开放'
|
||||
}
|
||||
],
|
||||
toolsTitle: '学习工具',
|
||||
toolCards: [
|
||||
{
|
||||
key: 'qa',
|
||||
icon: '问',
|
||||
title: 'AI问答',
|
||||
route: ROUTES.tabs.ai
|
||||
},
|
||||
{
|
||||
key: 'formula',
|
||||
icon: '方',
|
||||
title: '方剂笔记',
|
||||
route: `${ROUTES.tcm.assets}?kind=notes`
|
||||
},
|
||||
{
|
||||
key: 'constitution',
|
||||
icon: '诊',
|
||||
title: '体质诊断',
|
||||
route: ROUTES.tabs.ai
|
||||
},
|
||||
{
|
||||
key: 'wellness',
|
||||
icon: '养',
|
||||
title: '智能饮片'
|
||||
}
|
||||
],
|
||||
wellnessTitle: '养生调理',
|
||||
wellnessCards: [
|
||||
{
|
||||
key: 'constitution-check',
|
||||
icon: '🧬',
|
||||
title: 'AI体质检测',
|
||||
status: '待开放',
|
||||
route: ROUTES.tabs.ai
|
||||
},
|
||||
{
|
||||
key: 'medicated-diet',
|
||||
icon: '🍲',
|
||||
title: '药膳',
|
||||
status: '待开放'
|
||||
},
|
||||
{
|
||||
key: 'ingredient',
|
||||
icon: '🥬',
|
||||
title: '食材',
|
||||
status: '待开放'
|
||||
}
|
||||
],
|
||||
classicsTitle: '热门典籍',
|
||||
classicsActionText: '进入书城',
|
||||
classicsActionRoute: ROUTES.tabs.library,
|
||||
classicsBooks: [
|
||||
{
|
||||
key: 'huangdi-neijing-suwen',
|
||||
coverText: '黄',
|
||||
title: '黄帝内经素问',
|
||||
route: `${ROUTES.tcm.bookDetail}?scene=classic-a`
|
||||
},
|
||||
{
|
||||
key: 'shang-han-lun',
|
||||
coverText: '伤',
|
||||
title: '伤寒论',
|
||||
route: `${ROUTES.tcm.bookDetail}?scene=classic-b`
|
||||
},
|
||||
{
|
||||
key: 'wen-bing-tiao-bian',
|
||||
coverText: '温',
|
||||
title: '温病条辨',
|
||||
route: `${ROUTES.tcm.searchBooks}?keyword=温病条辨`
|
||||
},
|
||||
{
|
||||
key: 'bencao-gangmu-bieming-lu',
|
||||
coverText: '本',
|
||||
title: '本草纲目别名录',
|
||||
route: `${ROUTES.tcm.searchBooks}?keyword=本草纲目`
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
function buildSessionView(state) {
|
||||
const userName = state.userInfo?.nickname || state.userInfo?.name || '访客'
|
||||
function cloneItems(items) {
|
||||
return items.map(item => ({ ...item }))
|
||||
}
|
||||
|
||||
function createHomePageData() {
|
||||
return {
|
||||
statusLabel: state.isLoggedIn ? '已登录' : '未登录',
|
||||
userName,
|
||||
tokenLabel: maskToken(state.token),
|
||||
permissionsLabel: state.permissions.length ? state.permissions.join(' / ') : '暂无权限'
|
||||
brandName: HOME_PAGE_BLUEPRINT.brandName,
|
||||
greeting: HOME_PAGE_BLUEPRINT.greeting,
|
||||
subtitle: HOME_PAGE_BLUEPRINT.subtitle,
|
||||
searchPlaceholder: HOME_PAGE_BLUEPRINT.searchPlaceholder,
|
||||
searchBadge: HOME_PAGE_BLUEPRINT.searchBadge,
|
||||
searchRoute: HOME_PAGE_BLUEPRINT.searchRoute,
|
||||
portalTitle: HOME_PAGE_BLUEPRINT.portalTitle,
|
||||
portalCards: createTcmHomeHubCards(),
|
||||
encyclopediaTitle: HOME_PAGE_BLUEPRINT.encyclopediaTitle,
|
||||
encyclopediaCards: cloneItems(HOME_PAGE_BLUEPRINT.encyclopediaCards),
|
||||
toolsTitle: HOME_PAGE_BLUEPRINT.toolsTitle,
|
||||
toolCards: cloneItems(HOME_PAGE_BLUEPRINT.toolCards),
|
||||
wellnessTitle: HOME_PAGE_BLUEPRINT.wellnessTitle,
|
||||
wellnessCards: cloneItems(HOME_PAGE_BLUEPRINT.wellnessCards),
|
||||
classicsTitle: HOME_PAGE_BLUEPRINT.classicsTitle,
|
||||
classicsActionText: HOME_PAGE_BLUEPRINT.classicsActionText,
|
||||
classicsActionRoute: HOME_PAGE_BLUEPRINT.classicsActionRoute,
|
||||
classicsBooks: cloneItems(HOME_PAGE_BLUEPRINT.classicsBooks)
|
||||
}
|
||||
}
|
||||
|
||||
function navigateToRoute(route) {
|
||||
openStaticRoute(route, wx)
|
||||
}
|
||||
|
||||
function showPendingToast(title) {
|
||||
if (typeof wx?.showToast !== 'function') {
|
||||
return
|
||||
}
|
||||
|
||||
wx.showToast({
|
||||
title: title ? `${title}待开放` : '功能建设中',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
|
||||
function handleHomeEntry(route, title) {
|
||||
if (openStaticRoute(route, wx)) {
|
||||
return
|
||||
}
|
||||
|
||||
showPendingToast(title)
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
quickEntries: QUICK_ENTRIES,
|
||||
envName: '',
|
||||
apiBaseUrl: '',
|
||||
isLoggedIn: false,
|
||||
sessionView: buildSessionView(sessionStore.getState())
|
||||
},
|
||||
onLoad() {
|
||||
const runtimeConfig = getRuntimeConfig()
|
||||
data: createHomePageData(),
|
||||
|
||||
this.unsubscribe = sessionStore.subscribe(nextState => {
|
||||
this.syncSession(nextState)
|
||||
})
|
||||
handleSearchTap() {
|
||||
handleHomeEntry(this.data.searchRoute, '搜索')
|
||||
},
|
||||
|
||||
this.setData({
|
||||
envName: runtimeConfig.name.toUpperCase(),
|
||||
apiBaseUrl: runtimeConfig.baseURL
|
||||
})
|
||||
this.syncSession(sessionStore.getState())
|
||||
},
|
||||
onUnload() {
|
||||
this.unsubscribe?.()
|
||||
},
|
||||
syncSession(state) {
|
||||
this.setData({
|
||||
isLoggedIn: state.isLoggedIn,
|
||||
sessionView: buildSessionView(state)
|
||||
})
|
||||
},
|
||||
handlePrimaryAction() {
|
||||
if (this.data.isLoggedIn) {
|
||||
wx.navigateTo({
|
||||
url: '/packages/demo/pages/workbench/index'
|
||||
})
|
||||
return
|
||||
}
|
||||
handleEncyclopediaTap(event) {
|
||||
const { route, title } = event.currentTarget.dataset
|
||||
|
||||
wx.navigateTo({
|
||||
url: '/pages/login/index'
|
||||
})
|
||||
handleHomeEntry(route, title)
|
||||
},
|
||||
handleLogout() {
|
||||
sessionStore.clearSession()
|
||||
wx.showToast({
|
||||
title: '已清理登录态',
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
handlePortalTap(event) {
|
||||
navigateToRoute(event.currentTarget.dataset.route)
|
||||
},
|
||||
handleEntryAction(event) {
|
||||
const { path } = event.detail
|
||||
|
||||
if (!path) {
|
||||
return
|
||||
}
|
||||
handleToolTap(event) {
|
||||
const { route, title } = event.currentTarget.dataset
|
||||
|
||||
wx.navigateTo({
|
||||
url: path
|
||||
})
|
||||
handleHomeEntry(route, title)
|
||||
},
|
||||
|
||||
handleWellnessTap(event) {
|
||||
const { route, title } = event.currentTarget.dataset
|
||||
|
||||
handleHomeEntry(route, title)
|
||||
},
|
||||
|
||||
handleClassicActionTap() {
|
||||
handleHomeEntry(this.data.classicsActionRoute, this.data.classicsActionText)
|
||||
},
|
||||
|
||||
handleClassicTap(event) {
|
||||
const { route, title } = event.currentTarget.dataset
|
||||
|
||||
handleHomeEntry(route, title)
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = {
|
||||
HOME_PAGE_BLUEPRINT,
|
||||
createHomePageData
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user