/** * 路由仓库 * 统一管理页面路由配置和跳转逻辑 */ // 页面路由配置 export const PAGE_ROUTES = { // 主要功能页面 MONK: "/pages/monk/monk", MONK_DETAIL: "/pages/monk/monkDetail", WALK_INTO: "/pages/walkInto/walkInto", INSTITUTIONAL_STRUCTURE: "/pages/institutionalStructure/institutionalStructure", ACTIVITY: "/pages/activity/activity", PRAY: "/pages/pray/pray", PC: "/pages/personalCenter/personalCenter", FUTURE: "/pages/institutionalStructure/institutionalStructure?pageStatus=1,2", VR: "/page_user/webViewVR/webViewVR?id=15", // 待开发页面 NEWS: "/pages/news/news", ABBOT: "/pages/abbot/abbot", ANCIENT: "/pages/ancient/ancient", // 其他页面 LOGIN: "/pages/login/login", INDEX: "/pages/index/index", MY: "/pages/my/my", MY_ORDER: "/pages/myorder/index", MY_ORDER_RETURNED: "/pages/myorder/returned/index", }; // 页面类型映射 export const PAGE_TYPE_MAP = { monk: PAGE_ROUTES.MONK, monkDetail: PAGE_ROUTES.MONK_DETAIL, walkInto: PAGE_ROUTES.WALK_INTO, institutionalStructure: PAGE_ROUTES.INSTITUTIONAL_STRUCTURE, activity: PAGE_ROUTES.ACTIVITY, news: PAGE_ROUTES.NEWS, abbot: PAGE_ROUTES.ABBOT, ancient: PAGE_ROUTES.ANCIENT, future: PAGE_ROUTES.FUTURE, index: PAGE_ROUTES.INDEX, pray: PAGE_ROUTES.PRAY, pc: PAGE_ROUTES.PC, vr: PAGE_ROUTES.VR, }; /** * 页面跳转方法 * @param {string} pageType - 页面类型 * @param {Object} options - 跳转选项 */ export function navigateToPage(pageType, options = {}) { // 清除loading状态 try { uni.hideLoading(); } catch (error) { console.warn("清除loading失败:", error); } const targetPage = PAGE_TYPE_MAP[pageType]; if (!targetPage) { // 使用uni.showToast替代console,减少文件系统访问 uni.showToast({ title: "页面配置错误", icon: "none", }); return; } const defaultOptions = { url: targetPage, fail: (err) => { // 避免在真机调试时输出过多日志 uni.showToast({ title: "页面开发中", icon: "none", }); }, }; uni.navigateTo({ ...defaultOptions, ...options, }); } /** * 跳转到TabBar页面 * @param {string} pageType - 页面类型 */ export function switchToTab(pageType) { // 清除loading状态 try { uni.hideLoading(); } catch (error) { console.warn("清除loading失败:", error); } const tabRoutes = { index: PAGE_ROUTES.INDEX, my: PAGE_ROUTES.MY, }; const targetPage = tabRoutes[pageType]; if (!targetPage) { uni.showToast({ title: "页面配置错误", icon: "none", }); return; } uni.switchTab({ url: targetPage, fail: (err) => { uni.showToast({ title: "跳转失败", icon: "none", }); }, }); } /** * 返回上一页 * @param {number} delta - 返回的页面数,默认为1 */ export function navigateBack(delta = 1) { uni.navigateBack({ delta, fail: () => { // 如果没有上一页,跳转到首页 // 使用 reLaunch 而不是 switchTab,因为首页不是 tabBar 页面 reLaunchToPage("index"); }, }); } /** * 重定向到页面 * @param {string} pageType - 页面类型 */ export function redirectToPage(pageType) { // 清除loading状态 try { uni.hideLoading(); } catch (error) { console.warn("清除loading失败:", error); } const targetPage = PAGE_TYPE_MAP[pageType]; if (!targetPage) { console.error("未知的页面类型:", pageType); return; } uni.redirectTo({ url: targetPage, fail: (err) => { console.error("页面重定向失败:", err); }, }); } /** * 重新启动到页面 * @param {string} pageType - 页面类型 */ export function reLaunchToPage(pageType) { // 清除loading状态 try { uni.hideLoading(); } catch (error) { console.warn("清除loading失败:", error); } const targetPage = PAGE_TYPE_MAP[pageType]; if (!targetPage) { console.error("未知的页面类型:", pageType); return; } uni.reLaunch({ url: targetPage, fail: (err) => { console.error("页面重启失败:", err); }, }); }