replace momentjs with dayjs and use watch instead of update (#12351)

This commit is contained in:
Manoj Kumar 2026-01-05 12:49:03 +05:30 committed by GitHub
parent 77cb0827d3
commit ca64406a88
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 21 additions and 22 deletions

View File

@ -61,7 +61,7 @@
<script> <script>
import { ref, reactive, toRaw } from 'vue' import { ref, reactive, toRaw } from 'vue'
import moment from 'moment' import dayjs from 'dayjs'
export default { export default {
name: 'DateTimeFilter', name: 'DateTimeFilter',
@ -84,20 +84,6 @@ export default {
value: '' value: ''
} }
}, },
computed: {
startDate () {
if (this.startDateProp) {
return moment(this.startDateProp)
}
return null
},
endDate () {
if (this.endDateProp) {
return moment(this.endDateProp)
}
return null
}
},
data () { data () {
return { return {
allDataIsChecked: false, allDataIsChecked: false,
@ -110,19 +96,27 @@ export default {
submitButtonLabel: this.$t('label.ok') submitButtonLabel: this.$t('label.ok')
} }
}, },
updated () {
this.form.startDate = this.startDate
this.form.endDate = this.endDate
},
created () { created () {
this.initForm() this.initForm()
}, },
watch: {
startDateProp (newVal) {
this.form.startDate = newVal ? dayjs(newVal) : null
},
endDateProp (newVal) {
this.form.endDate = newVal ? dayjs(newVal) : null
}
},
methods: { methods: {
initForm () { initForm () {
this.formRef = ref() this.formRef = ref()
// Use dayjs instead of moment - Ant Design Vue requires dayjs
const startDate = this.startDateProp ? dayjs(this.startDateProp) : null
const endDate = this.endDateProp ? dayjs(this.endDateProp) : null
this.form = reactive({ this.form = reactive({
startDate: this.startDate, startDate: startDate,
endDate: this.endDate endDate: endDate
}) })
}, },
handleSubmit (e) { handleSubmit (e) {
@ -130,7 +124,12 @@ export default {
this.formRef.value.validate().then(() => { this.formRef.value.validate().then(() => {
this.submitButtonLabel = this.$t('label.refresh') this.submitButtonLabel = this.$t('label.refresh')
const values = toRaw(this.form) const values = toRaw(this.form)
this.$emit('onSubmit', values) // Convert dayjs objects back to JavaScript Date objects
const result = {
startDate: values.startDate ? values.startDate.toDate() : null,
endDate: values.endDate ? values.endDate.toDate() : null
}
this.$emit('onSubmit', result)
}).catch(error => { }).catch(error => {
this.formRef.value.scrollToField(error.errorFields[0].name) this.formRef.value.scrollToField(error.errorFields[0].name)
}) })