Skip to content

Commit d14bd84

Browse files
committed
fix: 移动 AtCalendar 的类型声明 close #968
1 parent f8938c2 commit d14bd84

File tree

11 files changed

+277
-249
lines changed

11 files changed

+277
-249
lines changed

src/components/calendar/body/index.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@ import classnames from 'classnames'
33
import dayjs from 'dayjs'
44
import _chunk from 'lodash/chunk'
55
import _throttle from 'lodash/throttle'
6+
import {
7+
AtCalendarBodyListGroup,
8+
AtCalendarBodyProps,
9+
AtCalendarBodyState,
10+
Calendar
11+
} from 'types/calendar'
612
import { Swiper, SwiperItem, View } from '@tarojs/components'
713
import { BaseEvent, ITouch, ITouchEvent } from '@tarojs/components/types/common'
814
import Taro from '@tarojs/taro'
915
import { delayQuerySelector } from '../../../common/utils'
1016
import generateCalendarGroup from '../common/helper'
11-
import Calendar from '../types'
1217
import AtCalendarDateList from '../ui/date-list/index'
1318
import AtCalendarDayList from '../ui/day-list/index'
14-
import { ListGroup, Props, State } from './interface'
1519

1620
const ANIMTE_DURATION: number = 300
1721

18-
const defaultProps: Partial<Props> = {
22+
const defaultProps: Partial<AtCalendarBodyProps> = {
1923
marks: [],
2024
selectedDate: {
2125
end: Date.now(),
@@ -26,12 +30,12 @@ const defaultProps: Partial<Props> = {
2630
}
2731

2832
export default class AtCalendarBody extends Taro.Component<
29-
Props,
30-
Readonly<State>
33+
AtCalendarBodyProps,
34+
Readonly<AtCalendarBodyState>
3135
> {
32-
static defaultProps: Partial<Props> = defaultProps
36+
static defaultProps: Partial<AtCalendarBodyProps> = defaultProps
3337

34-
constructor(props: Props) {
38+
constructor(props: AtCalendarBodyProps) {
3539
super(props)
3640
const {
3741
validDates,
@@ -67,7 +71,7 @@ export default class AtCalendarBody extends Taro.Component<
6771
})
6872
}
6973

70-
componentWillReceiveProps(nextProps: Props) {
74+
componentWillReceiveProps(nextProps: AtCalendarBodyProps) {
7175
const {
7276
validDates,
7377
marks,
@@ -115,9 +119,9 @@ export default class AtCalendarBody extends Taro.Component<
115119
private getGroups(
116120
generateDate: number,
117121
selectedDate: Calendar.SelectedDate
118-
): ListGroup {
122+
): AtCalendarBodyListGroup {
119123
const dayjsDate = dayjs(generateDate)
120-
const arr: ListGroup = []
124+
const arr: AtCalendarBodyListGroup = []
121125
const preList: Calendar.ListInfo<Calendar.Item> = this.generateFunc(
122126
dayjsDate.subtract(1, 'month').valueOf(),
123127
selectedDate

src/components/calendar/body/interface.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/components/calendar/common/helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import dayjs, { Dayjs } from 'dayjs'
22
import _flow from 'lodash/flow'
3-
import Calendar from '../types'
3+
import { Calendar } from 'types/calendar'
44
import * as constant from './constant'
55
import plugins from './plugins'
66

src/components/calendar/common/plugins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import dayjs from 'dayjs'
22
import _isEmpty from 'lodash/isEmpty'
3-
import Calendar from '../types'
3+
import { Calendar } from 'types/calendar'
44

55
interface PluginArg {
66
options: Calendar.GroupOptions

src/components/calendar/controller/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import classnames from 'classnames'
22
import dayjs, { Dayjs } from 'dayjs'
3+
import {
4+
AtCalendarControllerProps,
5+
AtCalendarControllerState
6+
} from 'types/calendar'
37
import { Picker, Text, View } from '@tarojs/components'
48
import Taro from '@tarojs/taro'
5-
import { Props, State } from './interface'
69

7-
export default class AtCalendarController extends Taro.Component<Props, State> {
10+
export default class AtCalendarController extends Taro.Component<
11+
AtCalendarControllerProps,
12+
AtCalendarControllerState
13+
> {
814
static options = { addGlobalClass: true }
915

1016
render() {

src/components/calendar/controller/interface.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/components/calendar/index.tsx

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@ import dayjs, { Dayjs } from 'dayjs'
44
import _isFunction from 'lodash/isFunction'
55
import _isObject from 'lodash/isObject'
66
import _pick from 'lodash/pick'
7+
import {
8+
AtCalendarDefaultProps,
9+
AtCalendarProps,
10+
AtCalendarPropsWithDefaults,
11+
AtCalendarState,
12+
Calendar
13+
} from 'types/calendar'
714
import { View } from '@tarojs/components'
815
import { BaseEvent } from '@tarojs/components/types/common'
916
import Taro from '@tarojs/taro'
1017
import AtCalendarBody from './body/index'
1118
import AtCalendarController from './controller/index'
12-
import { DefaultProps, Props, PropsWithDefaults, State } from './interface'
13-
import Calendar from './types'
1419

15-
const defaultProps: DefaultProps = {
20+
const defaultProps: AtCalendarDefaultProps = {
1621
validDates: [],
1722
marks: [],
1823
isSwiper: true,
@@ -25,18 +30,21 @@ const defaultProps: DefaultProps = {
2530
monthFormat: 'YYYY年MM月'
2631
}
2732

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
3038

31-
constructor(props: Props) {
39+
constructor(props: AtCalendarProps) {
3240
super(props)
3341

34-
const { currentDate, isMultiSelect } = props as PropsWithDefaults
42+
const { currentDate, isMultiSelect } = props as AtCalendarPropsWithDefaults
3543

3644
this.state = this.getInitializeState(currentDate, isMultiSelect)
3745
}
3846

39-
componentWillReceiveProps(nextProps: Props) {
47+
componentWillReceiveProps(nextProps: AtCalendarProps) {
4048
const { currentDate, isMultiSelect } = nextProps
4149
if (!currentDate || currentDate === this.props.currentDate) return
4250

@@ -50,7 +58,7 @@ export default class AtCalendar extends Taro.Component<Props, Readonly<State>> {
5058
}
5159
}
5260

53-
const stateValue: State = this.getInitializeState(
61+
const stateValue: AtCalendarState = this.getInitializeState(
5462
currentDate,
5563
isMultiSelect
5664
)
@@ -61,10 +69,10 @@ export default class AtCalendar extends Taro.Component<Props, Readonly<State>> {
6169
static options = { addGlobalClass: true }
6270

6371
@bind
64-
private getSingleSelectdState(value: Dayjs): Partial<State> {
72+
private getSingleSelectdState(value: Dayjs): Partial<AtCalendarState> {
6573
const { generateDate } = this.state
6674

67-
const stateValue: Partial<State> = {
75+
const stateValue: Partial<AtCalendarState> = {
6876
selectedDate: this.getSelectedDate(value.valueOf())
6977
}
7078

@@ -80,12 +88,14 @@ export default class AtCalendar extends Taro.Component<Props, Readonly<State>> {
8088
}
8189

8290
@bind
83-
private getMultiSelectedState(value: Dayjs): Pick<State, 'selectedDate'> {
91+
private getMultiSelectedState(
92+
value: Dayjs
93+
): Pick<AtCalendarState, 'selectedDate'> {
8494
const { selectedDate } = this.state
8595
const { end, start } = selectedDate
8696

8797
const valueUnix: number = value.valueOf()
88-
const state: Pick<State, 'selectedDate'> = {
98+
const state: Pick<AtCalendarState, 'selectedDate'> = {
8999
selectedDate
90100
}
91101

@@ -115,7 +125,7 @@ export default class AtCalendar extends Taro.Component<Props, Readonly<State>> {
115125
private getInitializeState(
116126
currentDate: Calendar.DateArg | Calendar.SelectedDate,
117127
isMultiSelect?: boolean
118-
): State {
128+
): AtCalendarState {
119129
let end: number
120130
let start: number
121131
let generateDateValue: number
@@ -235,15 +245,15 @@ export default class AtCalendar extends Taro.Component<Props, Readonly<State>> {
235245

236246
const dayjsDate: Dayjs = dayjs(value)
237247

238-
let stateValue: Partial<State> = {}
248+
let stateValue: Partial<AtCalendarState> = {}
239249

240250
if (isMultiSelect) {
241251
stateValue = this.getMultiSelectedState(dayjsDate)
242252
} else {
243253
stateValue = this.getSingleSelectdState(dayjsDate)
244254
}
245255

246-
this.setState(stateValue as State, () => {
256+
this.setState(stateValue as AtCalendarState, () => {
247257
this.handleSelectedDate()
248258
})
249259

@@ -290,7 +300,7 @@ export default class AtCalendar extends Taro.Component<Props, Readonly<State>> {
290300
isVertical,
291301
monthFormat,
292302
selectedDates
293-
} = this.props as PropsWithDefaults
303+
} = this.props as AtCalendarPropsWithDefaults
294304

295305
return (
296306
<View className={classnames('at-calendar', className)}>

src/components/calendar/interface.ts

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)