Commit bd151853 by liimin

feat(equity/detail): 改进滑动切换动画效果并优化方向判断逻辑

重构滑动切换动画效果,使用更流畅的动画曲线和方向判断逻辑:
1. 新增slide-in/slide-out动画类替代旧的to-left/to-right
2. 添加动画方向状态管理(pendingDirection/animDirection)
3. 优化touchEnd处理逻辑,简化方向判断
4. 增加动画过程中禁止重复触发的保护(isAnimating)
1 parent 5372dfcd
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* @Author: huyue * @Author: huyue
* @Date: 2024-04-08 11:30:30 * @Date: 2024-04-08 11:30:30
* @LastEditors: limin * @LastEditors: limin
* @LastEditTime: 2025-12-25 10:46:39 * @LastEditTime: 2025-12-26 19:43:55
--> -->
<template> <template>
<view class="detail-box" :key="dateilKey"> <view class="detail-box" :key="dateilKey">
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
</view> </view>
</view> </view>
<template v-for="(item, index) in moduleList"> <template v-for="(item, index) in moduleList">
<view :class="['view', { showView: id == item.id }, modeName]" :key="index" @touchstart.stop="touchStart" <view :class="['view', getViewClass(item)]" :key="index" @touchstart.stop="touchStart"
@touchend.stop="touchEnd"> @touchend.stop="touchEnd">
<component @full="handleFull" :detail="item" :is="item.componentName" <component @full="handleFull" :detail="item" :is="item.componentName"
:views="item.receptionSourceDetailList || []" :penSwitch="penSwitch" :show="id == item.id" :views="item.receptionSourceDetailList || []" :penSwitch="penSwitch" :show="id == item.id"
...@@ -192,8 +192,20 @@ export default { ...@@ -192,8 +192,20 @@ export default {
}, },
id: { id: {
immediate: true, immediate: true,
handler(newval) { handler(newval, oldval) {
if (!this.pageToolList.length) this.pageToolList = this.toolList if (!this.pageToolList.length) this.pageToolList = this.toolList
if (this.pendingDirection && oldval) {
this.animDirection = this.pendingDirection;
this.lastId = oldval;
this.isAnimating = true;
this.pendingDirection = '';
setTimeout(() => {
this.isAnimating = false;
this.lastId = null;
this.animDirection = '';
}, 500);
}
} }
}, },
media: { media: {
...@@ -249,6 +261,16 @@ export default { ...@@ -249,6 +261,16 @@ export default {
ref && ref.closeAllPopup && ref.closeAllPopup() ref && ref.closeAllPopup && ref.closeAllPopup()
} }
}) })
// 计算切换方向
if (e && e.id && this.id != e.id) {
let currentIndex = this.pageToolList.findIndex(item => item.id == this.id)
let nextIndex = this.pageToolList.findIndex(item => item.id == e.id)
if (currentIndex > -1 && nextIndex > -1) {
this.pendingDirection = nextIndex > currentIndex ? 'next' : 'prev'
}
}
// 选择素材:根据素材所属文件夹更新 moduleList,再切换当前素材 id // 选择素材:根据素材所属文件夹更新 moduleList,再切换当前素材 id
if (e && e.id) { if (e && e.id) {
const list = (e.folderCode && this.folderMaterialsMap[e.folderCode]) || null const list = (e.folderCode && this.folderMaterialsMap[e.folderCode]) || null
...@@ -379,44 +401,54 @@ export default { ...@@ -379,44 +401,54 @@ export default {
} }
}, },
touchEnd(e) { touchEnd(e) {
if (this.modeName) return if (this.modeName || this.isAnimating) return
try { try {
let { pageToolList, drawStatus, startX, screenWidth, id, scaleValueObject, productModelStatus } = this let { pageToolList, drawStatus, startX, screenWidth, id, scaleValueObject, productModelStatus } = this
if (!e || !e.changedTouches || drawStatus || pageToolList.length == 0 || e.changedTouches.length === 0) return if (!e || !e.changedTouches || drawStatus || pageToolList.length == 0 || e.changedTouches.length === 0) return
let halfScreenWidth = screenWidth / 2,
touch = e.changedTouches[0], let touch = e.changedTouches[0]
isDistanceSignificant = Math.abs(touch.pageX - startX) > screenWidth / 6, let diffX = touch.pageX - startX
index = pageToolList.findIndex(item => item.id == id)
let isDistanceSignificant = Math.abs(diffX) > screenWidth / 6
let index = pageToolList.findIndex(item => item.id == id)
if (Math.abs(this.startY - touch.pageY) > 150) return if (Math.abs(this.startY - touch.pageY) > 150) return
if (!scaleValueObject[id]) scaleValueObject[id] = 1 if (!scaleValueObject[id]) scaleValueObject[id] = 1
if (isDistanceSignificant && index != -1 && scaleValueObject[id] == 1 && !productModelStatus) { if (isDistanceSignificant && index != -1 && scaleValueObject[id] == 1 && !productModelStatus) {
const { nextId, modeName, title } = this.getNextId(index, pageToolList, startX, halfScreenWidth) const isNext = diffX < 0
this.modeName = modeName
this.$emit('update:id', nextId) let nextIndex
uni.$logger.local.info(`预览${title}`) if (isNext) {
setTimeout(() => { nextIndex = index === pageToolList.length - 1 ? 0 : index + 1
this.modeName = '' this.pendingDirection = 'next'
}, 500) } else {
nextIndex = index === 0 ? pageToolList.length - 1 : index - 1
this.pendingDirection = 'prev'
}
const nextItem = pageToolList[nextIndex]
this.$emit('update:id', nextItem.id)
uni.$logger.local.info(`预览${nextItem.title}`)
} }
} catch (error) { } catch (error) {
console.log(error) console.log(error)
} }
}, },
getNextId(index, pageToolList, startX, halfScreenWidth) { getViewClass(item) {
let nextItem = {}, const isCurrent = item.id == this.id
modeName = '' const isLast = item.id == this.lastId
if (startX > halfScreenWidth) {
nextItem = index === pageToolList.length - 1 ? pageToolList[0] : pageToolList[index + 1] if (isCurrent) {
modeName = 'to-right' if (this.isAnimating) {
} else { return this.animDirection === 'next' ? 'slide-in-right' : 'slide-in-left'
nextItem = index === 0 ? pageToolList[pageToolList.length - 1] : pageToolList[index - 1]
modeName = 'to-left'
} }
return { return 'showView'
nextId: nextItem.id, }
modeName, if (isLast && this.isAnimating) {
title: nextItem.title return this.animDirection === 'next' ? 'slide-out-left' : 'slide-out-right'
} }
return ''
}, },
scale(e) { scale(e) {
let { id } = this let { id } = this
...@@ -524,31 +556,63 @@ export default { ...@@ -524,31 +556,63 @@ export default {
visibility: visible; visibility: visible;
} }
.to-left { .slide-in-right {
animation: to-left 0.25s forwards; visibility: visible;
z-index: 2;
animation: slideInRight 0.6s cubic-bezier(0.25, 1, 0.25, 1.1) forwards;
}
.slide-in-left {
visibility: visible;
z-index: 2;
animation: slideInLeft 0.6s cubic-bezier(0.25, 1, 0.25, 1.1) forwards;
}
.slide-out-left {
visibility: visible;
z-index: 1;
animation: slideOutLeft 0.6s cubic-bezier(0.25, 1, 0.25, 1.1) forwards;
} }
.to-right { .slide-out-right {
animation: to-right 0.25s forwards; visibility: visible;
z-index: 1;
animation: slideOutRight 0.6s cubic-bezier(0.25, 1, 0.25, 1.1) forwards;
} }
@keyframes to-left { @keyframes slideInRight {
0% { from {
left: -100%; transform: translateX(100%);
}
to {
transform: translateX(0);
} }
}
100% { @keyframes slideInLeft {
left: 0; from {
transform: translateX(-100%);
}
to {
transform: translateX(0);
} }
} }
@keyframes to-right { @keyframes slideOutLeft {
0% { from {
left: 100%; transform: translateX(0);
}
to {
transform: translateX(-100%);
} }
}
100% { @keyframes slideOutRight {
left: 0; from {
transform: translateX(0);
}
to {
transform: translateX(100%);
} }
} }
</style> </style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!