From efbd5dd1d625efedc143d953a199b61ddcf6b7be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Fri, 20 Sep 2019 11:34:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96datepicker=E7=9A=84=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E9=80=9A=E8=AE=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/picker/date.wc | 63 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/src/picker/date.wc b/src/picker/date.wc index be089e6..d66c4ec 100644 --- a/src/picker/date.wc +++ b/src/picker/date.wc @@ -434,6 +434,58 @@ export default class DatePicker { }, 1500) } + // 修正日历日期渲染 + _fixedRenderDate() { + var { max, min, last } = this.props + + if (!last) { + this._updateValue(today) + last = this.props.last + } + if (max) { + if (last.year > max.year) { + last.year = max.year + last.month = max.month + last.day = max.day + } else if (max.year === last.year) { + if (last.month > max.month) { + last.month = max.month + } else if (last.month === max.month) { + if (last.day > max.day) { + last.day = max.day + } + } + } + } + if (min) { + if (last.year < min.year) { + last.year = min.year + last.month = min.month + last.day = min.day + } else if (last.year === min.year) { + if (last.month < min.month) { + last.month = min.month + } else if (last.month === min.month) { + if (last.day < max.day) { + last.day = min.day + } + } + } + } + + var _date = new Date(last.year, last.month, last.day) + this.props.calendar = { + year: _date.getFullYear(), + month: _date.getMonth(), + list: [] + } + + this._updateValue(_date) + this._renderCalendar() + + return _date + } + _updateValue(oDate, needUpdateStyle) { this.props.last = { year: oDate.getFullYear(), @@ -485,13 +537,7 @@ export default class DatePicker { this.__INPUT__.setAttribute('label', '') } - this.props.calendar = { - year: today.getFullYear(), - month: today.getMonth(), - list: [] - } - - this._renderCalendar() + this._fixedRenderDate() this._activeFn = bind(this.__INPUT__, 'click', ev => { if (this.props.disabled || this.props.readonly) { @@ -615,9 +661,10 @@ export default class DatePicker { month: tmp.getMonth(), day: tmp.getDate() } - this._renderCalendar() + this._fixedRenderDate() } } + this.removeAttribute(name) break