Skip to content

Commit 24309bd

Browse files
committed
patch release
1 parent a140dbf commit 24309bd

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

.changeset/selfish-dryers-wonder.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@casual-ui/vue": patch
3+
---
4+
5+
fix: date picker formatter ensure

packages/ui/src/components/form/date-picker/CDatePanel.vue

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script lang="ts">
2-
export type Formatter = (origin: Date | null, format: string) => string
2+
type Formatter = (origin: Date | null, format: string) => string
33
</script>
44
55
<script setup lang="ts">
66
import { computed, ref, toRefs } from 'vue'
7-
import dayjs from 'dayjs'
87
import { useMessage } from '../../../usable/useI18n'
8+
import defaultFormatter from './defaultFormatter'
99
1010
const props = withDefaults(defineProps<{
1111
year?: number
@@ -23,11 +23,7 @@ const props = withDefaults(defineProps<{
2323
dateRange: () => [null, null],
2424
formattedDateRange: () => ['', ''],
2525
format: 'YYYY-MM-DD',
26-
formatter: () => (d: Date | null, f: string) => {
27-
if (!d)
28-
return ''
29-
return dayjs(d).format(f)
30-
},
26+
formatter: defaultFormatter,
3127
range: false,
3228
})
3329
@@ -36,9 +32,11 @@ const emit = defineEmits<{
3632
(e: 'update:dateRange', dateRange: [Date | null, Date | null]): void
3733
}>()
3834
35+
const formatter = typeof props.formatter === 'function' ? props.formatter : defaultFormatter
36+
3937
const messages = useMessage()
4038
41-
const innerFormatter = (d: Date | null) => props.formatter(d, props.format)
39+
const innerFormatter = (d: Date | null) => formatter(d, props.format)
4240
/**
4341
* 比较两个日期是否相等
4442
*/

packages/ui/src/components/form/date-picker/CDatePicker.vue

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export type Unit = 'year' | 'month' | 'day'
33
</script>
44
55
<script setup lang="ts">
6-
import dayjs from 'dayjs'
76
import {
87
CDatePanel,
98
CDatePanelHeader,
@@ -21,6 +20,7 @@ import type { CSize } from '@casual-ui/types'
2120
import { matCalendarToday } from '@quasar/extras/material-icons/index'
2221
import useValidator from '../useValidator'
2322
import useUnit from './useUnit'
23+
import defaultFormatter from './defaultFormatter'
2424
2525
const props = withDefaults(defineProps<{
2626
/**
@@ -87,11 +87,7 @@ const props = withDefaults(defineProps<{
8787
unit?: Unit
8888
}>(), {
8989
format: 'YYYY-MM-DD',
90-
formatter: () => (d: Date | null, f: string) => {
91-
if (!d)
92-
return ''
93-
return dayjs(d).format(f)
94-
},
90+
formatter: defaultFormatter,
9591
hideOnSelect: true,
9692
formattedValue: '',
9793
dateRange: () => [null, null],
@@ -145,7 +141,9 @@ const emit = defineEmits<{
145141
(e: 'update:unit', newUnit: Unit): void
146142
}>()
147143
148-
const innerFormatter = (d: Date | null) => props.formatter(d, props.format)
144+
const formatter = typeof props.formatter === 'function' ? props.formatter : defaultFormatter
145+
146+
const innerFormatter = (d: Date | null) => formatter(d, props.format)
149147
150148
const { provideSize: size } = useInjectSize(props)
151149
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import dayjs from 'dayjs'
2+
const defaultFormatter = (d: Date | null, f: string) => {
3+
if (!d)
4+
return ''
5+
return dayjs(d).format(f)
6+
}
7+
8+
export default defaultFormatter

0 commit comments

Comments
 (0)