@@ -2,10 +2,12 @@ import { Search } from "@element-plus/icons-vue"
22import { css } from '@emotion/css'
33import { useState } from "@hooks"
44import Flex from "@pages/components/Flex"
5- import { getDatePickerIconSlots } from " @pages/element-ui/rtl"
5+ import { getDatePickerIconSlots } from ' @pages/element-ui/rtl'
66import { t } from "@side/locale"
7- import { ElDatePicker , ElInput , useNamespace } from "element-plus"
8- import { defineComponent , watch } from "vue"
7+ import { type DateCell , ElDatePicker , ElInput , useNamespace } from "element-plus"
8+ import { defineComponent , h } from "vue"
9+ import Cell from './Cell'
10+ import { useDatePicker } from './useDatePicker'
911
1012const useCalendarStyle = ( ) => {
1113 const inputNs = useNamespace ( 'input' )
@@ -48,13 +50,12 @@ type Props = {
4850}
4951
5052const _default = defineComponent < Props > ( props => {
51- const now = Date . now ( )
52-
5353 const [ query , setQuery ] = useState ( props . defaultQuery )
54- const [ date , setDate ] = useState ( props . defaultDate )
5554 const handleSearch = ( ) => props . onSearch ?.( query . value . trim ( ) , date . value )
56-
57- watch ( date , handleSearch )
55+ const {
56+ date, setDate, dataDates,
57+ disabledDate, onPanelChange,
58+ } = useDatePicker ( { onChange : handleSearch } )
5859
5960 const [ calendarCls , popoverCls ] = useCalendarStyle ( )
6061
@@ -72,15 +73,19 @@ const _default = defineComponent<Props>(props => {
7273 } }
7374 onKeydown = { kv => ( kv as KeyboardEvent ) . code === 'Enter' && handleSearch ( ) }
7475 />
75- < ElDatePicker
76- clearable = { false }
77- disabledDate = { ( date : Date ) => date . getTime ( ) > now }
78- modelValue = { date . value }
79- onUpdate :modelValue = { setDate }
80- class = { calendarCls }
81- popperClass = { popoverCls }
82- v-slots = { getDatePickerIconSlots ( ) }
83- />
76+ { /* The events of date picker is not compatible with typescript, so use h() to workaround */ }
77+ { h ( ElDatePicker , {
78+ clearable : false ,
79+ disabledDate,
80+ modelValue : date . value ,
81+ 'onUpdate:modelValue' : setDate ,
82+ class : calendarCls ,
83+ popperClass : popoverCls ,
84+ onPanelChange,
85+ } , {
86+ ...getDatePickerIconSlots ( ) ,
87+ default : ( cell : DateCell ) => < Cell cell = { cell } dataDates = { dataDates . value } /> ,
88+ } ) }
8489 </ Flex >
8590 )
8691} , { props : [ 'defaultDate' , 'defaultQuery' , 'onSearch' ] } )
0 commit comments