diff --git a/src/calendar/components/Month.js b/src/calendar/components/Month.js index 9a6508a00..d1d8cc45e 100644 --- a/src/calendar/components/Month.js +++ b/src/calendar/components/Month.js @@ -26,7 +26,6 @@ export default createComponent({ currentDate: [Date, Array], allowSameDay: Boolean, showSubtitle: Boolean, - realRowHeight: Number, showMonthTitle: Boolean, firstDayOfWeek: Number, }, @@ -66,15 +65,13 @@ export default createComponent({ return this.visible || !this.lazyRender; }, - monthStyle() { - if (!this.shouldRender) { - const padding = - Math.ceil((this.totalDay + this.offset) / 7) * this.realRowHeight; - - return { - paddingBottom: `${padding}px`, - }; + placeholders() { + const rows = []; + const count = Math.ceil((this.totalDay + this.offset) / 7); + for (let day = 1; day <= count; day++) { + rows.push({ type: 'placeholder' }); } + return rows; }, days() { @@ -104,23 +101,6 @@ export default createComponent({ }, }, - watch: { - shouldRender(value) { - if (value) { - this.$nextTick(() => { - if (this.$refs.day[0] && !this.realRowHeight) { - const { height } = this.$refs.day[0].getBoundingClientRect(); - this.$emit('update-height', height); - } - }); - } - }, - - realRowHeight() { - this.height = null; - }, - }, - methods: { getHeight() { if (!this.height) { @@ -238,6 +218,11 @@ export default createComponent({ height: this.rowHeightWithUnit, }; + if (type === 'placeholder') { + style.width = '100%'; + return style; + } + if (index === 0) { style.marginLeft = `${(100 * this.offset) / 7}%`; } @@ -266,22 +251,19 @@ export default createComponent({ }, genMark() { - if (this.showMark) { + if (this.showMark && this.shouldRender) { return
{this.date.getMonth() + 1}
; } }, genDays() { - if (this.shouldRender) { - return ( -
- {this.genMark()} - {this.days.map(this.genDay)} -
- ); - } - - return
; + const days = this.shouldRender ? this.days : this.placeholders; + return ( +
+ {this.genMark()} + {days.map(this.genDay)} +
+ ); }, genDay(item, index) { @@ -304,8 +286,6 @@ export default createComponent({ if (type === 'selected') { return (
+
{this.genTitle()} {this.genDays()}
diff --git a/src/calendar/index.js b/src/calendar/index.js index 6f6b7052d..36d16898d 100644 --- a/src/calendar/index.js +++ b/src/calendar/index.js @@ -112,7 +112,6 @@ export default createComponent({ return { subtitle: '', currentDate: this.getInitialDate(), - realRowHeight: 0, }; }, @@ -404,10 +403,6 @@ export default createComponent({ this.$emit('confirm', copyDates(this.currentDate)); }, - onUpdateHeight(height) { - this.realRowHeight = height; - }, - genMonth(date, index) { const showMonthTitle = index !== 0 || !this.showSubtitle; return ( @@ -426,11 +421,9 @@ export default createComponent({ currentDate={this.currentDate} showSubtitle={this.showSubtitle} allowSameDay={this.allowSameDay} - realRowHeight={this.realRowHeight} showMonthTitle={showMonthTitle} firstDayOfWeek={this.dayOffset} onClick={this.onClickDay} - onUpdate-height={this.onUpdateHeight} /> ); }, diff --git a/src/calendar/test/__snapshots__/demo.spec.js.snap b/src/calendar/test/__snapshots__/demo.spec.js.snap index b0a56dda3..6ac56d057 100644 --- a/src/calendar/test/__snapshots__/demo.spec.js.snap +++ b/src/calendar/test/__snapshots__/demo.spec.js.snap @@ -64,13 +64,13 @@ exports[`renders demo correctly 1`] = `
-
+
-
1
+
1
1
-
2
-
3
-
4
+
2
+
3
+
4
5
6
7
@@ -102,14 +102,14 @@ exports[`renders demo correctly 1`] = `
31
-
+
2012年2月
-
2
+
2
1
-
2
-
3
-
4
+
2
+
3
+
4
5
6
7
@@ -137,14 +137,14 @@ exports[`renders demo correctly 1`] = `
29
-
+
2012年3月
-
3
+
3
1
-
2
-
3
-
4
+
2
+
3
+
4
5
6
7
diff --git a/src/calendar/test/__snapshots__/index.spec.js.snap b/src/calendar/test/__snapshots__/index.spec.js.snap index b27a7f541..a45e76732 100644 --- a/src/calendar/test/__snapshots__/index.spec.js.snap +++ b/src/calendar/test/__snapshots__/index.spec.js.snap @@ -8,14 +8,14 @@ exports[`color prop when type is range 1`] = `
-
+
-
1
+
1
1
-
2
-
3
-
4
-
5
+
2
+
3
+
4
+
5
6
7
8
@@ -61,14 +61,14 @@ exports[`color prop when type is single 1`] = `
-
+
-
1
+
1
1
-
2
-
3
-
4
-
5
+
2
+
3
+
4
+
5
6
7
8
@@ -114,14 +114,14 @@ exports[`formatter prop 1`] = `
-
+
-
1
+
1
1
-
2
-
3
-
4
-
5
+
2
+
3
+
4
+
5
6
7
8
@@ -173,14 +173,14 @@ exports[`popup wrapper 2`] = `
-
+
-
1
+
1
1
-
2
-
3
-
4
-
5
+
2
+
3
+
4
+
5
6
7
8
@@ -228,9 +228,9 @@ exports[`row-height prop 1`] = `
-
+
-
1
+
1
1
2
3
@@ -281,14 +281,14 @@ exports[`title & footer slot 1`] = `
-
+
-
1
+
1
1
-
2
-
3
-
4
-
5
+
2
+
3
+
4
+
5
6
7
8