Skip to content

Commit 5fb9542

Browse files
perf: ⚡ 优化Calendar日历选择器打开关闭时的动画效果
1 parent 3746ba3 commit 5fb9542

File tree

3 files changed

+11
-23
lines changed

3 files changed

+11
-23
lines changed

src/uni_modules/wot-design-uni/components/wd-calendar-view/monthPanel/month-panel.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default {
6060
</script>
6161

6262
<script lang="ts" setup>
63-
import { computed, onMounted, ref, watch } from 'vue'
63+
import { computed, onBeforeMount, ref, watch } from 'vue'
6464
import { debounce, isArray, isEqual, isNumber, requestAnimationFrame } from '../../common/util'
6565
import { compareMonth, formatMonthTitle, getMonthEndDay, getMonths, getTimeData, getWeekLabel } from '../utils'
6666
import Month from '../month/month.vue'
@@ -136,7 +136,7 @@ watch(
136136
}
137137
)
138138
139-
onMounted(() => {
139+
onBeforeMount(() => {
140140
scrollIntoView()
141141
})
142142

src/uni_modules/wot-design-uni/components/wd-calendar-view/yearPanel/year-panel.vue

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ export default {
3131
</script>
3232

3333
<script lang="ts" setup>
34-
import { computed, onMounted, ref, nextTick } from 'vue'
34+
import { computed, ref, onBeforeMount } from 'vue'
3535
import { compareYear, formatYearTitle, getYears } from '../utils'
36-
import { isArray, isNumber } from '../../common/util'
36+
import { isArray, isNumber, requestAnimationFrame } from '../../common/util'
3737
import Year from '../year/year.vue'
3838
import { yearPanelProps, type YearInfo, type YearPanelExpose } from './types'
3939
@@ -62,25 +62,12 @@ const years = computed(() => {
6262
6363
const emit = defineEmits(['change'])
6464
65-
onMounted(() => {
65+
onBeforeMount(() => {
6666
scrollIntoView()
6767
})
6868
69-
const requestAnimationFrame = (cb = () => {}) => {
70-
return new Promise((resolve, reject) => {
71-
uni
72-
.createSelectorQuery()
73-
.selectViewport()
74-
.boundingClientRect()
75-
.exec(() => {
76-
resolve(true)
77-
cb()
78-
})
79-
})
80-
}
81-
8269
function scrollIntoView() {
83-
requestAnimationFrame().then(() => {
70+
requestAnimationFrame(() => {
8471
let activeDate: number | null = null
8572
if (isArray(props.value)) {
8673
activeDate = props.value![0]
@@ -102,7 +89,7 @@ function scrollIntoView() {
10289
top += yearsInfo[index] ? Number(yearsInfo[index].height) : 0
10390
}
10491
scrollTop.value = 0
105-
nextTick(() => {
92+
requestAnimationFrame(() => {
10693
scrollTop.value = top
10794
})
10895
})

src/uni_modules/wot-design-uni/components/wd-calendar/wd-calendar.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export default {
117117
<script lang="ts" setup>
118118
import { ref, computed, watch } from 'vue'
119119
import { dayjs } from '../common/dayjs'
120-
import { deepClone, isArray, isEqual, padZero } from '../common/util'
120+
import { deepClone, isArray, isEqual, padZero, requestAnimationFrame } from '../common/util'
121121
import { getWeekNumber, isRange } from '../wd-calendar-view/utils'
122122
import { useCell } from '../composables/useCell'
123123
import { FORM_KEY, type FormItemRule } from '../wd-form/types'
@@ -319,7 +319,9 @@ function open() {
319319
lastCalendarValue.value = deepClone(calendarValue.value)
320320
lastTab.value = currentTab.value
321321
lastCurrentType.value = currentType.value
322-
scrollIntoView()
322+
requestAnimationFrame(() => {
323+
scrollIntoView()
324+
})
323325
324326
setTimeout(() => {
325327
if (props.showTypeSwitch) {
@@ -331,7 +333,6 @@ function open() {
331333
// 对外暴露方法
332334
function close() {
333335
pickerShow.value = false
334-
scrollIntoView()
335336
setTimeout(() => {
336337
calendarValue.value = deepClone(lastCalendarValue.value)
337338
currentTab.value = lastTab.value

0 commit comments

Comments
 (0)