公共时间修改

This commit is contained in:
stt
2025-12-03 16:30:42 +08:00
parent 5db43cd4b1
commit 0518127792
3 changed files with 60 additions and 35 deletions

View File

@@ -44,6 +44,7 @@ import { ref, onMounted, provide, reactive, watch, h } from 'vue'
import TableStore from '@/utils/tableStore'
import TableHeader from '@/components/table/header/index.vue'
import { dayjs } from 'element-plus'
import { getTime } from '@/utils/formatTime'
const prop = defineProps({
w: { type: [String, Number] },
@@ -51,7 +52,8 @@ 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 headerHeight = ref(57)
@@ -95,11 +97,16 @@ const tableStore: any = new TableStore({
method: 'POST',
showPage: false,
column: [],
// beforeSearchFun: () => {
// if (!fullscreen.value && prop.timeValue && Array.isArray(prop.timeValue)) {
// tableStore.table.params.searchBeginTime = prop.timeValue[0]
// tableStore.table.params.searchEndTime = prop.timeValue[1]
// }
// },
beforeSearchFun: () => {
if (!fullscreen.value && prop.timeValue && Array.isArray(prop.timeValue)) {
tableStore.table.params.searchBeginTime = prop.timeValue[0]
tableStore.table.params.searchEndTime = prop.timeValue[1]
}
const time = getTime(prop.interval ?? 0, prop.timeKey, prop.timeValue)
tableStore.table.params.searchBeginTime = time[0]
tableStore.table.params.searchEndTime = time[1]
},
loadCallback: () => {
value.value = tableStore.table.params.searchBeginTime
@@ -148,8 +155,15 @@ onMounted(() => {
TableHeaderRef.value.setDatePicker([{ label: '月份', value: 3 }])
}
if (fullscreen.value) {
if (prop.interval == 3) {
const time = getTime(prop.interval ?? 0, prop.timeKey, prop.timeValue)
tableStore.table.params.searchBeginTime = time[0]
tableStore.table.params.searchEndTime = time[1]
TableHeaderRef.value.setTimeInterval(prop.timeValue)
} else {
TableHeaderRef.value.setInterval(3)
}
}
tableStore.index()
})
})
@@ -161,18 +175,14 @@ watch(
)
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()
// }
// },
val => {
(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()
}
},
{
deep: true
}

View File

@@ -22,11 +22,10 @@ import { ref, onMounted, provide, reactive, watch, nextTick } from 'vue'
import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue'
import TableHeader from '@/components/table/header/index.vue'
import { getTimeOfTheMonth } from '@/utils/formatTime'
import { getTime } from '@/utils/formatTime'
import OverLimitDetails from '@/components/cockpit/indicatorFittingChart/components/overLimitDetails.vue'
import { useRoute } from 'vue-router'
import { useTimeCacheStore } from '@/stores/timeCache'
import { log } from 'console'
const prop = defineProps({
w: { type: [String, Number] },
@@ -34,7 +33,8 @@ 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 OverLimitDetailsRef = ref()
const headerHeight = ref(57)
@@ -104,8 +104,12 @@ 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]
const time = getTime(prop.interval ?? 0, prop.timeKey, prop.timeValue)
tableStore.table.params.searchBeginTime = time[0]
tableStore.table.params.searchEndTime = time[1]
},
loadCallback: () => {
tableStore.table.height = `calc(${prop.height} - 80px)`

View File

@@ -361,21 +361,32 @@ export function getTimeOfTheMonth(key: any): [string, string] {
throw new Error('Invalid key')
}
}
/**
* 获取当月时间
* @param timeKey 组件外部时间 1 年 2 季 3 月 4 周 5 日
* @param interval 组件外部时间 1 年 2 季 3 月 4 周 5 日
* @param timeList 组件勾选时间 []
* @param fullScreen 是否全屏 true 是 false 否
* @param externalTime //外部传入时间
*/
export function getTime(timeKey: number, timeList: any[], fullScreen: boolean, externalTime: any[]) {
export function getTime(interval: number, timeList: any, externalTime: any) {
// 1、先匹配时间
// if(匹配上){
// 是全屏 返回缓存值
// 不是全屏返回外部传入时间 externalTime
// }else{
// 返回 getTimeOfTheMonth(timeList.at(-1))
// }
// 检查 interval 是否在 timeList 中
if (timeList && timeList.includes(interval.toString())) {
// 匹配上了,返回外部传入时间 externalTime
if (externalTime && externalTime.length >= 2) {
return [externalTime[0], externalTime[1]]
} else {
// 如果 externalTime 无效,回退到默认逻辑
return getTimeOfTheMonth(interval.toString())
}
} else {
// 没有匹配上,返回 timeList 中最后一项的时间范围
if (timeList && timeList.length > 0) {
const lastItem = timeList[timeList.length - 1]
return getTimeOfTheMonth(lastItem)
} else {
// 如果 timeList 为空,使用 interval 参数
return getTimeOfTheMonth(interval.toString())
}
}
}