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
+10
-1
@@ -23,6 +23,15 @@ export class RequestIdMiddleware {
|
||||
}
|
||||
}
|
||||
|
||||
/** HttpException.getResponse() 可能是字符串,或 { message: string | string[] }(含 ValidationPipe 错误)。 */
|
||||
function readMessage(detail: unknown): string {
|
||||
if (typeof detail === "string") return detail;
|
||||
const message = (detail as { message?: unknown } | null)?.message;
|
||||
if (typeof message === "string" && message) return message;
|
||||
if (Array.isArray(message) && message.length) return message.map(String).join(";");
|
||||
return "请求失败";
|
||||
}
|
||||
|
||||
@Catch()
|
||||
export class ApiExceptionFilter implements ExceptionFilter {
|
||||
catch(exception: unknown, host: ArgumentsHost): void {
|
||||
@@ -41,7 +50,7 @@ export class ApiExceptionFilter implements ExceptionFilter {
|
||||
data: null,
|
||||
error: {
|
||||
code: `HTTP_${status}`,
|
||||
message: typeof detail === "string" ? detail : "请求失败",
|
||||
message: readMessage(detail),
|
||||
},
|
||||
requestId:
|
||||
(request as FastifyRequest & { requestId?: string }).requestId ??
|
||||
|
||||
@@ -1062,6 +1062,16 @@ test("admin can create and version an inquiry form", async () => {
|
||||
payload: { formId: id, values: {} },
|
||||
});
|
||||
assert.equal(missingRequired.statusCode, 400);
|
||||
// 业务校验错误必须透传具体原因,不能被统一改写为"请求失败"。
|
||||
assert.equal(JSON.parse(missingRequired.body).error.code, "HTTP_400");
|
||||
assert.match(JSON.parse(missingRequired.body).error.message, /不能为空$/);
|
||||
const invalidBody = await request("/customer/inquiry-submissions", {
|
||||
method: "POST",
|
||||
headers: { authorization: `Bearer ${customerToken}` },
|
||||
payload: { formId: id },
|
||||
});
|
||||
assert.equal(invalidBody.statusCode, 400);
|
||||
assert.notEqual(JSON.parse(invalidBody.body).error.message, "请求失败");
|
||||
const capability = await prisma.capabilityInstallation.create({
|
||||
data: {
|
||||
brandId,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const { customerRequest, customerTokenKey } = require("../../utils/request");
|
||||
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
|
||||
const { openPage } = require("../../utils/navigation");
|
||||
|
||||
Page({
|
||||
data: { record: {}, presentation: {} },
|
||||
@@ -28,9 +29,9 @@ Page({
|
||||
}
|
||||
},
|
||||
viewRecords() {
|
||||
wx.redirectTo({ url: "/pages/records/index" });
|
||||
openPage("/pages/records/index");
|
||||
},
|
||||
home() {
|
||||
wx.navigateTo({ url: "/pages/index/index" });
|
||||
openPage("/pages/index/index");
|
||||
},
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
|
||||
const { openPage } = require("../../utils/navigation");
|
||||
Page({
|
||||
data: { item: null, loading: true, error: "", presentation: {} },
|
||||
onLoad(options) {
|
||||
@@ -17,6 +18,6 @@ Page({
|
||||
.catch((error) => this.setData({ loading: false, error: error.message }));
|
||||
},
|
||||
inquire() {
|
||||
wx.navigateTo({ url: "/pages/inquiry/index?offeringId=" + this.data.item.id });
|
||||
openPage("/pages/inquiry/index?offeringId=" + this.data.item.id);
|
||||
},
|
||||
});
|
||||
@@ -1,5 +1,6 @@
|
||||
const { customerRequest, customerTokenKey } = require("../../utils/request");
|
||||
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
|
||||
const { openPage } = require("../../utils/navigation");
|
||||
|
||||
const statusLabels = {
|
||||
new: "待处理",
|
||||
@@ -46,6 +47,6 @@ Page({
|
||||
});
|
||||
},
|
||||
inquire() {
|
||||
wx.navigateTo({ url: "/pages/inquiry/index" });
|
||||
openPage("/pages/inquiry/index");
|
||||
},
|
||||
});
|
||||
@@ -6,4 +6,5 @@ module.exports = {
|
||||
templateKey: "",
|
||||
templateVersion: "",
|
||||
runtimeContract: "1.0",
|
||||
tabPages: [],
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
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 };
|
||||
Reference in new issue
Block a user