Files
que01 55989a5dfe fix: 修复模板页面跳转并移除无入口的下单页
新增运行时 openPage/takePageQuery,tabBar 页自动使用 switchTab 并传递参数
- 编译器写入 tabPages,并拒绝 navigateTo/redirectTo 到 tabBar 页或 switchTab 带参数
- 阿成首页、套餐、出摊、主理人、详情、记录、成功页跳转统一改用 openPage
- 套餐筛选改用后台业务提供项分类;详情跳咨询时携带业务提供项
- 移除 capability-booking:小程序无入口且依赖已删除的 /public/brand,需求由咨询表单覆盖"
2026-09-27 10:10:23 +08:00

40 lines
1.5 KiB
JavaScript

const runtimeConfig = require("../runtime-config");
// tabBar 页面由 template-compiler 按模板 navigation 写入 runtime-config.js。
const tabPages = new Set(runtimeConfig.tabPages || []);
function parseQuery(query) {
const result = {};
for (const pair of (query || "").split("&")) {
if (!pair) continue;
const [key, value = ""] = pair.split("=");
result[decodeURIComponent(key)] = decodeURIComponent(value);
}
return result;
}
/**
* 打开页面。目标是 tabBar 页时使用 switchTab(微信不允许 navigateTo 到 tabBar 页,
* 且 switchTab 不能带参数),参数暂存到 globalData,由目标页 takePageQuery 读取。
*/
function openPage(url) {
const [rawPath, query = ""] = String(url).replace(/^\//, "").split("?");
const fail = (error) => console.error("openPage failed", { url, error });
if (tabPages.has(rawPath)) {
getApp().globalData.pendingPageQuery = { path: rawPath, query: parseQuery(query) };
return wx.switchTab({ url: "/" + rawPath, fail });
}
return wx.navigateTo({ url: "/" + rawPath + (query ? "?" + query : ""), fail });
}
/** 读取并清除 openPage 为当前 tabBar 页暂存的参数;非 tabBar 页直接使用 onLoad 的 options。 */
function takePageQuery(path) {
const app = getApp();
const pending = app.globalData.pendingPageQuery;
if (!pending || pending.path !== String(path).replace(/^\//, "")) return {};
app.globalData.pendingPageQuery = null;
return pending.query;
}
module.exports = { openPage, takePageQuery };