v1.3.0 - add Annual/Quarter/Hourly timeline views
This commit is contained in:
@@ -9,4 +9,5 @@ export interface ToolbarConfig {
|
||||
showTheme?: boolean
|
||||
showFullscreen?: boolean
|
||||
showTimeScale?: boolean // 显示时间刻度按钮组
|
||||
timeScaleDimensions?: ('hour' | 'day' | 'week' | 'month' | 'year')[] // 设置时间刻度按钮的展示维度
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* 时间轴数据类型兼容性定义
|
||||
* 用于处理现有代码的类型兼容问题
|
||||
*/
|
||||
|
||||
// 简化的通用时间轴数据类型,用于向下兼容
|
||||
export type LegacyTimelineData = Array<Record<string, any>>
|
||||
|
||||
// 类型守卫函数
|
||||
export function isTimelineMonth(item: any): item is Record<string, any> {
|
||||
return item && typeof item === 'object' && 'year' in item && 'month' in item
|
||||
}
|
||||
|
||||
export function isTimelineYear(item: any): item is Record<string, any> {
|
||||
return item && typeof item === 'object' && 'year' in item && 'yearLabel' in item
|
||||
}
|
||||
|
||||
export function isTimelineDay(item: any): item is Record<string, any> {
|
||||
return item && typeof item === 'object' && 'year' in item && 'day' in item
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/**
|
||||
* 时间轴数据类型定义
|
||||
* 统一管理所有时间轴相关的数据结构
|
||||
*/
|
||||
|
||||
// 基础时间单位接口
|
||||
export interface TimelineHour {
|
||||
hour: number
|
||||
label: string
|
||||
shortLabel?: string
|
||||
hourLabel?: string
|
||||
date?: Date
|
||||
isToday?: boolean
|
||||
isWorkingHour?: boolean
|
||||
isWeekend?: boolean
|
||||
}
|
||||
|
||||
export interface TimelineDay {
|
||||
year: number
|
||||
month: number
|
||||
day: number
|
||||
date: Date
|
||||
dateLabel: string
|
||||
label?: string
|
||||
dayOfWeek?: number
|
||||
isToday?: boolean
|
||||
isWeekend?: boolean
|
||||
hours?: TimelineHour[]
|
||||
hourOffset?: number
|
||||
}
|
||||
|
||||
export interface TimelineWeek {
|
||||
label: string
|
||||
startDate: Date
|
||||
endDate: Date
|
||||
weekStart?: Date
|
||||
weekEnd?: Date
|
||||
weekNumber?: number
|
||||
isToday?: boolean
|
||||
belongsToYear?: number
|
||||
belongsToMonth?: number
|
||||
subDays?: Array<{
|
||||
date: Date
|
||||
dayOfWeek?: number
|
||||
}>
|
||||
}
|
||||
|
||||
export interface TimelineMonth {
|
||||
year: number
|
||||
month: number
|
||||
startDate: Date
|
||||
endDate: Date
|
||||
monthLabel?: string
|
||||
yearMonthLabel?: string
|
||||
isToday?: boolean
|
||||
|
||||
// 月视图相关
|
||||
isMonthView?: boolean
|
||||
monthData?: {
|
||||
dayCount: number
|
||||
monthLabel?: string
|
||||
isToday?: boolean
|
||||
}
|
||||
|
||||
// 周视图相关
|
||||
isWeekView?: boolean
|
||||
weeks?: Array<{
|
||||
weekStart: Date
|
||||
weekEnd: Date
|
||||
subDays: Array<{
|
||||
date: Date
|
||||
dayOfWeek?: number
|
||||
}>
|
||||
}>
|
||||
|
||||
// 日视图相关
|
||||
days?: Array<{
|
||||
day: number
|
||||
date: Date
|
||||
label: string
|
||||
isToday: boolean
|
||||
isWeekend: boolean
|
||||
}>
|
||||
|
||||
subDays?: Array<{
|
||||
date: Date
|
||||
dayOfWeek?: number
|
||||
}>
|
||||
|
||||
// 调试信息
|
||||
_debugInfo?: Record<string, unknown>
|
||||
}
|
||||
|
||||
export interface TimelineQuarter {
|
||||
quarter: number
|
||||
label?: string
|
||||
fullLabel?: string
|
||||
quarterLabel: string
|
||||
startDate: Date
|
||||
endDate: Date
|
||||
isToday?: boolean
|
||||
year?: number
|
||||
}
|
||||
|
||||
export interface TimelineYear {
|
||||
year: number
|
||||
yearLabel: string
|
||||
startDate: Date
|
||||
endDate: Date
|
||||
isToday?: boolean
|
||||
quarters?: TimelineQuarter[]
|
||||
halfYears?: Array<{
|
||||
startDate: Date
|
||||
endDate: Date
|
||||
label: string
|
||||
}>
|
||||
}
|
||||
|
||||
// 联合类型,支持不同时间尺度的数据
|
||||
export type TimelineData = TimelineMonth[] | TimelineYear[] | TimelineDay[]
|
||||
|
||||
// 时间轴数据项类型(用于模板中的泛型推断)
|
||||
export type TimelineDataItem = TimelineMonth | TimelineYear | TimelineDay
|
||||
|
||||
// 缓存键类型
|
||||
export interface TimelineCacheKey {
|
||||
startDate: string
|
||||
endDate: string
|
||||
scale: string
|
||||
workingHours: string
|
||||
}
|
||||
@@ -1,13 +1,16 @@
|
||||
// 时间轴比例类型定义
|
||||
|
||||
// 使用字符串字面量类型代替enum,兼容erasableSyntaxOnly
|
||||
export type TimelineScale = 'day' | 'week' | 'month'
|
||||
export type TimelineScale = 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year'
|
||||
|
||||
// 导出常量值以便于使用
|
||||
export const TimelineScale = {
|
||||
HOUR: 'hour' as TimelineScale, // 小时视图 - 每列显示一小时
|
||||
DAY: 'day' as TimelineScale, // 日视图 - 每列显示一天
|
||||
WEEK: 'week' as TimelineScale, // 周视图 - 每列显示一周
|
||||
MONTH: 'month' as TimelineScale, // 月视图 - 每列显示一个月
|
||||
QUARTER: 'quarter' as TimelineScale, // 季度视图 - 每列显示一个季度
|
||||
YEAR: 'year' as TimelineScale, // 年视图 - 每列显示一年
|
||||
}
|
||||
|
||||
export interface TimelineScaleConfig {
|
||||
@@ -22,6 +25,12 @@ export interface TimelineScaleConfig {
|
||||
|
||||
// 预设配置
|
||||
export const SCALE_CONFIGS = {
|
||||
hour: {
|
||||
scale: TimelineScale.HOUR,
|
||||
cellWidth: 40,
|
||||
headerLevels: 2,
|
||||
formatters: { primary: 'yyyy年MM月dd日', secondary: 'HH:mm' },
|
||||
},
|
||||
day: {
|
||||
scale: TimelineScale.DAY,
|
||||
cellWidth: 30,
|
||||
@@ -40,6 +49,12 @@ export const SCALE_CONFIGS = {
|
||||
headerLevels: 2,
|
||||
formatters: { primary: 'yyyy年', secondary: 'MM月' },
|
||||
},
|
||||
year: {
|
||||
scale: TimelineScale.YEAR,
|
||||
cellWidth: 360,
|
||||
headerLevels: 2,
|
||||
formatters: { primary: 'yyyy年', secondary: '上半年|下半年' },
|
||||
},
|
||||
} as Record<TimelineScale, TimelineScaleConfig>
|
||||
|
||||
// 时间单元数据接口
|
||||
@@ -72,4 +87,16 @@ export interface TimelineData {
|
||||
endDate: Date
|
||||
units: TimelineUnit[]
|
||||
}>
|
||||
years?: Array<{
|
||||
year: number
|
||||
startDate: Date
|
||||
endDate: Date
|
||||
halfYears: Array<{
|
||||
label: string
|
||||
startDate: Date
|
||||
endDate: Date
|
||||
width: number
|
||||
}>
|
||||
width: number
|
||||
}>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user