66 lines
2.2 KiB
JavaScript
66 lines
2.2 KiB
JavaScript
const { request } = require("./request");
|
|
|
|
function toOffering(item) {
|
|
const presentation =
|
|
item && item.presentation && typeof item.presentation === "object" ? item.presentation : {};
|
|
const details =
|
|
presentation.details && typeof presentation.details === "object" ? presentation.details : {};
|
|
return {
|
|
...item,
|
|
...presentation,
|
|
id: item.id,
|
|
category: presentation.categoryLabel || "业务提供项",
|
|
name: item.name,
|
|
desc: item.summary || "",
|
|
image: presentation.heroImage || item.coverUrl || "",
|
|
priceRange: item.priceText || "沟通报价",
|
|
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
|
|
: {};
|
|
const trustItems = Array.isArray(workspace && workspace.trustItems)
|
|
? workspace.trustItems.map((item) => ({
|
|
...item,
|
|
lines: typeof item.content === "string" ? item.content.split(/\r?\n/).filter(Boolean) : [],
|
|
}))
|
|
: [];
|
|
return {
|
|
...workspace,
|
|
brand,
|
|
offerings,
|
|
trustContent,
|
|
trustItems,
|
|
plugins: Array.isArray(workspace.plugins) ? workspace.plugins : [],
|
|
};
|
|
}
|
|
|
|
function loadWorkspace() {
|
|
return request("/public/workspace").then((workspace) => {
|
|
if (workspace?.publication?.status !== "published") {
|
|
throw new Error("品牌尚未发布");
|
|
}
|
|
return normalizeWorkspace(workspace);
|
|
});
|
|
}
|
|
|
|
function loadWorkspaceWithFallback() {
|
|
return loadWorkspace();
|
|
}
|
|
|
|
module.exports = { loadWorkspaceWithFallback };
|