内部时间组件设置默认值

This commit is contained in:
stt
2025-11-06 14:24:15 +08:00
parent b5aff1a837
commit 593f2e2c66
4 changed files with 205 additions and 19 deletions

View File

@@ -1,14 +1,28 @@
<template>
<div>
<!--主要监测点列表 -->
<TableHeader :showReset="false" datePicker @selectChange="selectChange" v-if="fullscreen">
<TableHeader :showReset="false" @selectChange="selectChange" v-if="fullscreen">
<template v-slot:select>
<el-form-item label="日期">
<DatePicker
ref="datePickerRef"
:nextFlag="false"
:theCurrentTime="true"
:initialInterval="getInitialInterval()"
:initialTimeValue="getInitialTimeValue()"
@change="handleDatePickerChange"
></DatePicker>
</el-form-item>
<el-form-item label="关键词">
<el-input v-model="tableStore.table.params.searchValue" clearable placeholder="请输关键字" />
</el-form-item>
</template>
</TableHeader>
<Table ref="tableRef" @cell-click="cellClickEvent" :height="`calc(${prop.height} - ${headerHeight}px + ${fullscreen ? 0 : 56}px )`"></Table>
<Table
ref="tableRef"
@cell-click="cellClickEvent"
:height="`calc(${prop.height} - ${headerHeight}px + ${fullscreen ? 0 : 56}px )`"
></Table>
<!-- 指标越限详情 -->
<OverLimitDetails ref="OverLimitDetailsRef" />
</div>
@@ -23,6 +37,10 @@ import { ElMessage, ElMessageBox } from 'element-plus'
import { getTimeOfTheMonth } from '@/utils/formatTime'
import { ElTag } from 'element-plus'
import OverLimitDetails from '@/components/cockpit/listOfMainMonitoringPoints/components/overLimitDetails.vue'
import { useRoute } from 'vue-router'
import { useTimeCacheStore } from '@/stores/timeCache'
import DatePicker from '@/components/form/datePicker/index.vue'
const prop = defineProps({
w: { type: String },
h: { type: String },
@@ -34,6 +52,11 @@ const prop = defineProps({
const dictData = useDictData()
const OverLimitDetailsRef = ref()
const headerHeight = ref(57)
const route = useRoute()
const timeCacheStore = useTimeCacheStore()
const datePickerRef = ref()
const selectChange = (showSelect: any, height: any) => {
headerHeight.value = height
}
@@ -49,10 +72,20 @@ const fullscreen = computed(() => {
return false
}
})
// 处理 DatePicker 值变化事件
const handleDatePickerChange = (value: any) => {
console.log('DatePicker value changed:', value)
// 将值缓存到 timeCache
if (value) {
timeCacheStore.setCache(route.path, value.interval, value.timeValue)
}
}
const tableStore: any = new TableStore({
url: '/user-boot/role/selectRoleDetail?id=0',
url: '/system-boot/dashboard/queryPage',
method: 'POST',
showPage: false,
exportName: '主要监测点列表',
column: [
@@ -89,11 +122,23 @@ const tableStore: any = new TableStore({
{ title: '主要存在的电能质量问题', field: 'question', minWidth: '150' }
],
beforeSearchFun: () => {
tableStore.table.params.searchBeginTime = prop.timeValue?.[0] || getTimeOfTheMonth(prop.timeKey)[0]
tableStore.table.params.searchEndTime = prop.timeValue?.[1] || getTimeOfTheMonth(prop.timeKey)[1]
// 尝试从缓存获取时间值
let beginTime, endTime
if (fullscreen.value) {
const cached = timeCacheStore.getCache(route.path)
if (cached && cached.timeValue) {
beginTime = cached.timeValue[0]
endTime = cached.timeValue[1]
}
}
// 如果缓存中没有则使用默认值
tableStore.table.params.searchBeginTime = beginTime || prop.timeValue?.[0] || getTimeOfTheMonth(prop.timeKey)[0]
tableStore.table.params.searchEndTime = endTime || prop.timeValue?.[1] || getTimeOfTheMonth(prop.timeKey)[1]
},
loadCallback: () => {
tableStore.table.data = [
{
name: '10kV1#电动机',
@@ -139,7 +184,41 @@ const cellClickEvent = ({ row, column }: any) => {
}
}
// 获取缓存的初始值
const getInitialInterval = () => {
if (fullscreen.value) {
const cached = timeCacheStore.getCache(route.path)
if (cached && cached.interval !== undefined) {
return cached.interval
}
}
return 3 // 默认值
}
const getInitialTimeValue = () => {
if (fullscreen.value) {
const cached = timeCacheStore.getCache(route.path)
if (cached && cached.timeValue) {
return cached.timeValue
}
}
return prop.timeValue // 使用传入的默认值
}
// 在组件挂载时设置缓存值到 DatePicker
onMounted(() => {
if (datePickerRef.value) {
const cached = timeCacheStore.getCache(route.path)
if (cached) {
// 如果有缓存值,设置到 DatePicker 组件
if (cached.interval !== undefined) {
datePickerRef.value.setInterval(cached.interval)
}
if (cached.timeValue) {
datePickerRef.value.timeValue = cached.timeValue
}
}
}
tableStore.index()
})
watch(