日期下拉默认修改

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

View File

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

View File

@@ -5,7 +5,7 @@
style="min-width: 90px; width: 90px; margin-right: 10px" style="min-width: 90px; width: 90px; margin-right: 10px"
@change="timeChange" @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-select>
<el-date-picker <el-date-picker
v-model.trim="timeValue" v-model.trim="timeValue"
@@ -35,13 +35,15 @@ interface Props {
theCurrentTime?: boolean theCurrentTime?: boolean
initialInterval?: number initialInterval?: number
initialTimeValue?: any initialTimeValue?: any
timeKeyList?: string[] //日期下拉
} }
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
nextFlag: false, nextFlag: false,
theCurrentTime: true, theCurrentTime: true,
initialInterval: 3, initialInterval: 3,
initialTimeValue: undefined initialTimeValue: undefined,
timeKeyList: () => []
}) })
const emit = defineEmits(['change']) 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(() => { onMounted(() => {
// 使用传入的初始值 // 使用传入的初始值
if (props.initialInterval !== undefined) { if (props.initialInterval !== undefined) {

View File

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