Calendar.js
5.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import React,{PropTypes} from 'react';
import calendarUtil from '../../utils/calendarUtil';
import { Button, Icon ,Badge} from 'antd';
import moment from 'moment';
import cx from 'classnames';
import s from './calendarLess.les';
const solarFestivalData = {
'd0101':'元旦节',
'd0214':'情人节',
'd0308':'妇女节',
'd0312':'植树节',
'd0401':'愚人节',
'd0501':'劳动节',
'd0504':'青年节',
'd0601':'儿童节',
'd0801':'建军节',
'd1001':'国庆节',
'd1224':'平安夜',
'd1225':'圣诞节'
};
class Calendar extends React.Component {
constructor (props, context) {
super(props, context);
this.preMonth=this.preMonth.bind(this);
this.nextMonth=this.nextMonth.bind(this);
}
static propTypes={
onChange: PropTypes.func,
choseDay:PropTypes.object
}
static defaultProps = {
current:moment(new Date()),
onChange:(choseDay)=>{
console.log(choseDay.format('YYYY-MM-DD'));
},
todoList:{}
}
componentDidMount() {
}
componentWillReceiveProps(nextProps){
}
clickDay(day){
this.props.onChange(moment(day.year+"-"+day.month+"-"+day.day));
}
preMonth(){
const {current} = this.props;
this.props.onChange(current.subtract(1, 'months'));
}
nextMonth(){
const {current} = this.props;
this.props.onChange(current.add(1,'months'));
}
render(){
const {current,todoList}=this.props;
const months=calendarUtil.getMonths(current.format('YYYY'),current.format('MM'));
const renderDayName=(day)=>{
if(day){
if(day.lunarFestival){
return day.lunarFestival;
}else if(day.solarFestival){
return day.solarFestival;
}else if(day.lunarDayName&&'初一'==day.lunarDayName){
return day.lunarMonthName;
}else{
return day.lunarDayName;
}
}else{
return "";
}
}
return(
<div>
<div></div>
<div>
<table className={cx(s.calendar_wrap,s.lg)}>
<thead>
<tr className={s.calendar_week_head}>
<td className={s.week_day}>日</td>
<td>一</td>
<td>二</td>
<td>三</td>
<td>四</td>
<td>五</td>
<td className={s.week_day}>六</td>
</tr>
</thead>
<tbody>
{months.map((week,i)=>{
return (
<tr key={i}>
{
week.map((day,j)=>{
let currentDay=false
if(current.format('M-D')==(day.month+"-"+day.day)){
currentDay=true
}
const state=todoList[""+day.year+day.month+day.day]
if(state&&state.color=='Warning'){
return (
<td className={day.week==0||day.week==6?s.week_day:null} key={j}>
<div className={cx("dayInfo-2Vtsl_0",s.week_day_td_wrap)}>
<Badge status="warning" style={{ backgroundColor: '#ffbf00',position: 'absolute',right:0}} >
<p onClick={this.clickDay.bind(this,day)} className={s.day_nmuber_wrap}>
<span className={cx(currentDay?s.current_day:null,s.day_wrap)}>{day&&day.day} </span>
</p>
</Badge>
<p className={cx(s.week_day_nongli_wrap)}>{renderDayName(day)}</p>
</div>
</td>
)
}else if(state&&state.color){
return (
<td className={day.week==0||day.week==6?s.week_day:null} key={j}>
<div className={cx("dayInfo-2Vtsl_0",s.week_day_td_wrap)}>
<Badge status="warning" style={{ backgroundColor: '#d9d9d9',position: 'absolute',right:0}} >
<p onClick={this.clickDay.bind(this,day)} className={s.day_nmuber_wrap}>
<span className={cx(currentDay?s.current_day:null,s.day_wrap)}>{day&&day.day} </span>
</p>
</Badge>
<p className={cx(s.week_day_nongli_wrap)}>{renderDayName(day)}</p>
</div>
</td>
)
}else{
return (
<td className={day.week==0||day.week==6?s.week_day:null} key={j}>
<div className={cx("dayInfo-2Vtsl_0",s.week_day_td_wrap)}>
<p onClick={this.clickDay.bind(this,day)} className={s.day_nmuber_wrap}>
<span className={cx(currentDay?s.current_day:null,s.day_wrap)}>{day&&day.day} </span>
</p>
<p className={cx(s.week_day_nongli_wrap)}>{renderDayName(day)}</p>
</div>
</td>
)
}
})
}
</tr>
)
})}
</tbody>
</table>
</div>{/*
<div className={s.bottom_wrap}>
<Button.Group size={'small'}>
<Button onClick={this.preMonth}>
<Icon type="left" />
</Button>
<Button onClick={this.nextMonth}>
<Icon type="right" />
</Button>
</Button.Group>
</div>*/}
</div>
);
}
}
export default Calendar;