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

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 currentDate = window.XEUtils.toDateString(new Date(), 'yyyy-MM-dd')
// 如果结束时间小于当前日期,则不禁用"下一个"按钮
if (new Date(endTime + ' 00:00:00').getTime() < new Date(currentDate + ' 00:00:00').getTime()) {
preDisabled.value = false
// 只有当 props.nextFlag 为 false 时才应用限制
if (!props.nextFlag) {
// 如果结束时间早于当前日期则按钮可用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,
timeFlag: timeFlag.value
})
// preClick 操作后不执行按钮状态检查
if (!isUserAction) {
checkButtonStatus()
}
})
}
// 选择时间范围
@@ -182,39 +181,15 @@ const timeChange = (e: number) => {
timeFlag.value = 1
}
// 检查按钮状态
checkButtonStatus()
nextTick(() => {
// 检查按钮状态
checkInitialButtonStatus()
})
// 触发 change 事件
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 = () => {
// console.log(interval.value, '000000000')
@@ -282,10 +257,8 @@ const preClick = () => {
// var temp = NowgetEndTime()
// timeStatus(temp, endTime)
// 触发 change 事件,但临时标记为用户操作
isUserAction = true
// 触发 change 事件
emitChange()
isUserAction = false
}
//下一个
const next = () => {