From 1b97315b5448241b1f262f7950fbf47720f4ecb6 Mon Sep 17 00:00:00 2001 From: neverland Date: Sun, 18 Oct 2020 19:50:34 +0800 Subject: [PATCH] fix(Calendar): does not show current month with larger screen sizes (#7355) * fix(Calendar): does not show current month with larger screen sizes * chore: fix demo snapshot --- src/calendar/index.js | 27 ++++++++------ .../test/__snapshots__/demo.spec.js.snap | 35 ++++++++++++++++++- 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/src/calendar/index.js b/src/calendar/index.js index 5fc0c1ec4..6f6b7052d 100644 --- a/src/calendar/index.js +++ b/src/calendar/index.js @@ -266,28 +266,33 @@ export default createComponent({ let height = 0; let currentMonth; - let visibleIndex; + const visibleRange = [-1, -1]; for (let i = 0; i < months.length; i++) { const visible = height <= bottom && height + heights[i] >= top; - if (visible && !currentMonth) { - visibleIndex = i; - currentMonth = months[i]; - } + if (visible) { + visibleRange[1] = i; - if (!months[i].visible && visible) { - this.$emit('month-show', { - date: months[i].date, - title: months[i].title, - }); + if (!currentMonth) { + currentMonth = months[i]; + visibleRange[0] = i; + } + + if (!months[i].visible) { + this.$emit('month-show', { + date: months[i].date, + title: months[i].title, + }); + } } height += heights[i]; } months.forEach((month, index) => { - month.visible = index >= visibleIndex - 1 && index <= visibleIndex + 1; + month.visible = + index >= visibleRange[0] - 1 && index <= visibleRange[1] + 1; }); /* istanbul ignore else */ diff --git a/src/calendar/test/__snapshots__/demo.spec.js.snap b/src/calendar/test/__snapshots__/demo.spec.js.snap index 74018afa8..b0a56dda3 100644 --- a/src/calendar/test/__snapshots__/demo.spec.js.snap +++ b/src/calendar/test/__snapshots__/demo.spec.js.snap @@ -139,7 +139,40 @@ exports[`renders demo correctly 1`] = `
2012年3月
-
+
+
3
+
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+