Browse Source

增加上一个月与下一月逻辑,动态改变tags

胡耀汉 8 years ago
parent
commit
8077919167
3 changed files with 30 additions and 4 deletions
  1. 2 2
      react/assets/app.bundle.js
  2. 4 0
      react/components/Calendar.js
  3. 24 2
      react/entry/app.js

File diff suppressed because it is too large
+ 2 - 2
react/assets/app.bundle.js


+ 4 - 0
react/components/Calendar.js

@@ -158,6 +158,8 @@ const Calendar = React.createClass({
             select_day : select_day,
             date_num_array : date_num_array,
             first_day : first_day
+        }, () => {
+            this.props.onPreviousMonth(select_year, select_month + 1);
         })
     },
 
@@ -191,6 +193,8 @@ const Calendar = React.createClass({
             select_day : select_day,
             date_num_array : date_num_array,
             first_day : first_day
+        }, () => {
+            this.props.onNextMonth(select_year, select_month + 1);
         })
     },
 

+ 24 - 2
react/entry/app.js

@@ -10,12 +10,34 @@ import ReactDOM from 'react-dom';
 import Calendar from '../components/Calendar';
 
 const App = React.createClass({
+
+    getInitialState() {
+        return {
+            tags : [5, 21]
+        }
+    },
+
     selectDate(year, month, day) {
-        alert("当前日期为:" + year + '年' + month + '月' + day + '日' );
+        console.log("选择时间为:" + year + '年' + month + '月' + day + '日' );
+    },
+    previousMonth(year, month) {
+        console.log("当前日期为:" + year + '年' + month + '月');
+        this.setState({tags : [7, 11]});
+    },
+    nextMonth(year, month) {
+        console.log("当前日期为:" + year + '年' + month + '月');
+        this.setState({tags : [8, 23]});
     },
     render() {
         return (
-            <Calendar onSelectDate={this.selectDate} year="2016" month="8" day="7" tags={[5, 21]} />
+            <Calendar
+                onSelectDate={this.selectDate}
+                onPreviousMonth={this.previousMonth}
+                onNextMonth={this.nextMonth}
+                year="2016"
+                month="8"
+                day="7"
+                tags={this.state.tags} />
         );
     }
 });