日期下拉默认修改

This commit is contained in:
stt
2025-12-04 10:30:19 +08:00
parent 5687367602
commit 3accaf3079
5 changed files with 84 additions and 13 deletions

View File

@@ -8,6 +8,7 @@
datePicker
v-if="fullscreen"
:timeCacheFlag="false"
:timeKeyList="['3']"
></TableHeader>
<el-calendar
v-model="value"
@@ -104,7 +105,13 @@ const tableStore: any = new TableStore({
// }
// },
beforeSearchFun: () => {
const time = getTime(prop.interval ?? 0, prop.timeKey, prop.timeValue)
const time = getTime(
prop.interval ?? 0,
prop.timeKey,
tableStore.table.params.searchBeginTime && tableStore.table.params.searchEndTime
? [tableStore.table.params.searchBeginTime, tableStore.table.params.searchEndTime]
: prop.timeValue
)
tableStore.table.params.searchBeginTime = time[0]
tableStore.table.params.searchEndTime = time[1]
},
@@ -151,12 +158,18 @@ provide('tableStore', tableStore)
onMounted(() => {
nextTick(() => {
if (TableHeaderRef.value && typeof TableHeaderRef.value.setDatePicker === 'function') {
TableHeaderRef.value.setDatePicker([{ label: '月份', value: 3 }])
}
// if (TableHeaderRef.value && typeof TableHeaderRef.value.setDatePicker === 'function') {
// TableHeaderRef.value.setDatePicker([{ label: '月份', value: 3 }])
// }
if (fullscreen.value) {
if (prop.interval == 3) {
const time = getTime(prop.interval ?? 0, prop.timeKey, prop.timeValue)
const time = getTime(
prop.interval ?? 0,
prop.timeKey,
tableStore.table.params.searchBeginTime && tableStore.table.params.searchEndTime
? [tableStore.table.params.searchBeginTime, tableStore.table.params.searchEndTime]
: prop.timeValue
)
tableStore.table.params.searchBeginTime = time[0]
tableStore.table.params.searchEndTime = time[1]
TableHeaderRef.value.setTimeInterval(prop.timeValue)

View File

@@ -107,7 +107,13 @@ const tableStore: any = new TableStore({
// tableStore.table.params.searchBeginTime = tableStore.table.params.searchBeginTime || prop.timeValue?.[0]
// tableStore.table.params.searchEndTime = tableStore.table.params.searchEndTime || prop.timeValue?.[1]
const time = getTime(prop.interval ?? 0, prop.timeKey, prop.timeValue)
const time = getTime(
prop.interval ?? 0,
prop.timeKey,
tableStore.table.params.searchBeginTime && tableStore.table.params.searchEndTime
? [tableStore.table.params.searchBeginTime, tableStore.table.params.searchEndTime]
: prop.timeValue
)
tableStore.table.params.searchBeginTime = time[0]
tableStore.table.params.searchEndTime = time[1]
},

View File

@@ -1,7 +1,13 @@
<template>
<div>
<!--指标拟合图 -->
<TableHeader datePicker @selectChange="selectChange" v-if="fullscreen">
<TableHeader
datePicker
@selectChange="selectChange"
v-if="fullscreen"
ref="TableHeaderRef"
:timeKeyList="['4', '5']"
>
<template v-slot:select>
<el-form-item label="监测点">
<el-select v-model="tableStore.table.params.lineId" placeholder="请选择监测点" clearable>
@@ -75,6 +81,7 @@ import { useConfig } from '@/stores/config'
import { cslineList, fittingData } from '@/api/harmonic-boot/cockpit/cockpit'
import { queryByCode, queryCsDictTree } from '@/api/system-boot/dictTree'
import { ElMessage } from 'element-plus'
import { getTime } from '@/utils/formatTime'
const prop = defineProps({
w: { type: [String, Number] },
@@ -82,9 +89,12 @@ const prop = defineProps({
width: { type: [String, Number] },
height: { type: [String, Number] },
timeKey: { type: [String, Number] },
timeValue: { type: Object }
timeValue: { type: Object },
interval: { type: Number }
})
const TableHeaderRef = ref()
const config = useConfig()
const lineList: any = ref()
@@ -269,8 +279,17 @@ const tableStore: any = new TableStore({
column: [],
beforeSearchFun: () => {
// 设置时间参数
tableStore.table.params.searchBeginTime = tableStore.table.params.searchBeginTime || prop.timeValue?.[0]
tableStore.table.params.searchEndTime = tableStore.table.params.searchEndTime || prop.timeValue?.[1]
// tableStore.table.params.searchBeginTime = tableStore.table.params.searchBeginTime || prop.timeValue?.[0]
// tableStore.table.params.searchEndTime = tableStore.table.params.searchEndTime || prop.timeValue?.[1]
const time = getTime(
prop.interval ?? 0,
prop.timeKey,
tableStore.table.params.searchBeginTime && tableStore.table.params.searchEndTime
? [tableStore.table.params.searchBeginTime, tableStore.table.params.searchEndTime]
: prop.timeValue
)
tableStore.table.params.searchBeginTime = time[0]
tableStore.table.params.searchEndTime = time[1]
// 只有当 lineList 已加载且有数据时才设置默认 lineId
if (!tableStore.table.params.lineId && lineList.value && lineList.value.length > 0) {
@@ -373,6 +392,22 @@ watch(
)
onMounted(() => {
if (fullscreen.value) {
if (prop.interval == 4 || prop.interval == 5) {
const time = getTime(
prop.interval ?? 0,
prop.timeKey,
tableStore.table.params.searchBeginTime && tableStore.table.params.searchEndTime
? [tableStore.table.params.searchBeginTime, tableStore.table.params.searchEndTime]
: prop.timeValue
)
tableStore.table.params.searchBeginTime = time[0]
tableStore.table.params.searchEndTime = time[1]
TableHeaderRef.value.setTimeInterval(prop.timeValue)
} else {
TableHeaderRef.value.setInterval(5)
}
}
initLineList().then(() => {
initCode()
})

View File

@@ -5,7 +5,7 @@
style="min-width: 90px; width: 90px; margin-right: 10px"
@change="timeChange"
>
<el-option v-for="item in timeOptions" :key="item.value" :label="item.label" :value="item.value" />
<el-option v-for="item in filteredTimeOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
<el-date-picker
v-model.trim="timeValue"
@@ -35,13 +35,15 @@ interface Props {
theCurrentTime?: boolean
initialInterval?: number
initialTimeValue?: any
timeKeyList?: string[] //日期下拉
}
const props = withDefaults(defineProps<Props>(), {
nextFlag: false,
theCurrentTime: true,
initialInterval: 3,
initialTimeValue: undefined
initialTimeValue: undefined,
timeKeyList: () => []
})
const emit = defineEmits(['change'])
@@ -89,6 +91,18 @@ const shortcuts = [
}
}
]
// 计算过滤后的 timeOptions
const filteredTimeOptions = computed(() => {
if (!props.timeKeyList || props.timeKeyList.length === 0) {
return timeOptions.value
}
return timeOptions.value.filter((option: any) =>
props.timeKeyList.includes(option.value.toString())
)
})
onMounted(() => {
// 使用传入的初始值
if (props.initialInterval !== undefined) {

View File

@@ -15,6 +15,7 @@
:nextFlag="nextFlag"
:theCurrentTime="theCurrentTime"
@change="handleDatePickerChange"
:timeKeyList="props.timeKeyList"
></DatePicker>
</el-form-item>
@@ -89,6 +90,7 @@ interface Props {
showReset?: boolean //是否显示重置
showExport?: boolean //导出控制
timeCacheFlag?: boolean //是否取缓存时间
timeKeyList?: Array<string> //日期下拉列表
}
const props = withDefaults(defineProps<Props>(), {
@@ -99,7 +101,8 @@ const props = withDefaults(defineProps<Props>(), {
theCurrentTime: true,
showReset: true,
showExport: false,
timeCacheFlag: true
timeCacheFlag: true,
timeKeyList: () => [] // 修改为箭头函数返回空数组
})
// 处理 DatePicker 值变化事件