feat: 建立小程序品牌运行时上下文

This commit is contained in:
que01 committed 2026-09-23 13:31:08 +08:00
1 parent dcb40f629b
commit f7fe6d6b20
6 files changed
+51 -1

No files matched your search

+3
View File
@@ -7,4 +7,7 @@ module.exports = {
get brand() {
return app.globalData.brand || {};
},
get brandSlug() {
return app.globalData.brandSlug || "default-brand";
},
};
+8 -1
View File
@@ -1,9 +1,16 @@
const config = require("./config");
function withBrandContext(path, options) {
if (options.includeBrand === false || !path.startsWith("/public/")) return path;
const separator = path.includes("?") ? "&" : "?";
return path + separator + "brandSlug=" + encodeURIComponent(config.brandSlug);
}
function request(path, options = {}) {
return new Promise((resolve, reject) => {
const requestPath = withBrandContext(path, options);
wx.request({
url: config.apiBaseUrl + path,
url: config.apiBaseUrl + requestPath,
method: options.method || "GET",
header: { accept: "application/json", ...(options.header || {}) },
...(options.data === undefined ? {} : { data: options.data }),