refactor: 退役运行时视觉模块并泛化模板门禁
This commit is contained in:
1 parent
25d1fe983c
commit
e2e2340bfe
56 files changed
+290
-1037
No files matched your search
@@ -1,115 +0,0 @@
|
||||
const CORE_MODULES = {
|
||||
brandHero: { key: "brand-hero", variants: ["architectural", "portrait", "editorial"] },
|
||||
founderCard: { key: "founder-card", variants: ["compact", "contact"] },
|
||||
trustProof: { key: "trust-proof", variants: ["stats", "manifesto", "timeline"] },
|
||||
offeringList: { key: "offering-list", variants: ["image-first", "editorial", "square-card"] },
|
||||
offeringDetail: {
|
||||
key: "offering-detail",
|
||||
variants: ["project-case", "product-spec", "service-process"],
|
||||
},
|
||||
inquiry: { key: "inquiry", variants: ["standard", "project-brief", "booking"] },
|
||||
records: { key: "records", variants: ["timeline", "list"] },
|
||||
profile: { key: "profile", variants: ["contact", "editorial"] },
|
||||
};
|
||||
|
||||
const FALLBACK_THEME = {
|
||||
colors: {
|
||||
background: "#F7F5F1",
|
||||
surface: "#FFFFFF",
|
||||
foreground: "#252525",
|
||||
muted: "#77736B",
|
||||
accent: "#8A6846",
|
||||
dark: "#202221",
|
||||
border: "#E6DED5",
|
||||
},
|
||||
radius: { card: "16rpx", control: "8rpx" },
|
||||
spacing: { page: "32rpx", section: "28rpx" },
|
||||
};
|
||||
|
||||
function resolveModule(module) {
|
||||
const aliases = {
|
||||
identity: "brand-hero",
|
||||
trust: "trust-proof",
|
||||
offering: "offering-list",
|
||||
inquiry: "inquiry",
|
||||
contact: "founder-card",
|
||||
};
|
||||
const type = aliases[module.type] || module.type;
|
||||
const known = Object.values(CORE_MODULES).find((entry) => entry.key === type);
|
||||
return {
|
||||
...module,
|
||||
type,
|
||||
variant: module.variant || (known ? known.variants[0] : "default"),
|
||||
supported: Boolean(known || type === "custom"),
|
||||
};
|
||||
}
|
||||
|
||||
const MANIFEST_TYPE_ALIASES = {
|
||||
"brand-identity": "founder-card",
|
||||
hero: "brand-hero",
|
||||
trust: "trust-proof",
|
||||
"inquiry-form": "inquiry",
|
||||
"success-summary": "success-summary",
|
||||
"records-list": "records",
|
||||
};
|
||||
|
||||
function resolveManifest(workspace) {
|
||||
const manifest = workspace && workspace.visualTemplateManifest;
|
||||
if (!manifest || !Array.isArray(manifest.pages)) return null;
|
||||
const pages = {};
|
||||
for (const page of manifest.pages) {
|
||||
pages[page.key] = {
|
||||
...page,
|
||||
modules: (page.modules || []).map((module) => ({
|
||||
...module,
|
||||
type: MANIFEST_TYPE_ALIASES[module.type] || module.type,
|
||||
variant: module.variant || "default",
|
||||
})),
|
||||
};
|
||||
}
|
||||
return { ...manifest, pages };
|
||||
}
|
||||
|
||||
function resolveRuntime(workspace) {
|
||||
const modules = Array.isArray(workspace && workspace.modules) ? workspace.modules : [];
|
||||
const manifest = resolveManifest(workspace);
|
||||
const manifestHome = manifest && manifest.pages.home?.modules;
|
||||
const manifestModules = manifestHome || [];
|
||||
const resolved = modules.map(resolveModule);
|
||||
const resolvedTypes = new Set(resolved.map((item) => item.type));
|
||||
for (const module of manifestModules) {
|
||||
if (!resolvedTypes.has(module.type)) {
|
||||
resolved.push(resolveModule(module));
|
||||
resolvedTypes.add(module.type);
|
||||
}
|
||||
}
|
||||
const home = manifestHome?.length
|
||||
? manifestHome.map((item) => item.type)
|
||||
: workspace && workspace.layout && Array.isArray(workspace.layout.home)
|
||||
? workspace.layout.home
|
||||
: resolved.map((item) => item.type);
|
||||
const moduleVariants = {};
|
||||
for (const item of manifestHome || []) moduleVariants[item.type] = item.variant;
|
||||
const navigation = Array.isArray(manifest?.navigation)
|
||||
? manifest.navigation.map((item) => ({
|
||||
...item,
|
||||
page:
|
||||
typeof item.page === "string" && manifest.entrypoints?.[item.page]
|
||||
? manifest.entrypoints[item.page]
|
||||
: item.page,
|
||||
}))
|
||||
: Array.isArray(workspace?.navigation)
|
||||
? workspace.navigation
|
||||
: [];
|
||||
return {
|
||||
theme: manifest?.tokens || (workspace && workspace.theme ? workspace.theme : FALLBACK_THEME),
|
||||
modules: resolved,
|
||||
layout: { home: home.filter((key) => resolved.some((item) => item.type === key)) },
|
||||
moduleVariants,
|
||||
navigation,
|
||||
visualManifest: manifest,
|
||||
capabilities: workspace && Array.isArray(workspace.capabilities) ? workspace.capabilities : [],
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { CORE_MODULES, FALLBACK_THEME, resolveManifest, resolveRuntime };
|
||||
@@ -1,5 +1,4 @@
|
||||
const { request } = require("./request");
|
||||
const { resolveRuntime } = require("./module-registry");
|
||||
|
||||
function toOffering(item) {
|
||||
const presentation =
|
||||
@@ -36,7 +35,6 @@ function normalizeWorkspace(workspace) {
|
||||
: {};
|
||||
return {
|
||||
...workspace,
|
||||
...resolveRuntime(workspace),
|
||||
brand,
|
||||
offerings,
|
||||
trustContent,
|
||||
|
||||
Reference in new issue
Block a user