const { ROUTES, openStaticRoute } = require('../../utils/static-ux/route-map') const LIBRARY_CATEGORIES = Object.freeze([ { id: 'featured', name: '精选' }, { id: 'annotation', name: '注解' }, { id: 'classic-theory', name: '经论' }, { id: 'cold-damage', name: '伤寒金匮' }, { id: 'formula', name: '医方' }, { id: 'materia-medica', name: '本草' }, { id: 'acupuncture', name: '针灸' }, { id: 'medical-record', name: '医案' }, { id: 'comprehensive', name: '综合' } ]) const LIBRARY_BOOKS = Object.freeze({ featured: [ { id: 'huangdi-neijing-suwen', coverText: '典', title: '黄帝内经素问', author: '王冰次', dynasty: '唐', period: '公元762年' }, { id: 'shang-han-lun', coverText: '典', title: '伤寒论', author: '张仲景', dynasty: '东汉', period: '公元25-220年' }, { id: 'wen-bing-tiao-bian', coverText: '典', title: '温病条辨', author: '吴鞠通', dynasty: '清', period: '公元1644-1911年' }, { id: 'bencao-gangmu-bieming-lu', coverText: '典', title: '本草纲目别名录', author: '李时珍', dynasty: '明', period: '公元1368-1644年' }, { id: 'huangdi-neijing-jizhu', coverText: '典', title: '黄帝内经灵枢集注', author: '张志聪', dynasty: '清', period: '公元1672年' }, { id: 'jingui-yaolue-fanglun', coverText: '典', title: '金匮要略方论', author: '张仲景', dynasty: '汉', period: '公元219年' } ], annotation: [ { id: 'huangdi-neijing-suwen-jizhu', coverText: '典', title: '黄帝内经素问集注', author: '张志聪', dynasty: '清', period: '公元1672年' }, { id: 'shennong-bencao-jizhu', coverText: '典', title: '神农本草经辑注', author: '孙星衍', dynasty: '清', period: '公元1796年' }, { id: 'nanjing-jizhu', coverText: '典', title: '难经集注', author: '王九思', dynasty: '明', period: '公元1506年' } ], 'classic-theory': [ { id: 'nan-jing', coverText: '典', title: '难经', author: '扁鹊', dynasty: '战国', period: '约公元前475-221年' }, { id: 'lei-jing', coverText: '典', title: '类经', author: '张介宾', dynasty: '明', period: '公元1624年' }, { id: 'yi-zong-bi-du', coverText: '典', title: '医宗必读', author: '李中梓', dynasty: '明', period: '公元1637年' } ], 'cold-damage': [ { id: 'jin-kui-yao-lve', coverText: '典', title: '金匮要略', author: '张仲景', dynasty: '东汉', period: '公元219年' }, { id: 'zhu-jie-shang-han-lun', coverText: '典', title: '注解伤寒论', author: '成无己', dynasty: '金', period: '公元1144年' }, { id: 'shang-han-ming-li-lun', coverText: '典', title: '伤寒明理论', author: '成无己', dynasty: '金', period: '公元1156年' } ], formula: [ { id: 'tai-ping-hui-min-he-ji-ju-fang', coverText: '典', title: '太平惠民和剂局方', author: '陈师文', dynasty: '宋', period: '公元1107年' }, { id: 'pu-ji-fang', coverText: '典', title: '普济方', author: '朱橚', dynasty: '明', period: '公元1406年' }, { id: 'yi-fang-kao', coverText: '典', title: '医方考', author: '吴昆', dynasty: '明', period: '公元1584年' } ], 'materia-medica': [ { id: 'shennong-bencao-jing', coverText: '典', title: '神农本草经', author: '佚名', dynasty: '汉', period: '约公元1-2世纪' }, { id: 'bencao-gangmu', coverText: '典', title: '本草纲目', author: '李时珍', dynasty: '明', period: '公元1578年' }, { id: 'bencao-cong-xin', coverText: '典', title: '本草从新', author: '吴仪洛', dynasty: '清', period: '公元1757年' } ], acupuncture: [ { id: 'zhen-jiu-jia-yi-jing', coverText: '典', title: '针灸甲乙经', author: '皇甫谧', dynasty: '西晋', period: '公元282年' }, { id: 'zhen-jiu-da-cheng', coverText: '典', title: '针灸大成', author: '杨继洲', dynasty: '明', period: '公元1601年' }, { id: 'tong-ren-shu-xue-zhen-jiu-tu-jing', coverText: '典', title: '铜人腧穴针灸图经', author: '王惟一', dynasty: '宋', period: '公元1026年' } ], 'medical-record': [ { id: 'lin-zheng-zhi-nan-yi-an', coverText: '典', title: '临证指南医案', author: '叶天士', dynasty: '清', period: '公元1746年' }, { id: 'shi-an-de-xiao-fang', coverText: '典', title: '石案得效方', author: '危亦林', dynasty: '元', period: '公元1337年' }, { id: 'wang-meng-ying-yi-an', coverText: '典', title: '王孟英医案', author: '王孟英', dynasty: '清', period: '公元1862年' } ], comprehensive: [ { id: 'yi-xue-ru-men', coverText: '典', title: '医学入门', author: '李梴', dynasty: '明', period: '公元1575年' }, { id: 'jing-yue-quan-shu', coverText: '典', title: '景岳全书', author: '张介宾', dynasty: '明', period: '公元1624年' }, { id: 'yi-zong-jin-jian', coverText: '典', title: '医宗金鉴', author: '吴谦', dynasty: '清', period: '公元1742年' } ] }) function cloneItems(items) { return items.map(item => ({ ...item })) } function getCategoryById(categoryId) { return LIBRARY_CATEGORIES.find(item => item.id === categoryId) || LIBRARY_CATEGORIES[0] } function getBooksByCategory(categoryId) { const activeCategory = getCategoryById(categoryId) return cloneItems(LIBRARY_BOOKS[activeCategory.id] || []) } function createLibraryPageData(categoryId) { const activeCategory = getCategoryById(categoryId) return { title: '典籍', searchButtonText: '搜索', domainBridge: { title: '进入易学阁', subtitle: '切换到命理与经典的静态学习入口', route: ROUTES.mingli.hall }, categories: cloneItems(LIBRARY_CATEGORIES), activeCategoryId: activeCategory.id, currentCategoryName: activeCategory.name, visibleBooks: getBooksByCategory(activeCategory.id) } } function showNavigate(route) { if (openStaticRoute(route, wx)) { return } if (typeof wx?.showToast === 'function') { wx.showToast({ title: '页面暂不可达', icon: 'none' }) } } Page({ data: createLibraryPageData(), handleCategoryTap(event) { const categoryId = event.currentTarget.dataset.categoryId this.setData(createLibraryPageData(categoryId)) }, handleSearchTap() { if (!wx || typeof wx.showToast !== 'function') { return } wx.showToast({ title: '搜索功能暂未开放', icon: 'none' }) }, handleDomainBridgeTap() { showNavigate(ROUTES.mingli.hall) } }) module.exports = { LIBRARY_CATEGORIES, LIBRARY_BOOKS, createLibraryPageData, getBooksByCategory }