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 @@
* @Author: huyue
* @Date: 2024-04-08 11:30:30
* @LastEditors: limin
* @LastEditTime: 2025-12-25 10:46:39
* @LastEditTime: 2025-12-26 19:43:55
-->
<template>
<view class="detail-box" :key="dateilKey">
......@@ -13,7 +13,7 @@
</view>
</view>
<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">
<component @full="handleFull" :detail="item" :is="item.componentName"
:views="item.receptionSourceDetailList || []" :penSwitch="penSwitch" :show="id == item.id"
......@@ -192,8 +192,20 @@ export default {
},
id: {
immediate: true,
handler(newval) {
handler(newval, oldval) {
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: {
......@@ -249,6 +261,16 @@ export default {
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
if (e && e.id) {
const list = (e.folderCode && this.folderMaterialsMap[e.folderCode]) || null
......@@ -379,44 +401,54 @@ export default {
}
},
touchEnd(e) {
if (this.modeName) return
if (this.modeName || this.isAnimating) return
try {
let { pageToolList, drawStatus, startX, screenWidth, id, scaleValueObject, productModelStatus } = this
if (!e || !e.changedTouches || drawStatus || pageToolList.length == 0 || e.changedTouches.length === 0) return
let halfScreenWidth = screenWidth / 2,
touch = e.changedTouches[0],
isDistanceSignificant = Math.abs(touch.pageX - startX) > screenWidth / 6,
index = pageToolList.findIndex(item => item.id == id)
let touch = e.changedTouches[0]
let diffX = touch.pageX - startX
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 (!scaleValueObject[id]) scaleValueObject[id] = 1
if (isDistanceSignificant && index != -1 && scaleValueObject[id] == 1 && !productModelStatus) {
const { nextId, modeName, title } = this.getNextId(index, pageToolList, startX, halfScreenWidth)
this.modeName = modeName
this.$emit('update:id', nextId)
uni.$logger.local.info(`预览${title}`)
setTimeout(() => {
this.modeName = ''
}, 500)
const isNext = diffX < 0
let nextIndex
if (isNext) {
nextIndex = index === pageToolList.length - 1 ? 0 : index + 1
this.pendingDirection = 'next'
} 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) {
console.log(error)
}
},
getNextId(index, pageToolList, startX, halfScreenWidth) {
let nextItem = {},
modeName = ''
if (startX > halfScreenWidth) {
nextItem = index === pageToolList.length - 1 ? pageToolList[0] : pageToolList[index + 1]
modeName = 'to-right'
} else {
nextItem = index === 0 ? pageToolList[pageToolList.length - 1] : pageToolList[index - 1]
modeName = 'to-left'
}
return {
nextId: nextItem.id,
modeName,
title: nextItem.title
}
getViewClass(item) {
const isCurrent = item.id == this.id
const isLast = item.id == this.lastId
if (isCurrent) {
if (this.isAnimating) {
return this.animDirection === 'next' ? 'slide-in-right' : 'slide-in-left'
}
return 'showView'
}
if (isLast && this.isAnimating) {
return this.animDirection === 'next' ? 'slide-out-left' : 'slide-out-right'
}
return ''
},
scale(e) {
let { id } = this
......@@ -524,31 +556,63 @@ export default {
visibility: visible;
}
.to-left {
animation: to-left 0.25s forwards;
.slide-in-right {
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 {
animation: to-right 0.25s forwards;
.slide-out-right {
visibility: visible;
z-index: 1;
animation: slideOutRight 0.6s cubic-bezier(0.25, 1, 0.25, 1.1) forwards;
}
@keyframes to-left {
0% {
left: -100%;
@keyframes slideInRight {
from {
transform: translateX(100%);
}
to {
transform: translateX(0);
}
}
100% {
left: 0;
@keyframes slideInLeft {
from {
transform: translateX(-100%);
}
to {
transform: translateX(0);
}
}
@keyframes to-right {
0% {
left: 100%;
@keyframes slideOutLeft {
from {
transform: translateX(0);
}
to {
transform: translateX(-100%);
}
}
100% {
left: 0;
@keyframes slideOutRight {
from {
transform: translateX(0);
}
to {
transform: translateX(100%);
}
}
</style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!