Files
novalon-website/src/lib/cms/mock-home.ts
T
张翔 49dbced0cb feat(assets): 更新 Logo 与图片资源,添加数据层服务模块
- 更新 logo.svg/logo-light.svg/logo-white.svg 品牌标识
- 新增 logo-calligraphy.svg 书法体 Logo 变体
- 新增新闻、二维码、微信业务等图片资源
- 删除旧版 JPEG 测试图片
- 新增 CMS 数据层服务模块 (admin-api, auth, cms, crypto, db)
- 新增 cases/cross-references/methodology/team 常量数据
- 新增 site-config 站点配置
2026-07-07 06:54:47 +08:00

240 lines
7.1 KiB
TypeScript

import type { ContentZone, ContentItem } from './types';
import { STATS } from '@/lib/constants/stats';
import { SERVICES } from '@/lib/constants/services';
import { getFeaturedCases } from '@/lib/constants/cases';
import { NEWS } from '@/lib/constants/news';
import { SOLUTIONS } from '@/lib/constants/solutions';
function createBaseItem(id: string, modelCode: string, title: string, slug: string, index: number): Omit<ContentItem, 'data'> {
return {
id,
modelId: modelCode,
modelCode,
title,
slug,
status: 'published',
version: 1,
sortOrder: index,
createdAt: '2024-01-01T00:00:00Z',
updatedAt: '2024-01-01T00:00:00Z',
publishedAt: '2024-01-01T00:00:00Z',
createdBy: 'system',
updatedBy: 'system',
};
}
function statToContentItem(stat: Record<string, unknown>, index: number): ContentItem {
return {
...createBaseItem(`stat-${index}`, 'stat-item', String(stat.label || ''), `stat-${index}`, index),
data: {
icon: stat.icon,
label: stat.label,
value: stat.value,
suffix: stat.suffix,
prefix: stat.prefix || '',
decimals: stat.decimals || 0,
description: stat.description || '',
trendValue: stat.trend || '',
trendDirection: typeof stat.trend === 'string' && stat.trend.startsWith('+') ? 'up' : 'down',
accentColor: stat.color || 'brand',
},
};
}
function serviceToContentItem(service: { id: string; title: string; description: string; icon?: string; overview?: string; features?: unknown[]; benefits?: unknown[] }, index: number): ContentItem {
return {
...createBaseItem(service.id, 'service', service.title, service.id, index),
data: {
description: service.description,
icon: service.icon,
overview: service.overview,
features: service.features || [],
benefits: service.benefits || [],
},
};
}
function caseStudyToContentItem(cs: { id: string; title: string; slug: string; client?: string; industry?: string; subtitle?: string; challenge?: string; result?: string; metrics?: unknown[]; color?: string; featured?: boolean }, index: number): ContentItem {
return {
...createBaseItem(cs.id, 'case-study', cs.title, cs.slug, index),
data: {
client: cs.client,
industry: cs.industry,
subtitle: cs.subtitle,
challenge: cs.challenge,
result: cs.result,
metrics: cs.metrics || [],
color: cs.color,
featured: cs.featured,
},
};
}
function newsToContentItem(news: { id: string; title: string; excerpt?: string; date?: string; category?: string; image?: string; content?: string }, index: number): ContentItem {
return {
...createBaseItem(news.id, 'news', news.title, news.id, index),
data: {
excerpt: news.excerpt,
date: news.date,
category: news.category,
image: news.image,
content: news.content,
},
};
}
function solutionToContentItem(solution: { id: string; title: string; description: string; icon?: string; industry?: string; overview?: string }, index: number): ContentItem {
return {
...createBaseItem(solution.id, 'solution', solution.title, solution.id, index),
data: {
description: solution.description,
icon: solution.icon,
industry: solution.industry || '',
overview: solution.overview || '',
},
};
}
export function getMockHomeHeroBanner(): ContentItem {
return {
...createBaseItem('hero-home-main', 'hero-banner', '企业数字化转型的可靠伙伴', 'hero-home-main', 0),
data: {
heading: '企业数字化转型的可靠伙伴',
subheading: '深耕企业数字化 10+ 年',
description: '从战略规划到落地实施,为成长型企业提供端到端的数字化解决方案。以务实的态度、专业的能力、长期的陪伴,帮助企业实现可持续增长。',
primaryCtaText: '了解解决方案',
primaryCtaLink: '/solutions',
secondaryCtaText: '联系我们',
secondaryCtaLink: '/contact',
theme: 'brand',
},
};
}
export function getMockHomeStatsZone(): ContentZone {
const statList = Array.isArray(STATS) ? STATS : (STATS as { stats?: unknown[] }).stats || [];
const items = statList.slice(0, 4).map((s, i) => statToContentItem(s as Record<string, unknown>, i));
return {
id: 'zone-home-stats',
code: 'home-stats',
name: '首页数据指标区',
zoneKey: 'home-stats',
pageCode: 'home',
allowedModels: ['stat-item'],
items: items.map((item, i) => ({
item,
itemId: item.id,
sortOrder: i,
variant: 'default',
})),
settings: {
layout: 'grid',
columns: 4,
gap: 'large',
},
};
}
export function getMockHomeServicesZone(): ContentZone {
const items = SERVICES.slice(0, 4).map((s, i) => serviceToContentItem(s, i));
return {
id: 'zone-home-services',
code: 'home-services',
name: '首页服务区',
zoneKey: 'home-services',
pageCode: 'home',
allowedModels: ['service'],
items: items.map((item, i) => ({
item,
itemId: item.id,
sortOrder: i,
variant: 'default',
})),
settings: {
layout: 'grid',
columns: 4,
gap: 'large',
},
};
}
export function getMockHomeCasesZone(): ContentZone {
const items = getFeaturedCases().slice(0, 3).map((cs, i) => caseStudyToContentItem(cs, i));
return {
id: 'zone-home-cases',
code: 'home-cases',
name: '首页案例区',
zoneKey: 'home-cases',
pageCode: 'home',
allowedModels: ['case-study'],
items: items.map((item, i) => ({
item,
itemId: item.id,
sortOrder: i,
variant: 'default',
})),
settings: {
layout: 'grid',
columns: 3,
gap: 'large',
},
};
}
export function getMockHomeNewsZone(): ContentZone {
const items = NEWS.slice(0, 3).map((n, i) => newsToContentItem(n, i));
return {
id: 'zone-home-news',
code: 'home-news',
name: '首页新闻区',
zoneKey: 'home-news',
pageCode: 'home',
allowedModels: ['news'],
items: items.map((item, i) => ({
item,
itemId: item.id,
sortOrder: i,
variant: 'default',
})),
settings: {
layout: 'grid',
columns: 3,
gap: 'large',
},
};
}
export function getMockHomeSolutionsZone(): ContentZone {
const items = SOLUTIONS.slice(0, 4).map((s, i) => solutionToContentItem(s, i));
return {
id: 'zone-home-solutions',
code: 'home-solutions',
name: '首页方案区',
zoneKey: 'home-solutions',
pageCode: 'home',
allowedModels: ['solution'],
items: items.map((item, i) => ({
item,
itemId: item.id,
sortOrder: i,
variant: 'default',
})),
settings: {
layout: 'grid',
columns: 4,
gap: 'large',
},
};
}
export function getMockContentZone(zoneKey: string, _page = 'home'): ContentZone | null {
const zones: Record<string, ContentZone> = {
'home-stats': getMockHomeStatsZone(),
'home-services': getMockHomeServicesZone(),
'home-cases': getMockHomeCasesZone(),
'home-news': getMockHomeNewsZone(),
'home-solutions': getMockHomeSolutionsZone(),
};
return zones[zoneKey] || null;
}