修复bug

This commit is contained in:
zhouyanli
2026-08-13 14:12:11 +08:00
parent 94146ce27a
commit 32765cc004
12 changed files with 145 additions and 48 deletions

View File

@@ -169,8 +169,21 @@ const form = ref({
// ========== 基础数据 ==========
const timePopupRef = ref(null)
const selectedTime = ref('')
const tempTime = ref(moment().hour(9).minute(30).second(0))
// 默认预约时间:今天(向上取整到下一个整点/半点)
const getDefaultTime = () => {
const t = moment().second(0).millisecond(0)
if (t.minute() > 30) {
t.add(1, 'hour').minute(0)
} else if (t.minute() > 0) {
t.minute(30)
}
return t
}
const selectedTime = ref(getDefaultTime())
const tempTime = ref(getDefaultTime())
form.value.datetime = selectedTime.value.format('YYYY-MM-DD HH:mm')
// ========== 时间选择列数据 ==========
const dateList = ref([
@@ -191,12 +204,15 @@ const minuteList = ref([
])
// ========== 选中状态 ==========
const selectedDate = ref('')
const selectedHour = ref('')
const selectedMinute = ref('')
const selectedDate = ref(selectedTime.value.format('YYYY-MM-DD'))
const selectedHour = ref(selectedTime.value.format('HH'))
const selectedMinute = ref(selectedTime.value.format('mm'))
// ========== 滚动配置 ==========
const itemHeight = 80
// 每项高度 / 可视高度rpx 转 px避免直接用数字导致滚动错位
const itemHeight = uni.upx2px(80)
const visibleHeight = uni.upx2px(400)
const centerOffset = (visibleHeight - itemHeight) / 2
const dateScrollTop = ref(0)
const hourScrollTop = ref(0)
const minuteScrollTop = ref(0)
@@ -242,10 +258,11 @@ const syncScrollPosition = () => {
const dateIdx = dateList.value.findIndex(i => i.value === selectedDate.value)
const hourIdx = hourList.value.findIndex(i => i.time === selectedHour.value)
const minIdx = minuteList.value.findIndex(i => i.minute === selectedMinute.value)
dateScrollTop.value = dateIdx * itemHeight
hourScrollTop.value = hourIdx * itemHeight
minuteScrollTop.value = minIdx * itemHeight
// 让选中项滚动到可视区域居中位置,并限制不小于 0
dateScrollTop.value = dateIdx >= 0 ? Math.max(0, dateIdx * itemHeight - centerOffset) : 0
hourScrollTop.value = hourIdx >= 0 ? Math.max(0, hourIdx * itemHeight - centerOffset) : 0
minuteScrollTop.value = minIdx >= 0 ? Math.max(0, minIdx * itemHeight - centerOffset) : 0
}
// 点击选择日期