修改时间传值

This commit is contained in:
stt
2025-11-14 13:42:26 +08:00
parent ea6aed9b99
commit d6bfd8b958
2 changed files with 31 additions and 59 deletions

View File

@@ -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
}
)