- 新增客片案例全流程功能,包含前台页面、管理端配置、后端API、数据库迁移与文档 - 新增团队共创详情页面与对应接口 - 重构玩法模块:将静态playData替换为动态API获取,拆分类型定义到playTypes.ts - 优化vite构建配置与环境变量处理,调整详情页操作栏文案 - 更新全量相关文档与配图,新增客片案例、团队共创API文档 - 新增测试用例,完善数据归一化逻辑 - 调整路由配置与环境变量示例文件
128 lines
3.5 KiB
Python
128 lines
3.5 KiB
Python
from datetime import datetime
|
|
from sqlalchemy.inspection import inspect
|
|
|
|
|
|
def encode_value(value):
|
|
if isinstance(value, datetime):
|
|
return value.isoformat()
|
|
if isinstance(value, list):
|
|
return [encode_value(item) for item in value]
|
|
if isinstance(value, dict):
|
|
return {key: encode_value(item) for key, item in value.items()}
|
|
return value
|
|
|
|
|
|
def model_dict(instance, include: dict[str, object] | None = None) -> dict:
|
|
data = {column.key: encode_value(getattr(instance, column.key)) for column in inspect(instance).mapper.column_attrs}
|
|
if include:
|
|
for key, value in include.items():
|
|
data[key] = encode_value(value)
|
|
return data
|
|
|
|
|
|
def lead_dict(lead) -> dict:
|
|
return model_dict(
|
|
lead,
|
|
{"assignedUser": {"id": lead.assignedUser.id, "name": lead.assignedUser.name} if lead.assignedUser else None},
|
|
)
|
|
|
|
|
|
def public_wanfa_route_dict(route) -> dict:
|
|
return {
|
|
"id": route.id,
|
|
"title": route.title,
|
|
"subtitle": route.subtitle,
|
|
"image": route.image,
|
|
"routeCount": route.routeCount,
|
|
"demandKeyword": route.demandKeyword,
|
|
}
|
|
|
|
|
|
def public_wanfa_category_dict(category) -> dict:
|
|
return {
|
|
"id": category.id,
|
|
"label": category.label,
|
|
"routes": [public_wanfa_route_dict(route) for route in category.routes],
|
|
}
|
|
|
|
|
|
def public_home_wanfa_recommendation_dict(item) -> dict:
|
|
return {
|
|
"id": item.id,
|
|
"categoryId": item.category.id,
|
|
"label": item.category.label,
|
|
"routes": [public_wanfa_route_dict(route) for route in item.category.routes],
|
|
}
|
|
|
|
|
|
def concierge_advisor_dict(advisor) -> dict:
|
|
return model_dict(advisor)
|
|
|
|
|
|
def public_concierge_advisor_dict(advisor) -> dict:
|
|
return {
|
|
"avatar": advisor.avatar,
|
|
"name": advisor.name,
|
|
"role": advisor.role,
|
|
"details": advisor.details or [],
|
|
"qrImage": advisor.qrImage,
|
|
}
|
|
|
|
|
|
def public_home_experience_dict(item) -> dict:
|
|
return {
|
|
"id": item.id,
|
|
"badge": item.badge,
|
|
"category": item.category,
|
|
"title": item.title,
|
|
"englishTitle": item.englishTitle,
|
|
"image": item.image,
|
|
"demandKeyword": item.demandKeyword,
|
|
}
|
|
|
|
|
|
def public_home_team_building_dict(item) -> dict:
|
|
return {
|
|
"id": item.id,
|
|
"tag": item.tag,
|
|
"title": item.title,
|
|
"description": item.description,
|
|
"image": item.image,
|
|
"demandKeyword": item.demandKeyword,
|
|
}
|
|
|
|
|
|
def public_home_team_building_detail_dict(item) -> dict:
|
|
paragraphs = [
|
|
paragraph.strip()
|
|
for paragraph in (getattr(item, "detailParagraphs", None) or [])
|
|
if isinstance(paragraph, str) and paragraph.strip()
|
|
]
|
|
if not paragraphs:
|
|
paragraphs = [item.description]
|
|
return {
|
|
**public_home_team_building_dict(item),
|
|
"detailSubtitle": (getattr(item, "detailSubtitle", None) or item.description).strip(),
|
|
"detailParagraphs": paragraphs,
|
|
}
|
|
|
|
|
|
def public_home_wild_archive_dict(item) -> dict:
|
|
return {
|
|
"id": item.id,
|
|
"title": item.title,
|
|
"image": item.image,
|
|
"demandKeyword": item.demandKeyword,
|
|
"photoCount": len(item.images or [item.image]),
|
|
}
|
|
|
|
|
|
def public_home_wild_archive_detail_dict(item) -> dict:
|
|
images = [image for image in (item.images or []) if isinstance(image, str) and image.strip()]
|
|
if not images:
|
|
images = [item.image]
|
|
return {
|
|
**public_home_wild_archive_dict(item),
|
|
"images": images,
|
|
}
|