Skip to content

Commit f47d96f

Browse files
committed
修复日期控件赋值再清空查询会提示Invalid Date异常问题
1 parent 98bbbd0 commit f47d96f

File tree

1 file changed

+10
-46
lines changed
  • ui/zhontai.ui.admin.vue3/src/components/my-date-range

1 file changed

+10
-46
lines changed

ui/zhontai.ui.admin.vue3/src/components/my-date-range/index.vue

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,17 @@
1313

1414
<script lang="ts" setup>
1515
import dayjs from 'dayjs'
16-
import { reactive, watch, ref, PropType } from 'vue'
16+
import { reactive, ref } from 'vue'
1717
1818
const emit = defineEmits(['update:startDate', 'update:endDate'])
1919
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: '' })
3022
3123
const timeFormat = ref('YYYY-MM-DD').value
3224
3325
const state = reactive({
34-
dateRange: [props.startDate, props.endDate],
26+
dateRange: [startDate, endDate],
3527
shortcuts: [
3628
{
3729
text: '最近一年',
@@ -93,40 +85,12 @@ const state = reactive({
9385
})
9486
9587
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 = ''
10594
}
106-
107-
emit('update:startDate', start)
108-
emit('update:endDate', end)
10995
}
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-
)
13296
</script>

0 commit comments

Comments
 (0)