2025-07-30 10:10:31 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 路由仓库
|
|
|
|
|
|
* 统一管理页面路由配置和跳转逻辑
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// 页面路由配置
|
|
|
|
|
|
export const PAGE_ROUTES = {
|
|
|
|
|
|
// 主要功能页面
|
|
|
|
|
|
MONK: '/pages/Monk/Monk',
|
|
|
|
|
|
WALK_INTO: '/pages/walkInto/walkInto',
|
|
|
|
|
|
INSTITUTIONAL_STRUCTURE: '/pages/institutionalStructure/institutionalStructure',
|
|
|
|
|
|
|
|
|
|
|
|
// 待开发页面
|
|
|
|
|
|
ACTIVITY: '/pages/activity/activity',
|
|
|
|
|
|
NEWS: '/pages/news/news',
|
|
|
|
|
|
ABBOT: '/pages/abbot/abbot',
|
|
|
|
|
|
ANCIENT: '/pages/ancient/ancient',
|
|
|
|
|
|
|
|
|
|
|
|
// 其他页面
|
|
|
|
|
|
LOGIN: '/pages/login/login',
|
|
|
|
|
|
INDEX: '/pages/nearbystores/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,
|
|
|
|
|
|
'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,
|
|
|
|
|
|
'index': PAGE_ROUTES.INDEX,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 页面跳转方法
|
|
|
|
|
|
* @param {string} pageType - 页面类型
|
|
|
|
|
|
* @param {Object} options - 跳转选项
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function navigateToPage(pageType, options = {}) {
|
|
|
|
|
|
const targetPage = PAGE_TYPE_MAP[pageType];
|
|
|
|
|
|
|
|
|
|
|
|
if (!targetPage) {
|
2025-07-30 10:45:26 +08:00
|
|
|
|
// 使用uni.showToast替代console,减少文件系统访问
|
2025-07-30 10:10:31 +08:00
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: '页面配置错误',
|
|
|
|
|
|
icon: 'none'
|
|
|
|
|
|
});
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const defaultOptions = {
|
|
|
|
|
|
url: targetPage,
|
|
|
|
|
|
fail: (err) => {
|
2025-07-30 10:45:26 +08:00
|
|
|
|
// 避免在真机调试时输出过多日志
|
2025-07-30 10:10:31 +08:00
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: '页面开发中',
|
|
|
|
|
|
icon: 'none'
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
uni.navigateTo({
|
|
|
|
|
|
...defaultOptions,
|
|
|
|
|
|
...options
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 跳转到TabBar页面
|
|
|
|
|
|
* @param {string} pageType - 页面类型
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function switchToTab(pageType) {
|
|
|
|
|
|
const tabRoutes = {
|
|
|
|
|
|
'index': PAGE_ROUTES.INDEX,
|
|
|
|
|
|
'my': PAGE_ROUTES.MY
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const targetPage = tabRoutes[pageType];
|
|
|
|
|
|
|
|
|
|
|
|
if (!targetPage) {
|
2025-07-30 10:45:26 +08:00
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: '页面配置错误',
|
|
|
|
|
|
icon: 'none'
|
|
|
|
|
|
});
|
2025-07-30 10:10:31 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uni.switchTab({
|
|
|
|
|
|
url: targetPage,
|
|
|
|
|
|
fail: (err) => {
|
2025-07-30 10:45:26 +08:00
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: '跳转失败',
|
|
|
|
|
|
icon: 'none'
|
|
|
|
|
|
});
|
2025-07-30 10:10:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 返回上一页
|
|
|
|
|
|
* @param {number} delta - 返回的页面数,默认为1
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function navigateBack(delta = 1) {
|
|
|
|
|
|
uni.navigateBack({
|
|
|
|
|
|
delta,
|
|
|
|
|
|
fail: () => {
|
|
|
|
|
|
// 如果没有上一页,跳转到首页
|
|
|
|
|
|
switchToTab('index');
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 重定向到页面
|
|
|
|
|
|
* @param {string} pageType - 页面类型
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function redirectToPage(pageType) {
|
|
|
|
|
|
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) {
|
|
|
|
|
|
const targetPage = PAGE_TYPE_MAP[pageType];
|
|
|
|
|
|
|
|
|
|
|
|
if (!targetPage) {
|
|
|
|
|
|
console.error('未知的页面类型:', pageType);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uni.reLaunch({
|
|
|
|
|
|
url: targetPage,
|
|
|
|
|
|
fail: (err) => {
|
|
|
|
|
|
console.error('页面重启失败:', err);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|