@@ -4,15 +4,20 @@ import dayjs, { Dayjs } from 'dayjs'
4
4
import _isFunction from 'lodash/isFunction'
5
5
import _isObject from 'lodash/isObject'
6
6
import _pick from 'lodash/pick'
7
+ import {
8
+ AtCalendarDefaultProps ,
9
+ AtCalendarProps ,
10
+ AtCalendarPropsWithDefaults ,
11
+ AtCalendarState ,
12
+ Calendar
13
+ } from 'types/calendar'
7
14
import { View } from '@tarojs/components'
8
15
import { BaseEvent } from '@tarojs/components/types/common'
9
16
import Taro from '@tarojs/taro'
10
17
import AtCalendarBody from './body/index'
11
18
import AtCalendarController from './controller/index'
12
- import { DefaultProps , Props , PropsWithDefaults , State } from './interface'
13
- import Calendar from './types'
14
19
15
- const defaultProps : DefaultProps = {
20
+ const defaultProps : AtCalendarDefaultProps = {
16
21
validDates : [ ] ,
17
22
marks : [ ] ,
18
23
isSwiper : true ,
@@ -25,18 +30,21 @@ const defaultProps: DefaultProps = {
25
30
monthFormat : 'YYYY年MM月'
26
31
}
27
32
28
- export default class AtCalendar extends Taro . Component < Props , Readonly < State > > {
29
- static defaultProps : DefaultProps = defaultProps
33
+ export default class AtCalendar extends Taro . Component <
34
+ AtCalendarProps ,
35
+ Readonly < AtCalendarState >
36
+ > {
37
+ static defaultProps : AtCalendarDefaultProps = defaultProps
30
38
31
- constructor ( props : Props ) {
39
+ constructor ( props : AtCalendarProps ) {
32
40
super ( props )
33
41
34
- const { currentDate, isMultiSelect } = props as PropsWithDefaults
42
+ const { currentDate, isMultiSelect } = props as AtCalendarPropsWithDefaults
35
43
36
44
this . state = this . getInitializeState ( currentDate , isMultiSelect )
37
45
}
38
46
39
- componentWillReceiveProps ( nextProps : Props ) {
47
+ componentWillReceiveProps ( nextProps : AtCalendarProps ) {
40
48
const { currentDate, isMultiSelect } = nextProps
41
49
if ( ! currentDate || currentDate === this . props . currentDate ) return
42
50
@@ -50,7 +58,7 @@ export default class AtCalendar extends Taro.Component<Props, Readonly<State>> {
50
58
}
51
59
}
52
60
53
- const stateValue : State = this . getInitializeState (
61
+ const stateValue : AtCalendarState = this . getInitializeState (
54
62
currentDate ,
55
63
isMultiSelect
56
64
)
@@ -61,10 +69,10 @@ export default class AtCalendar extends Taro.Component<Props, Readonly<State>> {
61
69
static options = { addGlobalClass : true }
62
70
63
71
@bind
64
- private getSingleSelectdState ( value : Dayjs ) : Partial < State > {
72
+ private getSingleSelectdState ( value : Dayjs ) : Partial < AtCalendarState > {
65
73
const { generateDate } = this . state
66
74
67
- const stateValue : Partial < State > = {
75
+ const stateValue : Partial < AtCalendarState > = {
68
76
selectedDate : this . getSelectedDate ( value . valueOf ( ) )
69
77
}
70
78
@@ -80,12 +88,14 @@ export default class AtCalendar extends Taro.Component<Props, Readonly<State>> {
80
88
}
81
89
82
90
@bind
83
- private getMultiSelectedState ( value : Dayjs ) : Pick < State , 'selectedDate' > {
91
+ private getMultiSelectedState (
92
+ value : Dayjs
93
+ ) : Pick < AtCalendarState , 'selectedDate' > {
84
94
const { selectedDate } = this . state
85
95
const { end, start } = selectedDate
86
96
87
97
const valueUnix : number = value . valueOf ( )
88
- const state : Pick < State , 'selectedDate' > = {
98
+ const state : Pick < AtCalendarState , 'selectedDate' > = {
89
99
selectedDate
90
100
}
91
101
@@ -115,7 +125,7 @@ export default class AtCalendar extends Taro.Component<Props, Readonly<State>> {
115
125
private getInitializeState (
116
126
currentDate : Calendar . DateArg | Calendar . SelectedDate ,
117
127
isMultiSelect ?: boolean
118
- ) : State {
128
+ ) : AtCalendarState {
119
129
let end : number
120
130
let start : number
121
131
let generateDateValue : number
@@ -235,15 +245,15 @@ export default class AtCalendar extends Taro.Component<Props, Readonly<State>> {
235
245
236
246
const dayjsDate : Dayjs = dayjs ( value )
237
247
238
- let stateValue : Partial < State > = { }
248
+ let stateValue : Partial < AtCalendarState > = { }
239
249
240
250
if ( isMultiSelect ) {
241
251
stateValue = this . getMultiSelectedState ( dayjsDate )
242
252
} else {
243
253
stateValue = this . getSingleSelectdState ( dayjsDate )
244
254
}
245
255
246
- this . setState ( stateValue as State , ( ) => {
256
+ this . setState ( stateValue as AtCalendarState , ( ) => {
247
257
this . handleSelectedDate ( )
248
258
} )
249
259
@@ -290,7 +300,7 @@ export default class AtCalendar extends Taro.Component<Props, Readonly<State>> {
290
300
isVertical,
291
301
monthFormat,
292
302
selectedDates
293
- } = this . props as PropsWithDefaults
303
+ } = this . props as AtCalendarPropsWithDefaults
294
304
295
305
return (
296
306
< View className = { classnames ( 'at-calendar' , className ) } >
0 commit comments