smooth exist bug

This commit is contained in:
WindowBird 2025-10-31 14:14:51 +08:00
parent 0ff56a83d4
commit ea139100e6

View File

@ -2,7 +2,7 @@
<!-- 顶部Tabs栏 -->
<uv-tabs :list="topTabs" @click="clickTab"></uv-tabs>
<!-- 内容区域 -->
<view class="content-wrapper" >
<view class="content-wrapper">
<view>
<uv-calendar ref="calendar" mode="single" @confirm="handleConfirm" ></uv-calendar>
<button @click="openCalendar">选择日期</button>
@ -10,8 +10,31 @@
当前选择日期{{ selectedDate }}事件数{{ eventsInDay.length }}
</view>
</view>
<!-- 时间轴表格 -->
<TimeTable :hours="hours" :events="eventsInDay" />
<!-- 滑动容器 -->
<view
class="swipe-container"
@touchstart="handleTouchStart"
@touchmove="handleTouchMove"
@touchend="handleTouchEnd"
>
<view
class="swipe-wrapper"
:style="{ transform: `translateX(${translateX}px)`, transition: isAnimating ? 'transform 0.3s ease-out' : 'none' }"
>
<!-- 昨天的表格 -->
<view class="table-item">
<TimeTable :hours="hours" :events="prevDayEvents" />
</view>
<!-- 今天的表格 -->
<view class="table-item">
<TimeTable :hours="hours" :events="eventsInDay" />
</view>
<!-- 明天的表格 -->
<view class="table-item">
<TimeTable :hours="hours" :events="nextDayEvents" />
</view>
</view>
</view>
</view>
<!-- 悬浮新建按钮 -->
@ -31,7 +54,7 @@
</template>
<script setup>
import { ref, computed, watch } from 'vue';
import { ref, computed, watch, onMounted } from 'vue';
import TimeTable from '@/components/TimeTable.vue';
import FabPlus from '@/components/FabPlus.vue';
@ -68,12 +91,10 @@ yesterday.setDate(yesterday.getDate() - 1);
const yesterdayStr = yesterday.toISOString().slice(0, 10);
const allEvents = ref([
{id:1,title:'今天的日程1',startHour:15,startMin:30,color:'#e3fae6',date:today},
{id:2,title:'今天的日程2',startHour:16,startMin:0,color:'#fae1e1',date:today},
{id:3,title:'今天的日程3',startHour:23,startMin:0,color:'#e3fae6',date:today},
{id:4,title:'明天的日程1',startHour:9,startMin:0,color:'#e3fae6',date:tomorrowStr},
{id:5,title:'明天的日程2',startHour:14,startMin:30,color:'#fae1e1',date:tomorrowStr},
{id:6,title:'昨天的日程',startHour:10,startMin:0,color:'#e3fae6',date:yesterdayStr},
{id:1,title:'今天的日程1',startHour:10,startMin:30,color:'#e3fae6',date:today},
{id:5,title:'明天的日程2',startHour:10,startMin:30,color:'#fae1e1',date:tomorrowStr},
{id:6,title:'昨天的日程3',startHour:10,startMin:30,color:'#e3fae6',date:yesterdayStr},
]);
//
@ -83,6 +104,29 @@ const eventsInDay = computed(() => {
return filtered;
});
//
const prevDate = computed(() => {
const date = new Date(selectedDate.value);
date.setDate(date.getDate() - 1);
return date.toISOString().slice(0, 10);
});
const nextDate = computed(() => {
const date = new Date(selectedDate.value);
date.setDate(date.getDate() + 1);
return date.toISOString().slice(0, 10);
});
//
const prevDayEvents = computed(() => {
return allEvents.value.filter(e => e.date === prevDate.value);
});
//
const nextDayEvents = computed(() => {
return allEvents.value.filter(e => e.date === nextDate.value);
});
// selectedDate
watch(selectedDate, (newDate, oldDate) => {
console.log('selectedDate 发生变化:', oldDate, '->', newDate);
@ -162,6 +206,167 @@ function addEvent(e) {
showAdd.value = false;
}
const value=ref(0);
//
const touchStartX = ref(0);
const touchStartY = ref(0);
const screenWidth = ref(375); // mounted
const translateX = ref(-375); // -375mounted
const baseTranslateX = ref(-375); //
const isAnimating = ref(false); //
const isDragging = ref(false); //
//
const initScreenWidth = () => {
uni.getSystemInfo({
success: (res) => {
const width = res.windowWidth || res.screenWidth || 375;
screenWidth.value = width;
//
if (translateX.value === -375) {
translateX.value = -width;
baseTranslateX.value = -width;
}
}
});
};
//
const handleTouchStart = (e) => {
if (isAnimating.value) return;
const touch = e.touches[0];
touchStartX.value = touch.clientX;
touchStartY.value = touch.clientY;
isDragging.value = true;
baseTranslateX.value = translateX.value; //
};
//
const handleTouchMove = (e) => {
if (!isDragging.value || isAnimating.value) return;
const touch = e.touches[0];
const deltaX = touch.clientX - touchStartX.value;
const deltaY = Math.abs(touch.clientY - touchStartY.value);
//
if (Math.abs(deltaX) > deltaY && Math.abs(deltaX) > 10) {
e.preventDefault();
}
//
translateX.value = baseTranslateX.value + deltaX;
//
const minTranslate = -screenWidth.value * 2; //
const maxTranslate = 0; //
translateX.value = Math.max(minTranslate, Math.min(maxTranslate, translateX.value));
};
//
const handleTouchEnd = (e) => {
if (!isDragging.value || isAnimating.value) return;
const touch = e.changedTouches[0];
const deltaX = touch.clientX - touchStartX.value;
const deltaY = Math.abs(touch.clientY - touchStartY.value);
const minSwipeDistance = screenWidth.value * 0.2; // 20%
//
const isHorizontalSwipe = Math.abs(deltaX) > deltaY && Math.abs(deltaX) > minSwipeDistance;
isDragging.value = false;
if (isHorizontalSwipe) {
//
if (deltaX > 0) {
//
// slideToPreviousDay();
} else {
//
slideToNextDay();
}
} else {
//
resetToCenter();
}
};
//
const resetToCenter = () => {
isAnimating.value = true;
translateX.value = -screenWidth.value;
setTimeout(() => {
isAnimating.value = false;
}, 1000);
};
//
const slideToPreviousDay = () => {
isAnimating.value = true;
// -screenWidth * 2
const targetX = -screenWidth.value*2;
translateX.value = targetX;
setTimeout(() => {
// transition
isAnimating.value = false;
// transition
setTimeout(() => {
//
const currentDate = new Date(selectedDate.value);
currentDate.setDate(currentDate.getDate() - 1);
selectedDate.value = currentDate.toISOString().slice(0, 10);
// prev/next transition
translateX.value = -screenWidth.value;
baseTranslateX.value = -screenWidth.value;
console.log(`日期切换:上一天,新日期:${selectedDate.value}`);
}, 16); // transition
}, 1000);
};
//
const slideToNextDay = () => {
isAnimating.value = true;
// 0
const targetX = 0;
translateX.value = targetX;
setTimeout(() => {
// transition
isAnimating.value = false;
// transition
setTimeout(() => {
//
const currentDate = new Date(selectedDate.value);
currentDate.setDate(currentDate.getDate() + 1);
selectedDate.value = currentDate.toISOString().slice(0, 10);
// prev/next transition
translateX.value = -screenWidth.value;
baseTranslateX.value = -screenWidth.value;
console.log(`日期切换:下一天,新日期:${selectedDate.value}`);
}, 16); // transition
}, 1000);
};
//
watch(selectedDate, () => {
if (!isDragging.value && !isAnimating.value) {
resetToCenter();
}
});
//
onMounted(() => {
initScreenWidth();
});
</script>
<style lang="scss" scoped>
@ -186,6 +391,7 @@ const value=ref(0);
.content-wrapper {
min-height: 100vh;
overflow: hidden;
}
:deep(.bottom-tabbar) { z-index: 1000 !important; }
@ -193,4 +399,23 @@ const value=ref(0);
.schedule-timeline {
padding-bottom: 130rpx !important;
}
.swipe-container {
position: relative;
width: 100%;
overflow: hidden;
touch-action: pan-y; /* 允许垂直滚动,但控制水平滑动 */
}
.swipe-wrapper {
display: flex;
width: 300%; /* 三个表格的宽度 */
will-change: transform; /* 优化性能 */
}
.table-item {
flex: 0 0 33.333%; /* 每个表格占33.333% */
width: 33.333%;
min-width: 0;
}
</style>