46 lines
1.0 KiB
TypeScript
46 lines
1.0 KiB
TypeScript
/**
|
||
* 路由辅助工具函数
|
||
* getMenuRoute 为纯函数,navigateTo/switchTab/navigateBack 封装 wx.* API
|
||
*/
|
||
|
||
/** 菜单 key → 页面路径映射 */
|
||
const MENU_ROUTE_MAP: Record<string, string> = {
|
||
'chat-history': '/pages/chat-history/chat-history',
|
||
'performance': '/pages/performance/performance',
|
||
'notes': '/pages/notes/notes',
|
||
'settings': '',
|
||
}
|
||
|
||
/**
|
||
* 获取菜单项对应的页面路径
|
||
* @param menuKey 菜单 key
|
||
* @returns 页面路径,未知 key 返回空字符串
|
||
*/
|
||
export function getMenuRoute(menuKey: string): string {
|
||
return MENU_ROUTE_MAP[menuKey] ?? ''
|
||
}
|
||
|
||
/**
|
||
* 跳转到普通页面
|
||
* @param url 页面路径
|
||
*/
|
||
export function navigateTo(url: string): void {
|
||
wx.navigateTo({ url })
|
||
}
|
||
|
||
/**
|
||
* 切换 TabBar 页面
|
||
* @param url TabBar 页面路径
|
||
*/
|
||
export function switchTab(url: string): void {
|
||
wx.switchTab({ url })
|
||
}
|
||
|
||
/**
|
||
* 返回上一页
|
||
* @param delta 返回层数,默认 1
|
||
*/
|
||
export function navigateBack(delta: number = 1): void {
|
||
wx.navigateBack({ delta })
|
||
}
|