1
+ import { parserPixelToTime } from '@/utils/deal_data' ;
1
2
import React , { FC , useEffect , useRef } from 'react' ;
2
- import {
3
- AutoSizer , Grid ,
4
- GridCellRenderer ,
5
- OnScrollParams
6
- } from 'react-virtualized' ;
3
+ import { AutoSizer , Grid , GridCellRenderer , OnScrollParams } from 'react-virtualized' ;
7
4
import { CommonProp } from '../../interface/common_prop' ;
8
5
import { prefix } from '../../utils/deal_class_prefix' ;
9
6
import './time_area.less' ;
@@ -19,18 +16,7 @@ export type TimeAreaProps = CommonProp & {
19
16
} ;
20
17
21
18
/** 动画时间轴组件 */
22
- export const TimeArea : FC < TimeAreaProps > = ( {
23
- setCursor,
24
- hideCursor,
25
- scale,
26
- scaleWidth,
27
- scaleCount,
28
- scaleSplitCount,
29
- startLeft,
30
- scrollLeft,
31
- onScroll,
32
- getScaleRender,
33
- } ) => {
19
+ export const TimeArea : FC < TimeAreaProps > = ( { setCursor, hideCursor, scale, scaleWidth, scaleCount, scaleSplitCount, startLeft, scrollLeft, onClickTimeArea, getScaleRender } ) => {
34
20
const gridRef = useRef < Grid > ( ) ;
35
21
/** 是否显示细分刻度 */
36
22
const showUnit = scaleSplitCount > 0 ;
@@ -43,11 +29,7 @@ export const TimeArea: FC<TimeAreaProps> = ({
43
29
const item = ( showUnit ? columnIndex / scaleSplitCount : columnIndex ) * scale ;
44
30
return (
45
31
< div key = { key } style = { style } className = { prefix ( ...classNames ) } >
46
- { isShowScale && (
47
- < div className = { prefix ( 'time-unit-scale' ) } >
48
- { getScaleRender ? getScaleRender ( item ) : item }
49
- </ div >
50
- ) }
32
+ { isShowScale && < div className = { prefix ( 'time-unit-scale' ) } > { getScaleRender ? getScaleRender ( item ) : item } </ div > }
51
33
</ div >
52
34
) ;
53
35
} ;
@@ -74,9 +56,7 @@ export const TimeArea: FC<TimeAreaProps> = ({
74
56
< >
75
57
< Grid
76
58
ref = { gridRef }
77
- columnCount = {
78
- showUnit ? scaleCount * scaleSplitCount : scaleCount
79
- }
59
+ columnCount = { showUnit ? scaleCount * scaleSplitCount : scaleCount }
80
60
columnWidth = { getColumnWidth }
81
61
rowCount = { 1 }
82
62
rowHeight = { height }
@@ -91,11 +71,13 @@ export const TimeArea: FC<TimeAreaProps> = ({
91
71
style = { { width, height } }
92
72
onClick = { ( e ) => {
93
73
if ( hideCursor ) return ;
94
- const rect = (
95
- e . currentTarget as HTMLElement
96
- ) . getBoundingClientRect ( ) ;
74
+ const rect = ( e . currentTarget as HTMLElement ) . getBoundingClientRect ( ) ;
97
75
const position = e . clientX - rect . x ;
98
- setCursor ( { left : Math . max ( position + scrollLeft , startLeft ) } ) ;
76
+
77
+ const time = parserPixelToTime ( Math . max ( position + scrollLeft , startLeft ) , { startLeft, scale, scaleWidth } ) ;
78
+ const result = onClickTimeArea && onClickTimeArea ( time , e ) ;
79
+ if ( result === false ) return ; // 返回false时阻止设置时间
80
+ setCursor ( { time } ) ;
99
81
} }
100
82
className = { prefix ( 'time-area-interact' ) }
101
83
> </ div >
0 commit comments