This commit is contained in:
guanj
2025-12-04 09:37:58 +08:00
3 changed files with 60 additions and 34 deletions

View File

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

View File

@@ -22,7 +22,7 @@ import { ref, onMounted, provide, reactive, watch, nextTick } from 'vue'
import TableStore from '@/utils/tableStore' import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue' import Table from '@/components/table/index.vue'
import TableHeader from '@/components/table/header/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 OverLimitDetails from '@/components/cockpit/indicatorFittingChart/components/overLimitDetails.vue'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import { useTimeCacheStore } from '@/stores/timeCache' import { useTimeCacheStore } from '@/stores/timeCache'
@@ -33,7 +33,8 @@ 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 OverLimitDetailsRef = ref() const OverLimitDetailsRef = ref()
const headerHeight = ref(57) const headerHeight = ref(57)
@@ -103,8 +104,12 @@ const tableStore: any = new TableStore({
{ title: '主要存在的电能质量问题', field: 'problems', minWidth: '150', showOverflow: true } { title: '主要存在的电能质量问题', field: 'problems', minWidth: '150', showOverflow: true }
], ],
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, prop.timeValue)
tableStore.table.params.searchBeginTime = time[0]
tableStore.table.params.searchEndTime = time[1]
}, },
loadCallback: () => { loadCallback: () => {
tableStore.table.height = `calc(${prop.height} - 80px)` 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') throw new Error('Invalid key')
} }
} }
/** /**
* 获取当月时间 * 获取当月时间
* @param timeKey 组件外部时间 1 年 2 季 3 月 4 周 5 日 * @param interval 组件外部时间 1 年 2 季 3 月 4 周 5 日
* @param timeList 组件勾选时间 [] * @param timeList 组件勾选时间 []
* @param fullScreen 是否全屏 true 是 false 否
* @param externalTime //外部传入时间 * @param externalTime //外部传入时间
*/ */
export function getTime(interval: number, timeList: any, externalTime: any) {
export function getTime(timeKey: number, timeList: any[], fullScreen: boolean, externalTime: any[]) {
// 1、先匹配时间 // 1、先匹配时间
// if(匹配上){ // 检查 interval 是否在 timeList 中
// 是全屏 返回缓存值 if (timeList && timeList.includes(interval.toString())) {
// 不是全屏返回外部传入时间 externalTime // 匹配上了,返回外部传入时间 externalTime
// }else{ if (externalTime && externalTime.length >= 2) {
// 返回 getTimeOfTheMonth(timeList.at(-1)) 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())
}
}
}