-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] Calendar 日历上添加月份,年份切换功能 #11228
Comments
your can try this: <script setup lang="tsx">
import dayjs from 'dayjs'
import type { Calendar } from 'vant'
import { computed, reactive, ref, useAttrs, useSlots } from 'vue'
const ATTRS = useAttrs<typeof Calendar>()
const DATA = reactive({
quickJumpShow: false,
})
const needQuickJump = computed(() => {
const min = ATTRS['min-date']
const max = ATTRS['max-date']
return max && min && dayjs(max).diff(min, 'month') >= 2
})
const SLOTS = {
subtitle: ({ text }) => <>
{ text }{ needQuickJump.value && <van-icon name="play" /> }
</>,
...useSlots(),
}
function Render({ render, data }) {
return render?.(data)
}
const calenderRef = ref<typeof Calendar>()
function scrollToDate([year, month]: [string?, string?] = []) {
if (year && month)
calenderRef.value?.scrollToDate(new Date(+year, +month - 1, 1)) // month: 0-11
}
</script>
<template>
<van-calendar
ref="calenderRef"
v-bind="ATTRS"
:teleport="ATTRS.teleport || 'body'"
@click-subtitle="(e) => {
DATA.quickJumpShow = true
ATTRS.onClickSubtitle?.(e)
}"
>
<template v-for="slot, key in SLOTS" :key="key" #[key]="slotProp">
<Render :render="slot" :data="slotProp" />
</template>
</van-calendar>
<van-popup
v-if="needQuickJump"
v-model:show="DATA.quickJumpShow"
position="bottom"
:teleport="ATTRS.teleport || 'body'"
>
<van-date-picker
title="跳转年月"
:model-value="[]"
:min-date="ATTRS['min-date']"
:max-date="ATTRS['max-date']"
:columns-type="['year', 'month']"
@confirm="({ selectedValues }) => {
DATA.quickJumpShow = false
scrollToDate(selectedValues)
}"
@cancel="() => {
DATA.quickJumpShow = false
}"
/>
</van-popup>
</template> |
@chenjiahan 要支持这个功能的话,对外提供的 api 名称有什么参考的吗 |
@inottn 可以考虑新增一个 switch-mode 属性:
|
这种方案还是存在一个问题,比如我需要选中一个比较早的时间,我按年切换的话,还是需要按非常多次上一年。这种体验不太好。 我的另外一种方案是,点击日历副标题的时候,弹出一个年月选择器,用户选择之后则调用scrollToDate,滚动到指定日期。 如果考虑这种方案的话 我可以实现一下,提个PR。 |
|
关于你说的缺少 '<<' '>>' icon问题,已和设计师沟通,预计最快会在下周增加,具体进度我会继续跟进 |
nice! |
@inottn 两个icon已经增加啦~ |
2024 年了,强烈要求增加一个 可以切换年月的的功能,如 uniapp 的 Calendar,就可以接受,期望官方大大赶紧实现呀 |
这个功能解决了什么问题?
遇到跨年多的场景,用户滑动起来很麻烦
你期望的 API 是什么样子的?
null
The text was updated successfully, but these errors were encountered: