1
1
import React from 'react'
2
2
import { AtButton , AtCalendar } from 'taro-ui'
3
+ import dayjs from 'dayjs'
3
4
import { View } from '@tarojs/components'
4
5
import Taro from '@tarojs/taro'
5
6
import DocsHeader from '../../components/doc-header'
@@ -21,7 +22,8 @@ interface IndexState {
21
22
[ key : string ] : any
22
23
}
23
24
24
- export default class Index extends React . Component < { } , IndexState > {
25
+ interface IndexProps { }
26
+ export default class Index extends React . Component < IndexProps , IndexState > {
25
27
public config : Taro . PageConfig = {
26
28
navigationBarTitleText : 'Taro日历组件展示'
27
29
}
@@ -30,8 +32,8 @@ export default class Index extends React.Component<{}, IndexState> {
30
32
super ( props )
31
33
this . state = {
32
34
now : Date . now ( ) ,
33
- minDate : '2018/06/11' ,
34
- maxDate : '2020/12/12' ,
35
+ minDate : dayjs ( ) . startOf ( 'month' ) . format ( 'YYYY-MM-DD' ) ,
36
+ maxDate : dayjs ( ) . endOf ( 'month' ) . format ( 'YYYY-MM-DD' ) ,
35
37
multiCurentDate : {
36
38
start : Date . now ( )
37
39
} ,
@@ -86,14 +88,8 @@ export default class Index extends React.Component<{}, IndexState> {
86
88
}
87
89
88
90
public render ( ) : JSX . Element {
89
- const {
90
- now,
91
- minDate,
92
- maxDate,
93
- mark,
94
- multiCurentDate,
95
- validDates
96
- } = this . state
91
+ const { now, minDate, maxDate, mark, multiCurentDate, validDates } =
92
+ this . state
97
93
return (
98
94
< View className = 'page calendar-page' >
99
95
< DocsHeader title = 'Calendar 日历' />
@@ -211,6 +207,21 @@ export default class Index extends React.Component<{}, IndexState> {
211
207
< AtCalendar validDates = { validDates } />
212
208
</ View >
213
209
</ View >
210
+
211
+ < View className = 'panel' >
212
+ < View className = 'panel__title' > 禁用日期</ View >
213
+ < View className = 'panel__content' >
214
+ < AtCalendar
215
+ minDate = { minDate }
216
+ maxDate = { maxDate }
217
+ disabledDate = { ( currentDate : dayjs . Dayjs ) => {
218
+ // 禁用周末
219
+ const currentDayOfWeek = dayjs ( currentDate ) . day ( )
220
+ return [ 0 , 6 ] . includes ( currentDayOfWeek )
221
+ } }
222
+ />
223
+ </ View >
224
+ </ View >
214
225
</ View >
215
226
</ View >
216
227
)
0 commit comments