diff --git a/src/components/TableModel2/index.vue b/src/components/TableModel2/index.vue index 7e2ce28..aa2895b 100644 --- a/src/components/TableModel2/index.vue +++ b/src/components/TableModel2/index.vue @@ -368,11 +368,27 @@ export default { /* 生成查询参数 */ this.formLabel.map((e) => { if (e.f_type === 'dateRange' || e.f_type === 'dateTimeRange') { + // 获取默认值 + let defaultValues = null + if (e.defaultValue) { + // 如果 defaultValue 是函数,调用它获取值;否则直接使用 + defaultValues = typeof e.defaultValue === 'function' ? e.defaultValue() : e.defaultValue + } + // 初始化日期范围的两个字段 - this.$set(this.queryParams, e.dateType[0], '') - this.$set(this.queryParams, e.dateType[1], '') - // 初始化日期选择器绑定的字段(用于 v-model) - this.$set(this.queryParams, e.f_model, null) + if (defaultValues && Array.isArray(defaultValues) && defaultValues.length === 2) { + // 如果有默认值,使用默认值 + this.$set(this.queryParams, e.dateType[0], defaultValues[0] || '') + this.$set(this.queryParams, e.dateType[1], defaultValues[1] || '') + // 初始化日期选择器绑定的字段(用于 v-model),设置为默认值数组 + this.$set(this.queryParams, e.f_model, defaultValues) + } else { + // 没有默认值,初始化为空 + this.$set(this.queryParams, e.dateType[0], '') + this.$set(this.queryParams, e.dateType[1], '') + // 初始化日期选择器绑定的字段(用于 v-model) + this.$set(this.queryParams, e.f_model, null) + } this.typeList = e.dateType if (this.isOneMonth) { @@ -488,26 +504,36 @@ export default { /** 重置按钮 */ resetQuery() { this.$refs.queryFormRef.resetFields() - if (this.typeList.length > 1) { - if (this.isCurrentDate) { - this.queryParams[this.typeList[0]] = new Date() - .toISOString() - .split('T')[0] - this.queryParams[this.typeList[1]] = new Date() - .toISOString() - .split('T')[0] - this.queryParams.time = [ - new Date().toISOString().split('T')[0], - new Date().toISOString().split('T')[0], - ] - } else { - this.queryParams[this.typeList[0]] = '' - this.queryParams[this.typeList[1]] = '' - this.queryParams.time = [] + // 遍历所有日期范围字段,重置为默认值或清空 + this.formLabel.forEach((e) => { + if (e.f_type === 'dateRange' || e.f_type === 'dateTimeRange') { + // 获取默认值 + let defaultValues = null + if (e.defaultValue) { + defaultValues = typeof e.defaultValue === 'function' ? e.defaultValue() : e.defaultValue + } + + if (e.dateType && e.dateType.length >= 2) { + if (this.isCurrentDate && e.f_type === 'dateRange') { + // 日期类型,设置为今天 + const today = new Date().toISOString().split('T')[0] + this.queryParams[e.dateType[0]] = today + this.queryParams[e.dateType[1]] = today + this.queryParams[e.f_model] = [today, today] + } else if (defaultValues && Array.isArray(defaultValues) && defaultValues.length === 2) { + // 有默认值,恢复默认值 + this.queryParams[e.dateType[0]] = defaultValues[0] || '' + this.queryParams[e.dateType[1]] = defaultValues[1] || '' + this.queryParams[e.f_model] = defaultValues + } else { + // 没有默认值,清空 + this.queryParams[e.dateType[0]] = '' + this.queryParams[e.dateType[1]] = '' + this.queryParams[e.f_model] = null + } + } } - } else { - this.queryParams[this.typeList[0]] = '' - } + }) this.queryParams.pageNum = 1 this.queryParams.pageSize = 10 this.getTableList() diff --git a/src/views/alarm/alarm/config.js b/src/views/alarm/alarm/config.js index a87fc1e..c66ce4c 100644 --- a/src/views/alarm/alarm/config.js +++ b/src/views/alarm/alarm/config.js @@ -7,6 +7,23 @@ export const formLabel = [ f_width: '400px', dateType: ['startTime', 'endTime'], valueFormat: 'yyyy-MM-dd HH:mm', + // 默认时间设置,可以是数组 [startTime, endTime] 或函数返回数组 + // 函数形式:() => [startTime, endTime],支持动态计算 + defaultValue: () => { + // 默认设置为当天00:00到23:59 + const now = new Date() + const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0) + const todayEnd = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59) + const formatTime = (date) => { + const year = date.getFullYear() + const month = String(date.getMonth() + 1).padStart(2, '0') + const day = String(date.getDate()).padStart(2, '0') + const hours = String(date.getHours()).padStart(2, '0') + const minutes = String(date.getMinutes()).padStart(2, '0') + return `${year}-${month}-${day} ${hours}:${minutes}` + } + return [formatTime(todayStart), formatTime(todayEnd)] + }, }, ] diff --git a/src/views/device/image-recognition/index.vue b/src/views/device/image-recognition/index.vue index 88a1198..e36ad73 100644 --- a/src/views/device/image-recognition/index.vue +++ b/src/views/device/image-recognition/index.vue @@ -31,7 +31,7 @@ -