时间取值修改
This commit is contained in:
@@ -32,11 +32,11 @@ import { useRoute } from 'vue-router'
|
||||
import { useTimeCacheStore } from '@/stores/timeCache'
|
||||
|
||||
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 }
|
||||
})
|
||||
|
||||
@@ -48,11 +48,10 @@ const timeCacheStore = useTimeCacheStore()
|
||||
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]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,21 +179,8 @@ 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] || getTimeOfTheMonth(prop.timeKey)[0]
|
||||
|
||||
tableStore.table.params.searchEndTime = endTime || prop.timeValue?.[1] || getTimeOfTheMonth(prop.timeKey)[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.data = [
|
||||
@@ -235,12 +221,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
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user