feat: 让小程序消费运行时工作空间
This commit is contained in:
1 parent
53ee034db8
commit
c3df77e227
4 files changed
+45
-2
No files matched your search
@@ -0,0 +1,39 @@
|
||||
const { request } = require("./request");
|
||||
const fallback = require("./linjing-data");
|
||||
|
||||
function toOffering(item) {
|
||||
const config = item && item.config && typeof item.config === "object" ? item.config : {};
|
||||
return {
|
||||
...item,
|
||||
id: item.id,
|
||||
category: item.category || item.kind || "业务提供项",
|
||||
name: item.name,
|
||||
desc: item.summary || item.description || "",
|
||||
image: item.coverUrl || item.image || "",
|
||||
priceRange: item.priceText || "沟通报价",
|
||||
keywords: Array.isArray(config.keywords) ? config.keywords : [],
|
||||
};
|
||||
}
|
||||
|
||||
function loadWorkspace() {
|
||||
return request("/public/workspace").then((workspace) => {
|
||||
const brand = workspace && workspace.brand ? workspace.brand : fallback.brand;
|
||||
const offerings = Array.isArray(workspace && workspace.offerings)
|
||||
? workspace.offerings.map(toOffering)
|
||||
: fallback.offerings;
|
||||
return { ...workspace, brand, offerings, trustContent: fallback.trustContent };
|
||||
});
|
||||
}
|
||||
|
||||
function loadWorkspaceWithFallback() {
|
||||
return loadWorkspace().catch(() => ({
|
||||
schemaVersion: "static-fallback",
|
||||
brand: fallback.brand,
|
||||
offerings: fallback.offerings,
|
||||
trustContent: fallback.trustContent,
|
||||
modules: [],
|
||||
capabilities: [],
|
||||
}));
|
||||
}
|
||||
|
||||
module.exports = { loadWorkspaceWithFallback };
|
||||
Reference in new issue
Block a user