修改"下一个"按钮的状态

This commit is contained in:
stt
2025-12-08 15:23:38 +08:00
parent f92b07c555
commit 9b0fd76f48

View File

@@ -126,9 +126,13 @@ const checkInitialButtonStatus = () => {
const endTime = timeValue.value[1] const endTime = timeValue.value[1]
const currentDate = window.XEUtils.toDateString(new Date(), 'yyyy-MM-dd') const currentDate = window.XEUtils.toDateString(new Date(), 'yyyy-MM-dd')
// 如果结束时间小于当前日期,则不禁用"下一个"按钮 // 只有当 props.nextFlag 为 false 时才应用限制
if (new Date(endTime + ' 00:00:00').getTime() < new Date(currentDate + ' 00:00:00').getTime()) { if (!props.nextFlag) {
preDisabled.value = false // 如果结束时间早于当前日期则按钮可用preDisabled = false
// 如果结束时间晚于或等于当前日期则按钮禁用preDisabled = true
const endDateTime = new Date(endTime).getTime()
const currentDateTime = new Date(currentDate).getTime()
preDisabled.value = endDateTime >= currentDateTime
} }
} }
} }
@@ -141,11 +145,6 @@ const emitChange = () => {
timeValue: timeValue.value, timeValue: timeValue.value,
timeFlag: timeFlag.value timeFlag: timeFlag.value
}) })
// preClick 操作后不执行按钮状态检查
if (!isUserAction) {
checkButtonStatus()
}
}) })
} }
// 选择时间范围 // 选择时间范围
@@ -182,39 +181,15 @@ const timeChange = (e: number) => {
timeFlag.value = 1 timeFlag.value = 1
} }
// 检查按钮状态 nextTick(() => {
checkButtonStatus() // 检查按钮状态
checkInitialButtonStatus()
})
// 触发 change 事件 // 触发 change 事件
emitChange() emitChange()
} }
// 添加一个标志来跟踪是否由用户操作触发
let isUserAction = true
// 修改 checkButtonStatus 方法
const checkButtonStatus = (forceEnable = false) => {
// 如果是强制启用,则直接启用
if (forceEnable) {
preDisabled.value = false
return
}
if (timeValue.value && timeValue.value.length >= 2) {
const endTime = timeValue.value[1]
const currentDate = window.XEUtils.toDateString(new Date(), 'yyyy-MM-dd')
// 如果结束时间大于等于当前日期,且 nextFlag 为 false则禁用"下一个"按钮
if (!props.nextFlag) {
if (new Date(endTime + ' 00:00:00').getTime() >= new Date(currentDate + ' 00:00:00').getTime()) {
preDisabled.value = true
} else {
preDisabled.value = false
}
}
}
}
// 当前 // 当前
const nowTime = () => { const nowTime = () => {
// console.log(interval.value, '000000000') // console.log(interval.value, '000000000')
@@ -282,10 +257,8 @@ const preClick = () => {
// var temp = NowgetEndTime() // var temp = NowgetEndTime()
// timeStatus(temp, endTime) // timeStatus(temp, endTime)
// 触发 change 事件,但临时标记为用户操作 // 触发 change 事件
isUserAction = true
emitChange() emitChange()
isUserAction = false
} }
//下一个 //下一个
const next = () => { const next = () => {