|
13 | 13 |
|
14 | 14 | <script lang="ts" setup>
|
15 | 15 | import dayjs from 'dayjs'
|
16 |
| -import { reactive, watch, ref, PropType } from 'vue' |
| 16 | +import { reactive, ref } from 'vue' |
17 | 17 |
|
18 | 18 | const emit = defineEmits(['update:startDate', 'update:endDate'])
|
19 | 19 |
|
20 |
| -const props = defineProps({ |
21 |
| - startDate: { |
22 |
| - type: String as PropType<string | undefined | null>, |
23 |
| - default: '', |
24 |
| - }, |
25 |
| - endDate: { |
26 |
| - type: String as PropType<string | undefined | null>, |
27 |
| - default: '', |
28 |
| - }, |
29 |
| -}) |
| 20 | +const startDate = defineModel('startDate', { default: '' }) |
| 21 | +const endDate = defineModel('endDate', { default: '' }) |
30 | 22 |
|
31 | 23 | const timeFormat = ref('YYYY-MM-DD').value
|
32 | 24 |
|
33 | 25 | const state = reactive({
|
34 |
| - dateRange: [props.startDate, props.endDate], |
| 26 | + dateRange: [startDate, endDate], |
35 | 27 | shortcuts: [
|
36 | 28 | {
|
37 | 29 | text: '最近一年',
|
@@ -93,40 +85,12 @@ const state = reactive({
|
93 | 85 | })
|
94 | 86 |
|
95 | 87 | const change = (value: any) => {
|
96 |
| - let start = '' |
97 |
| - let end = '' |
98 |
| -
|
99 |
| - if (value) { |
100 |
| - end = dayjs(value[1]).endOf('day').format(timeFormat) |
101 |
| - start = dayjs(value[0]).startOf('day').format(timeFormat) |
102 |
| -
|
103 |
| - state.dateRange[0] = start |
104 |
| - state.dateRange[1] = end |
| 88 | + if (value && value.length === 2) { |
| 89 | + startDate.value = value[0] |
| 90 | + endDate.value = value[1] |
| 91 | + } else { |
| 92 | + startDate.value = '' |
| 93 | + endDate.value = '' |
105 | 94 | }
|
106 |
| -
|
107 |
| - emit('update:startDate', start) |
108 |
| - emit('update:endDate', end) |
109 | 95 | }
|
110 |
| -
|
111 |
| -watch( |
112 |
| - () => props.startDate, |
113 |
| - async (newValue) => { |
114 |
| - if (newValue == '' || newValue == null) { |
115 |
| - state.dateRange = ['', ''] |
116 |
| - emit('update:startDate', '') |
117 |
| - emit('update:endDate', '') |
118 |
| - } else state.dateRange = [newValue, state.dateRange[1]] |
119 |
| - } |
120 |
| -) |
121 |
| -
|
122 |
| -watch( |
123 |
| - () => props.endDate, |
124 |
| - async (newValue) => { |
125 |
| - if (newValue == '' || newValue == null) { |
126 |
| - state.dateRange = ['', ''] |
127 |
| - emit('update:startDate', '') |
128 |
| - emit('update:endDate', '') |
129 |
| - } else state.dateRange = [state.dateRange[0], newValue] |
130 |
| - } |
131 |
| -) |
132 | 96 | </script>
|
0 commit comments