zhb há 1 mês atrás
pai
commit
d1c7e7e5e1

+ 32 - 7
components/cwg-complex-search.vue

@@ -116,7 +116,7 @@
 </template>
 
 <script setup>
-import { ref, computed, watch, onMounted, onUnmounted } from 'vue'
+import { ref, computed, watch, onMounted, nextTick, onUnmounted } from 'vue'
 import { useI18n } from 'vue-i18n'
 
 const { t } = useI18n()
@@ -162,14 +162,16 @@ const dateLimit = computed(() => {
     }
 })
 
-// 获取日期字段的默认值(当前月范围或当天)
+// 获取日期字段的默认值(当前月范围:月初 ~ 今天)
 const getDefaultDateValue = (field) => {
     const now = new Date()
     const year = now.getFullYear()
     const month = now.getMonth()
-    const firstDay = new Date(year, month, 1)
-    const lastDay = new Date(year, month + 1, 0)
 
+    // 本月1号
+    const firstDay = new Date(year, month, 1)
+    // 今天
+    const today = new Date()
     const formatDate = (date) => {
         const y = date.getFullYear()
         const m = String(date.getMonth() + 1).padStart(2, '0')
@@ -178,10 +180,9 @@ const getDefaultDateValue = (field) => {
     }
 
     if (field.type === 'daterange') {
-        return [formatDate(firstDay), formatDate(lastDay)]
+        return [formatDate(firstDay), formatDate(today)]
     } else if (field.type === 'date') {
-        // 单日期默认设为今天(也可设为第一天,根据需求调整)
-        return formatDate(now)
+        return formatDate(today)
     }
     return ''
 }
@@ -327,6 +328,17 @@ const resetForm = () => {
         }
     })
     formData.value = empty
+    tempFormData.value = JSON.parse(JSON.stringify(empty)) // 👈 加这行
+    nextTick(() => {
+        tempFormData.value = { ...empty }
+        formData.value = { ...empty }
+
+        nextTick(() => {
+            if (dateField.value) {
+                handleDateChange(formData.value[dateField.value.key])
+            }
+        })
+    })
     emit('reset', empty)
 }
 // 触发查询
@@ -366,6 +378,19 @@ const resetTempForm = () => {
         }
     })
     tempFormData.value = empty
+    formData.value = JSON.parse(JSON.stringify(empty)) // 👈 加这行
+    // 👇 强制日期组件刷新选中状态
+    nextTick(() => {
+        formData.value = { ...empty }
+        tempFormData.value = { ...empty }
+
+        nextTick(() => {
+            if (dateField.value) {
+                handleDateChange(formData.value[dateField.value.key])
+            }
+            handleSearch()
+        })
+    })
 }
 const applyFilter = () => {
     // 将临时数据同步到正式表单

+ 13 - 0
uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.vue

@@ -822,6 +822,19 @@ export default {
 				this.tempRange.startTime = ''
 				this.tempRange.endDate = ''
 				this.tempRange.endTime = ''
+				// 重置左右日历的状态
+				this.startMultipleStatus = {
+					before: '',
+					after: '',
+					data: [],
+					fulldate: ''
+				}
+				this.endMultipleStatus = {
+					before: '',
+					after: '',
+					data: [],
+					fulldate: ''
+				}
 				if (this.isPhone) {
 					this.$refs.mobile && this.$refs.mobile.clearCalender()
 				} else {