fix: 修复模板页面跳转并移除无入口的下单页
新增运行时 openPage/takePageQuery,tabBar 页自动使用 switchTab 并传递参数 - 编译器写入 tabPages,并拒绝 navigateTo/redirectTo 到 tabBar 页或 switchTab 带参数 - 阿成首页、套餐、出摊、主理人、详情、记录、成功页跳转统一改用 openPage - 套餐筛选改用后台业务提供项分类;详情跳咨询时携带业务提供项 - 移除 capability-booking:小程序无入口且依赖已删除的 /public/brand,需求由咨询表单覆盖"
This commit is contained in:
1 parent
a97cc860cf
commit
55989a5dfe
29 files changed
+353
-119
No files matched your search
@@ -237,6 +237,7 @@ function writeGeneratedFiles(output, manifest, params, appJson, capabilities) {
|
||||
templateKey: manifest.packageKey,
|
||||
templateVersion: manifest.version,
|
||||
runtimeContract: manifest.runtimeContract,
|
||||
tabPages: appJson.tabBar.list.map((item) => item.pagePath),
|
||||
};
|
||||
fs.writeFileSync(
|
||||
path.join(output, "runtime-config.js"),
|
||||
@@ -314,6 +315,7 @@ function validateOutput(output, appJson, packageKey) {
|
||||
}
|
||||
}
|
||||
const hasNpm = fs.existsSync(path.join(output, "miniprogram_npm"));
|
||||
const tabPages = new Set(appJson.tabBar.list.map((item) => item.pagePath));
|
||||
const forbiddenComponents = otherTemplateComponentNames(packageKey);
|
||||
const sourceFiles = listFiles(output, new Set(["miniprogram_npm"])).filter((file) =>
|
||||
/\.(js|json|wxml)$/.test(file),
|
||||
@@ -337,6 +339,16 @@ function validateOutput(output, appJson, packageKey) {
|
||||
if (!resolveRequire(output, file, match[1]))
|
||||
errors.push(`${file}: require("${match[1]}") cannot be resolved`);
|
||||
}
|
||||
// 微信不允许 navigateTo/redirectTo 到 tabBar 页,switchTab 也不能带参数;失败时页面毫无反应。
|
||||
for (const match of source.matchAll(
|
||||
/wx\.(navigateTo|redirectTo|switchTab)\(\s*\{\s*url:\s*["'`]\/?([^"'`?]+)(\?)?/g,
|
||||
)) {
|
||||
const [, method, target, hasQuery] = match;
|
||||
if (method !== "switchTab" && tabPages.has(target))
|
||||
errors.push(`${file}: wx.${method} cannot open tabBar page ${target}; use openPage()`);
|
||||
if (method === "switchTab" && hasQuery)
|
||||
errors.push(`${file}: wx.switchTab cannot pass a query to ${target}; use openPage()`);
|
||||
}
|
||||
}
|
||||
if (file.startsWith("pages/") || file.startsWith("components/")) {
|
||||
for (const token of ["pageRenderer", "templateKey ==="]) {
|
||||
|
||||
@@ -43,7 +43,7 @@ test("compiler generates an isolated Acheng runtime manifest", () => {
|
||||
true,
|
||||
);
|
||||
assert.equal(fs.existsSync(path.join(output, "pages/stall-service/index.wxml")), true);
|
||||
assert.equal(fs.existsSync(path.join(output, "pages/booking/index.wxml")), true);
|
||||
assert.equal(fs.existsSync(path.join(output, "pages/booking")), false);
|
||||
assert.equal(fs.existsSync(path.join(output, "assets/tab/booking.png")), true);
|
||||
// 运行时的 npm 构建产物必须完整复制,不能被按名称排除的 src/test/dist 误伤。
|
||||
const runtimeNpm = path.join(workspaceRoot, "apps/miniapp/miniprogram_npm");
|
||||
@@ -190,6 +190,36 @@ test("compiler lets a template replace a runtime page declared in overrides", ()
|
||||
);
|
||||
});
|
||||
|
||||
test("compiler rejects navigateTo calls that target tabBar pages", () => {
|
||||
const templateDirectory = copyTemplate("linjing-editorial");
|
||||
fs.appendFileSync(
|
||||
path.join(templateDirectory, "miniapp/pages/index/index.js"),
|
||||
'\nfunction broken() { wx.navigateTo({ url: "/pages/services/index" }); }\n',
|
||||
);
|
||||
const output = fs.mkdtempSync(path.join(os.tmpdir(), "personal-brand-template-"));
|
||||
assert.throws(
|
||||
() =>
|
||||
execFileSync(
|
||||
process.execPath,
|
||||
[compiler, "--template-dir", templateDirectory, "--out", output],
|
||||
{ cwd: workspaceRoot, stdio: "pipe" },
|
||||
),
|
||||
/wx\.navigateTo cannot open tabBar page pages\/services\/index/,
|
||||
);
|
||||
});
|
||||
|
||||
test("compiler writes tabBar pages into runtime-config for openPage", () => {
|
||||
const output = fs.mkdtempSync(path.join(os.tmpdir(), "personal-brand-template-"));
|
||||
execFileSync(process.execPath, [compiler, "--template", "acheng-campus-food", "--out", output], {
|
||||
cwd: workspaceRoot,
|
||||
stdio: "pipe",
|
||||
});
|
||||
const config = fs.readFileSync(path.join(output, "runtime-config.js"), "utf8");
|
||||
assert.match(config, /"tabPages"/);
|
||||
assert.match(config, /"pages\/inquiry\/index"/);
|
||||
assert.equal(fs.existsSync(path.join(output, "utils/navigation.js")), true);
|
||||
});
|
||||
|
||||
test("compiler rejects unknown capabilities before copying layers", () => {
|
||||
const templateDirectory = copyTemplate("linjing-editorial");
|
||||
const manifestPath = path.join(templateDirectory, "template.json");
|
||||
|
||||
Reference in new issue
Block a user