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 @@ -
+
{ + 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}` + } + const defaultTimeRange = [formatTime(todayStart), formatTime(todayEnd)] + this.timeRange = defaultTimeRange + this.queryParams.startTime = defaultTimeRange[0] + this.queryParams.endTime = defaultTimeRange[1] + }, + /** 格式化日期时间字符串(从接口返回的格式转换) */ formatDateTimeFromString(dateStr) { if (!dateStr) return '' @@ -200,9 +221,8 @@ export default { /** 重置操作 */ handleReset() { this.queryParams.carType = '' - this.queryParams.startTime = '' - this.queryParams.endTime = '' - this.timeRange = null + // 重置时恢复默认时间范围(当天的 0点0分 到 23点59分) + this.initDefaultTimeRange() this.queryParams.pageNum = 1 this.getImageList() }, @@ -259,6 +279,11 @@ export default { if (item.vehicleType) parts.push(item.vehicleType) return parts.join(' ') || '未知位置' }, + + /** 判断是否需要滚动 */ + needsScroll() { + return this.imageList.length > 4 + }, }, } @@ -330,7 +355,7 @@ export default { } .table-card { - height: calc(100vh - 230px); + min-height: calc(100vh - 230px); display: flex; flex-direction: column; @@ -338,7 +363,7 @@ export default { padding: 20px; display: flex; flex-direction: column; - height: 100%; + min-height: 0; } .table-header { @@ -354,12 +379,20 @@ export default { } .image-grid-container { - flex: 1; - overflow-y: auto; display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; padding: 0 0 16px 0; + // 防止单行数据时占满整个高度 + align-content: start; + grid-auto-rows: min-content; + + // 数据多时才允许滚动 + &.has-scroll { + flex: 1; + overflow-y: auto; + min-height: 0; + } &::-webkit-scrollbar { width: 6px; @@ -384,6 +417,8 @@ export default { overflow: hidden; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); transition: all 0.3s; + // 防止在 grid 中被拉伸 + align-self: start; &:hover { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15); @@ -395,6 +430,8 @@ export default { width: 100%; padding-top: 75%; // 4:3 比例 overflow: hidden; + // 防止拉伸 + height: 0; .detection-image { position: absolute; @@ -504,7 +541,7 @@ export default { flex-shrink: 0; margin-top: 16px; padding-top: 16px; - border-top: 1px solid #ebeef5; + border-top: none; } }