diff --git a/src/components/cockpit/listOfMainMonitoringPoints/index.vue b/src/components/cockpit/listOfMainMonitoringPoints/index.vue index 5c174a7..6354271 100644 --- a/src/components/cockpit/listOfMainMonitoringPoints/index.vue +++ b/src/components/cockpit/listOfMainMonitoringPoints/index.vue @@ -141,7 +141,6 @@ const echartList = ref() const headerHeight = ref(57) const selectChange = (showSelect: any, height: any, datePickerValue?: any) => { headerHeight.value = height - if (datePickerValue && datePickerValue.timeValue) { // 更新时间参数 tableStore.table.params.searchBeginTime = datePickerValue.timeValue[0] @@ -265,6 +264,7 @@ const initCode = () => { tableStore.table.params.power = powerList.value[0].id tableStore.table.params.indicator = indicatorList.value[0].id nextTick(() => { + // setTime() tableStore.index() }) }) @@ -278,18 +278,19 @@ const tableStore: any = new TableStore({ exportName: '主要监测点列表', column: [], beforeSearchFun: () => { + setTime() // 设置时间参数 // 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] + // 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) { @@ -392,41 +393,57 @@ 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) - } - } + // 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() }) }) + watch( () => prop.timeKey, val => { tableStore.index() } ) +const setTime = () => { + const time = getTime( + (TableHeaderRef.value?.datePickerRef.interval || prop.interval) ?? 0, + prop.timeKey, + fullscreen.value + ? [tableStore.table.params.searchBeginTime, tableStore.table.params.searchEndTime] + : prop.timeValue + ) + console.log("🚀 ~ setTime ~ time:", time) + + tableStore.table.params.searchBeginTime = time[0] + tableStore.table.params.searchEndTime = time[1] + TableHeaderRef.value?.setInterval(time[2] - 0) + TableHeaderRef.value?.setTimeInterval([time[0], time[1]]) +} + watch( () => prop.timeValue, (newVal, oldVal) => { // 当外部时间值变化时,更新表格的时间参数 - 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() - } + // if (newVal && (!oldVal || newVal[0] !== oldVal[0] || newVal[1] !== oldVal[1])) { + tableStore.index() + + // } }, { deep: true diff --git a/src/components/form/datePicker/index.vue b/src/components/form/datePicker/index.vue index 3c251fd..7216ba7 100644 --- a/src/components/form/datePicker/index.vue +++ b/src/components/form/datePicker/index.vue @@ -101,6 +101,7 @@ const filteredTimeOptions = computed(() => { return timeOptions.value.filter((option: any) => props.timeKeyList.includes(option.value.toString()) ) + }) onMounted(() => { diff --git a/src/utils/formatTime.ts b/src/utils/formatTime.ts index da5195b..8b3b67c 100644 --- a/src/utils/formatTime.ts +++ b/src/utils/formatTime.ts @@ -352,6 +352,7 @@ export function getTimeOfTheMonth(key: any): [string, string] { const dayOfWeek = now.getDay() // 0是周日 const diff = now.getDate() - dayOfWeek + (dayOfWeek === 0 ? -6 : 1) // 调整为周一 const weekStart = new Date(year, month, diff) + console.log("🚀 ~ getTimeOfTheMonth ~ weekStart:", weekStart) return [formatDate(weekStart, 'YYYY-MM-DD'), formatDate(now, 'YYYY-MM-DD')] case '5': // 日 @@ -367,26 +368,31 @@ export function getTimeOfTheMonth(key: any): [string, string] { * @param interval 组件外部时间 1 年 2 季 3 月 4 周 5 日 * @param timeList 组件勾选时间 [] * @param externalTime //外部传入时间 + * @param fullscreen // 全屏是否全屏 */ -export function getTime(interval: number, timeList: any, externalTime: any) { +export function getTime(interval: number | 3, timeList: any , externalTime: any, ) { + console.log("🚀 ~ getTime ~ timeList:", timeList) // 1、先匹配时间 // 检查 interval 是否在 timeList 中 if (timeList && timeList.includes(interval.toString())) { + return [externalTime[0], externalTime[1], interval] + // 匹配上了,返回外部传入时间 externalTime - if (externalTime && externalTime.length >= 2) { - return [externalTime[0], externalTime[1]] - } else { - // 如果 externalTime 无效,回退到默认逻辑 - return getTimeOfTheMonth(interval.toString()) - } + // if (externalTime && externalTime.length >= 2) { + // return [externalTime[0], externalTime[1]] + // } else { + // // 如果 externalTime 无效,回退到默认逻辑 + // return getTimeOfTheMonth(interval.toString()) + // } } else { + return [...getTimeOfTheMonth(timeList[0]), timeList[0], ] // 没有匹配上,返回 timeList 中最后一项的时间范围 - if (timeList && timeList.length > 0) { - const lastItem = timeList[timeList.length - 1] - return getTimeOfTheMonth(lastItem) - } else { - // 如果 timeList 为空,使用 interval 参数 - return getTimeOfTheMonth(interval.toString()) - } + // if (timeList && timeList.length > 0) { + // const lastItem = timeList[timeList.length - 1] + // return getTimeOfTheMonth(lastItem) + // } else { + // // 如果 timeList 为空,使用 interval 参数 + // return getTimeOfTheMonth(interval.toString()) + // } } }