refactor: 按模板隔离小程序 fallback 数据
This commit is contained in:
1 parent
bfa24d48d0
commit
b525c4d29a
2 files changed
+36
-10
No files matched your search
@@ -0,0 +1,31 @@
|
||||
const doorFallback = require("./linjing-data");
|
||||
|
||||
const base = (name, tagline) => ({
|
||||
schemaVersion: "fallback-1.0",
|
||||
brand: {
|
||||
id: "fallback",
|
||||
name,
|
||||
tagline,
|
||||
description: "以专业经验建立长期信任。",
|
||||
contactPhone: "",
|
||||
contactWechat: "",
|
||||
},
|
||||
offerings: [],
|
||||
trustContent: [],
|
||||
fields: [],
|
||||
modules: [],
|
||||
capabilities: [],
|
||||
theme: {},
|
||||
});
|
||||
|
||||
const fallbacks = {
|
||||
doors: { ...doorFallback, schemaVersion: "fallback-doors-1.0", template: { key: "doors" } },
|
||||
food: base("个人品牌", "私房菜与定制服务"),
|
||||
personal: base("个人品牌", "专业经验与可信赖的合作方式"),
|
||||
};
|
||||
|
||||
function getFallbackWorkspace(templateKey) {
|
||||
return fallbacks[templateKey] || fallbacks.personal;
|
||||
}
|
||||
|
||||
module.exports = { getFallbackWorkspace };
|
||||
@@ -1,5 +1,5 @@
|
||||
const { request } = require("./request");
|
||||
const fallback = require("./linjing-data");
|
||||
const { getFallbackWorkspace } = require("./fallback-workspaces");
|
||||
const { resolveRuntime } = require("./module-registry");
|
||||
|
||||
function toOffering(item) {
|
||||
@@ -18,6 +18,9 @@ function toOffering(item) {
|
||||
|
||||
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)
|
||||
@@ -38,15 +41,7 @@ function loadWorkspace() {
|
||||
}
|
||||
|
||||
function loadWorkspaceWithFallback() {
|
||||
return loadWorkspace().catch(() => ({
|
||||
schemaVersion: "static-fallback",
|
||||
brand: fallback.brand,
|
||||
offerings: fallback.offerings,
|
||||
trustContent: fallback.trustContent,
|
||||
capabilities: [],
|
||||
theme: resolveRuntime({}).theme,
|
||||
modules: [],
|
||||
}));
|
||||
return loadWorkspace().catch(() => getFallbackWorkspace("personal"));
|
||||
}
|
||||
|
||||
module.exports = { loadWorkspaceWithFallback };
|
||||
Reference in new issue
Block a user