Kaynağa Gözat

日历组件bug修复

dev01 1 yıl önce
ebeveyn
işleme
008cb5823a

+ 3 - 4
src/components/common/xx-calendar/xx-calendar.js

@@ -9,8 +9,8 @@ Component({
       type: Array,
       value: [],
       observer(v) {
-
         let nowMonthDays = this.data.nowMonthDays
+        // let sel = this.data.dateSel.replace(/\-/g, "/")
         if (v.length > 0) {
           v.forEach(el => {
             let ele = el.dates.replace(/\-/g, "/")
@@ -24,7 +24,6 @@ Component({
         this.setData({
           nowMonthDays
         })
-
       }
     },
     year: {
@@ -108,14 +107,14 @@ Component({
     getNowMonthDays(year, month) {
       let {
         nowMonth,
-        nowDay
+        nowDay,
       } = this.data
       let nowMonthDays = []
       let days = this.getThisMonthDays(year, month); //获取当月的天数
       for (let i = 1; i <= days; i++) {
         let d = new Date(year, month - 1, i)
         let years = d.getFullYear()
-        let months = d.getMonth() + 1
+        let months = (d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1)
         let day2 = d.getDate() < 10 ? '0' + d.getDate() : d.getDate()
         let time = `${years + '/' + months + '/' + day2}` // 2022/3/3
         let timer = time.replace(/\//g, "-")

+ 18 - 6
src/pages/punchClock/punchClocks.jsx

@@ -51,6 +51,11 @@ class PunchClocks extends Component {
       clockId: "",
       dateList: [],
       isCalendar: true,
+
+      year: new Date().getFullYear(),
+      month: new Date().getMonth() + 1,
+      day: new Date().getDate(),
+
     }
     this.onChange = this.onChange.bind(this);
     this.publicReleaseClockIn = this.publicReleaseClockIn.bind(this);
@@ -204,6 +209,9 @@ class PunchClocks extends Component {
     this.imagePickerRef && this.imagePickerRef.clear();
     this.setState({
       dateSel: dayjs().format('YYYY-MM-DD'),
+      year: new Date().getFullYear(),
+      month: new Date().getMonth() + 1,
+      day: new Date().getDate(),
       duration: "",
       selectorChecked: {},
       remark: "",
@@ -220,8 +228,12 @@ class PunchClocks extends Component {
 
   onSelectDate(val) {
     let data = val.detail;
+    let date = dayjs(data)
     this.setState({
-      dateSel: data
+      dateSel: data,
+      year: date.year(),
+      month: date.month() + 1,
+      day: date.date(),
     }, () => {
       this.onmyDuration()
     })
@@ -233,7 +245,7 @@ class PunchClocks extends Component {
   }
 
   render() {
-    const { data, dateList } = this.state;
+    const { data, dateList, year, month, day } = this.state;
     return (
       <View className='punchClock'>
         <View className='header'>
@@ -302,10 +314,10 @@ class PunchClocks extends Component {
                     this.state.isCalendar &&
                     <calendar
                       use_date_arr={dateList}
-                      year={new Date().getFullYear()}
-                      month={new Date().getMonth() + 1}
-                      nowMonth={new Date().getMonth() + 1}
-                      nowDay={new Date().getDate()}
+                      year={year}
+                      month={month}
+                      nowMonth={month}
+                      nowDay={day}
                       onselectdate={(v) => {
                         this.onSelectDate(v)
                       }}