feat: 收口多品牌与模板构建基础
This commit is contained in:
1 parent
0425a1c672
commit
77224ea51f
317 files changed
+11290
-1158
No files matched your search
@@ -1,47 +1,59 @@
|
||||
const { request } = require("./request");
|
||||
const { getFallbackWorkspace } = require("./fallback-workspaces");
|
||||
const { resolveRuntime } = require("./module-registry");
|
||||
|
||||
function toOffering(item) {
|
||||
const config = item && item.config && typeof item.config === "object" ? item.config : {};
|
||||
const presentation =
|
||||
item && item.presentation && typeof item.presentation === "object" ? item.presentation : {};
|
||||
const details =
|
||||
presentation.details && typeof presentation.details === "object" ? presentation.details : {};
|
||||
return {
|
||||
...item,
|
||||
id: item.id,
|
||||
category: item.category || item.kind || "业务提供项",
|
||||
category: presentation.categoryLabel || "业务提供项",
|
||||
name: item.name,
|
||||
desc: item.summary || item.description || "",
|
||||
image: item.coverUrl || item.image || "",
|
||||
desc: item.summary || "",
|
||||
image: presentation.heroImage || item.coverUrl || "",
|
||||
priceRange: item.priceText || "沟通报价",
|
||||
keywords: Array.isArray(config.keywords) ? config.keywords : [],
|
||||
keywords: Array.isArray(presentation.keywords) ? presentation.keywords : [],
|
||||
details: {
|
||||
background: typeof details.background === "string" ? details.background : "",
|
||||
designConcept: typeof details.designConcept === "string" ? details.designConcept : "",
|
||||
crafts: Array.isArray(details.crafts) ? details.crafts : [],
|
||||
materialsList: Array.isArray(details.materialsList) ? details.materialsList : [],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeWorkspace(workspace) {
|
||||
const brand = workspace && workspace.brand ? workspace.brand : {};
|
||||
const offerings = Array.isArray(workspace && workspace.offerings)
|
||||
? workspace.offerings.map(toOffering)
|
||||
: [];
|
||||
const trustContent =
|
||||
workspace && workspace.trustPresentation && typeof workspace.trustPresentation === "object"
|
||||
? workspace.trustPresentation
|
||||
: {};
|
||||
return {
|
||||
...workspace,
|
||||
...resolveRuntime(workspace),
|
||||
brand,
|
||||
offerings,
|
||||
trustContent,
|
||||
plugins: Array.isArray(workspace.plugins) ? workspace.plugins : [],
|
||||
};
|
||||
}
|
||||
|
||||
function loadWorkspace() {
|
||||
return request("/public/workspace").then((workspace) => {
|
||||
const fallback = getFallbackWorkspace(
|
||||
workspace && workspace.template && workspace.template.key,
|
||||
);
|
||||
const brand = workspace && workspace.brand ? workspace.brand : fallback.brand;
|
||||
const offerings = Array.isArray(workspace && workspace.offerings)
|
||||
? workspace.offerings.map(toOffering)
|
||||
: fallback.offerings;
|
||||
const trustContent =
|
||||
Array.isArray(workspace && workspace.trustContent) && workspace.trustContent.length
|
||||
? workspace.trustContent
|
||||
: fallback.trustContent;
|
||||
return {
|
||||
...workspace,
|
||||
...resolveRuntime(workspace),
|
||||
brand,
|
||||
offerings,
|
||||
trustContent,
|
||||
plugins: Array.isArray(workspace.plugins) ? workspace.plugins : [],
|
||||
};
|
||||
if (workspace?.publication?.status !== "published") {
|
||||
throw new Error("品牌尚未发布");
|
||||
}
|
||||
return normalizeWorkspace(workspace);
|
||||
});
|
||||
}
|
||||
|
||||
function loadWorkspaceWithFallback() {
|
||||
return loadWorkspace().catch(() => getFallbackWorkspace("personal"));
|
||||
return loadWorkspace();
|
||||
}
|
||||
|
||||
module.exports = { loadWorkspaceWithFallback };
|
||||
Reference in new issue
Block a user