Sanakey
2021-01-31 53cc6f817625897935fb10c3845ad7be400f3036
src/vant-weapp/calendar/index.js
@@ -11,6 +11,7 @@
  getDayByOffset,
} from './utils';
import Toast from '../toast/toast';
import { requestAnimationFrame } from '../common/utils';
VantComponent({
  props: {
    title: {
@@ -34,7 +35,7 @@
    },
    rangePrompt: String,
    defaultDate: {
      type: [Number, Array],
      type: null,
      observer(val) {
        this.setData({ currentDate: val });
        this.scrollIntoView();
@@ -64,7 +65,7 @@
      value: 'bottom',
    },
    rowHeight: {
      type: [Number, String],
      type: null,
      value: ROW_HEIGHT,
    },
    round: {
@@ -100,7 +101,7 @@
      value: true,
    },
    maxRange: {
      type: [Number, String],
      type: null,
      value: null,
    },
  },
@@ -152,12 +153,12 @@
        ];
      }
      if (type === 'multiple') {
        return [defaultDate || minDate];
        return defaultDate || [minDate];
      }
      return defaultDate || minDate;
    },
    scrollIntoView() {
      setTimeout(() => {
      requestAnimationFrame(() => {
        const {
          currentDate,
          type,
@@ -166,6 +167,7 @@
          minDate,
          maxDate,
        } = this.data;
        // @ts-ignore
        const targetDate = type === 'single' ? currentDate : currentDate[0];
        const displayed = show || !poppable;
        if (!targetDate || !displayed) {
@@ -179,7 +181,7 @@
          }
          return false;
        });
      }, 100);
      });
    },
    onOpen() {
      this.$emit('open');
@@ -197,6 +199,7 @@
      const { date } = event.detail;
      const { type, currentDate, allowSameDay } = this.data;
      if (type === 'range') {
        // @ts-ignore
        const [startDay, endDay] = currentDate;
        if (startDay && !endDay) {
          const compareToStart = compareDay(date, startDay);
@@ -212,6 +215,7 @@
        }
      } else if (type === 'multiple') {
        let selectedIndex;
        // @ts-ignore
        const selected = currentDate.some((dateItem, index) => {
          const equal = compareDay(dateItem, date) === 0;
          if (equal) {
@@ -220,10 +224,12 @@
          return equal;
        });
        if (selected) {
          // @ts-ignore
          const cancelDate = currentDate.splice(selectedIndex, 1);
          this.setData({ currentDate });
          this.unselect(cancelDate);
        } else {
          // @ts-ignore
          this.select([...currentDate, date]);
        }
      } else {
@@ -276,10 +282,14 @@
      return true;
    },
    onConfirm() {
      if (this.data.type === 'range' && !this.checkRange()) {
      if (
        this.data.type === 'range' &&
        !this.checkRange(this.data.currentDate)
      ) {
        return;
      }
      wx.nextTick(() => {
        // @ts-ignore
        this.$emit('confirm', copyDates(this.data.currentDate));
      });
    },