2025-08-28 09:20:15 +08:00
|
|
|
from typing import Literal
|
|
|
|
|
|
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
|
|
|
|
from ..core.base import RenderableComponent
|
|
|
|
|
|
|
|
|
|
__all__ = ["Timeline", "TimelineItem"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TimelineItem(BaseModel):
|
|
|
|
|
"""时间轴中的单个事件点。"""
|
|
|
|
|
|
|
|
|
|
timestamp: str = Field(..., description="显示在时间点旁边的时间或标签")
|
2025-09-11 10:31:49 +08:00
|
|
|
"""显示在时间点旁边的时间或标签"""
|
2025-08-28 09:20:15 +08:00
|
|
|
title: str = Field(..., description="事件的标题")
|
2025-09-11 10:31:49 +08:00
|
|
|
"""事件的标题"""
|
2025-08-28 09:20:15 +08:00
|
|
|
content: str = Field(..., description="事件的详细描述")
|
2025-09-11 10:31:49 +08:00
|
|
|
"""事件的详细描述"""
|
2025-08-28 09:20:15 +08:00
|
|
|
icon: str | None = Field(default=None, description="可选的自定义图标SVG路径")
|
2025-09-11 10:31:49 +08:00
|
|
|
"""可选的自定义图标SVG路径"""
|
2025-08-28 09:20:15 +08:00
|
|
|
color: str | None = Field(default=None, description="可选的自定义颜色,覆盖默认")
|
2025-09-11 10:31:49 +08:00
|
|
|
"""可选的自定义颜色,覆盖默认"""
|
2025-08-28 09:20:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class Timeline(RenderableComponent):
|
|
|
|
|
"""一个垂直时间轴组件,用于按顺序展示事件。"""
|
|
|
|
|
|
|
|
|
|
component_type: Literal["timeline"] = "timeline"
|
|
|
|
|
items: list[TimelineItem] = Field(
|
|
|
|
|
default_factory=list, description="时间轴项目列表"
|
|
|
|
|
)
|
2025-09-11 10:31:49 +08:00
|
|
|
"""时间轴项目列表"""
|
2025-08-28 09:20:15 +08:00
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def template_name(self) -> str:
|
|
|
|
|
return "components/widgets/timeline"
|