Skip to content

Commit 43a5da6

Browse files
authored
feat: ✨Calendar日历添加open事件 (#627)
Closes: #624
1 parent a82529c commit 43a5da6

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

docs/component/calendar.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ function handleConfirm4({ value }) {
417417
| confirm | 绑定值变化时触发 | `{ value }` | - |
418418
| change | 点击面板日期时触发 | `{ value }` | - |
419419
| cancel | 点击关闭按钮或者蒙层时触发 | -|-|
420+
| open | 日历打开时触发 | -|-|
420421

421422
## Methods
422423

src/pages/calendar/Index.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,20 @@
4444
</wd-calendar>
4545
</view>
4646
</demo-block>
47+
<demo-block transparent title="open事件">
48+
<wd-calendar v-model="value17" @open="handleOpen" />
49+
</demo-block>
4750
</page-wraper>
51+
<wd-message-box />
4852
</template>
4953
<script lang="ts" setup>
5054
import { useToast } from '@/uni_modules/wot-design-uni'
5155
import { dayjs } from '@/uni_modules/wot-design-uni'
5256
import type { CalendarDayItem, CalendarFormatter } from '@/uni_modules/wot-design-uni/components/wd-calendar-view/types'
5357
import type { CalendarOnShortcutsClickOption } from '@/uni_modules/wot-design-uni/components/wd-calendar/types'
5458
import { ref } from 'vue'
59+
import { useMessage } from '@/uni_modules/wot-design-uni'
60+
const message = useMessage()
5561
5662
const minDate = ref<number>(new Date(new Date().getFullYear() - 20, new Date().getMonth() - 6, new Date().getDate()).getTime())
5763
@@ -71,7 +77,7 @@ const value13 = ref<number[]>([Date.now() - 24 * 60 * 60 * 1000 * 3, Date.now()]
7177
const value14 = ref<number | null>(null)
7278
const value15 = ref<number | null>(null)
7379
const value16 = ref<number>(Date.now())
74-
80+
const value17 = ref<number>(Date.now())
7581
const formatValue = ref<string>('')
7682
const formatter: CalendarFormatter = (day: CalendarDayItem) => {
7783
const date = new Date(day.date)
@@ -165,5 +171,8 @@ function handleConfirm4({ value }: any) {
165171
console.log(new Date(value).toString())
166172
formatValue.value = new Date(value).toString()
167173
}
174+
function handleOpen() {
175+
message.alert('打开日历')
176+
}
168177
</script>
169178
<style lang="scss" scoped></style>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ const formatRange = (value: number, rangeType: 'start' | 'end', type: CalendarTy
205205
}
206206
207207
const props = defineProps(calendarProps)
208-
const emit = defineEmits(['cancel', 'change', 'update:modelValue', 'confirm'])
208+
const emit = defineEmits(['cancel', 'change', 'update:modelValue', 'confirm', 'open'])
209209
210210
const pickerShow = ref<boolean>(false)
211211
const calendarValue = ref<null | number | number[]>(null)
@@ -333,6 +333,7 @@ function open() {
333333
calendarTabs.value.updateLineStyle(false)
334334
}
335335
}, 250)
336+
emit('open')
336337
}
337338
// 对外暴露方法
338339
function close() {
@@ -349,7 +350,6 @@ function handleTypeChange({ index }: { index: number }) {
349350
const tabs = ['date', 'week', 'month']
350351
const rangeTabs = ['daterange', 'weekrange', 'monthrange']
351352
const type = props.type.indexOf('range') > -1 ? rangeTabs[index] : tabs[index]
352-
353353
currentTab.value = index
354354
currentType.value = type as CalendarType
355355
}

0 commit comments

Comments
 (0)