diff --git a/src/components/cockpit/indicatorFittingChart/index.vue b/src/components/cockpit/indicatorFittingChart/index.vue index 72bdefd..35c53e2 100644 --- a/src/components/cockpit/indicatorFittingChart/index.vue +++ b/src/components/cockpit/indicatorFittingChart/index.vue @@ -104,8 +104,8 @@ const tableStore: any = new TableStore({ { title: '主要存在的电能质量问题', field: 'problems', minWidth: '150', showOverflow: true } ], 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] }, loadCallback: () => { tableStore.table.height = `calc(${prop.height} - 80px)` @@ -128,27 +128,6 @@ const cellClickEvent = ({ row, column }: any) => { } } -// 获取缓存的初始值 -const getInitialInterval = (): 3 => { - if (fullscreen.value) { - const cached = timeCacheStore.getCache(route.path) - if (cached && cached.interval !== undefined) { - return cached.interval as 3 // 强制断言为 3 或根据实际类型调整 - } - } - return 3 // 明确返回字面量类型 3 -} -// 外部总的时间值 -const getInitialTimeValue = () => { - if (fullscreen.value) { - const cached = timeCacheStore.getCache(route.path) - if (cached && cached.timeValue) { - return cached.timeValue - } - } - return prop.timeValue // 使用传入的默认值 -} - // 在组件挂载时设置缓存值到 DatePicker onMounted(() => { tableStore.index() @@ -160,12 +139,17 @@ watch( } ) watch( - () => prop.timeValue, // 监听的目标(函数形式避免直接传递 props 导致的警告) + () => prop.timeValue, (newVal, oldVal) => { - tableStore.index() + // 当外部时间值变化时,更新表格的时间参数 + if (newVal && (!oldVal || newVal[0] !== oldVal[0] || newVal[1] !== oldVal[1])) { + tableStore.table.params.searchBeginTime = newVal[0] + tableStore.table.params.searchEndTime = newVal[1] + tableStore.index() + } }, { - deep: true // 若 timeValue 是对象/数组,需开启深度监听 + deep: true } ) diff --git a/src/components/cockpit/overLimitStatistics/index.vue b/src/components/cockpit/overLimitStatistics/index.vue index 3eac2a5..621d6c5 100644 --- a/src/components/cockpit/overLimitStatistics/index.vue +++ b/src/components/cockpit/overLimitStatistics/index.vue @@ -26,18 +26,17 @@ import TableStore from '@/utils/tableStore' import Table from '@/components/table/index.vue' import TableHeader from '@/components/table/header/index.vue' import MyEchart from '@/components/echarts/MyEchart.vue' -import { getTimeOfTheMonth } from '@/utils/formatTime' import OverLimitDetails from '@/components/cockpit/overLimitStatistics/components/overLimitDetails.vue' import { useRoute } from 'vue-router' import { useTimeCacheStore } from '@/stores/timeCache' import { totalLimitStatisticsData } from '@/api/harmonic-boot/cockpit/cockpit' const prop = defineProps({ - w: { type: [String, Number]}, - h: { type: [String, Number]}, - width: { type: [String, Number]}, - height: { type: [String, Number]}, - timeKey: { type: [String, Number]}, + w: { type: [String, Number] }, + h: { type: [String, Number] }, + width: { type: [String, Number] }, + height: { type: [String, Number] }, + timeKey: { type: [String, Number] }, timeValue: { type: Object } }) @@ -51,12 +50,11 @@ const echartList = ref({}) const selectChange = (showSelect: any, height: any, datePickerValue?: any) => { headerHeight.value = height - // 如果有传入 datePicker 的值 - // if (datePickerValue) { - // // 更新表格参数 - // tableStore.table.params.searchBeginTime = datePickerValue.timeValue?.[0] - // tableStore.table.params.searchEndTime = datePickerValue.timeValue?.[1] - // } + if (datePickerValue && datePickerValue.timeValue) { + // 更新时间参数 + tableStore.table.params.searchBeginTime = datePickerValue.timeValue[0] + tableStore.table.params.searchEndTime = datePickerValue.timeValue[1] + } } // 计算是否全屏展示 @@ -117,7 +115,6 @@ const initEcharts = () => { ] } } - }) } @@ -194,24 +191,12 @@ const tableStore: any = new TableStore({ } ], beforeSearchFun: () => { - // 尝试从缓存获取时间值 - 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] - - tableStore.table.params.searchEndTime = endTime || 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] }, loadCallback: () => { tableStore.table.height = `calc(${prop.height} - 80px)` + initEcharts() } }) @@ -233,7 +218,6 @@ const cellClickEvent = ({ row, column }: any) => { onMounted(() => { tableStore.index() - initEcharts() }) watch( () => prop.timeKey, @@ -243,13 +227,17 @@ watch( } ) watch( - () => prop.timeValue, // 监听的目标(函数形式避免直接传递 props 导致的警告) + () => prop.timeValue, (newVal, oldVal) => { - tableStore.index() - initEcharts() + // 当外部时间值变化时,更新表格的时间参数 + if (newVal && (!oldVal || newVal[0] !== oldVal[0] || newVal[1] !== oldVal[1])) { + tableStore.table.params.searchBeginTime = newVal[0] + tableStore.table.params.searchEndTime = newVal[1] + tableStore.index() + } }, { - deep: true // 若 timeValue 是对象/数组,需开启深度监听 + deep: true } )