fix: 修复多个TemplateCard拖拽逻辑冲突问题
问题分析: - 每个TemplateCard都使用相同的CSS选择器 - Taro选择器总是选择页面中第一个匹配元素 - 导致第二个及后续卡片获取到错误的容器信息 - 造成拖拽计算错误,出现不连续的滑动效果 解决方案: - 为每个TemplateCard容器添加唯一ID - 使用ID选择器替代class选择器 - 确保每个卡片获取到正确的容器边界信息 - 保证拖拽计算基于正确的容器尺寸和位置 修复效果: - 所有卡片的拖拽逻辑互不干扰 - 分割线移动精确响应触摸位置 - 解决多实例组件选择器冲突问题
This commit is contained in:
parent
ccdacf2fb4
commit
f37a1e7b81
|
|
@ -14,6 +14,7 @@ export default function TemplateCard({ template, onClick }: TemplateCardProps) {
|
||||||
const [isDragging, setIsDragging] = useState(false)
|
const [isDragging, setIsDragging] = useState(false)
|
||||||
const [containerInfo, setContainerInfo] = useState<any>(null)
|
const [containerInfo, setContainerInfo] = useState<any>(null)
|
||||||
const containerRef = useRef<any>(null)
|
const containerRef = useRef<any>(null)
|
||||||
|
const containerId = `container-${template.code}` // 为每个容器创建唯一ID
|
||||||
|
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
if (!isDragging) {
|
if (!isDragging) {
|
||||||
|
|
@ -25,7 +26,7 @@ export default function TemplateCard({ template, onClick }: TemplateCardProps) {
|
||||||
const getContainerInfo = () => {
|
const getContainerInfo = () => {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const query = Taro.createSelectorQuery()
|
const query = Taro.createSelectorQuery()
|
||||||
query.select('.merged-image-container').boundingClientRect((rect) => {
|
query.select(`#${containerId}`).boundingClientRect((rect) => {
|
||||||
if (rect) {
|
if (rect) {
|
||||||
setContainerInfo(rect)
|
setContainerInfo(rect)
|
||||||
resolve(rect)
|
resolve(rect)
|
||||||
|
|
@ -68,6 +69,7 @@ export default function TemplateCard({ template, onClick }: TemplateCardProps) {
|
||||||
{/* 合成对比图片区域 */}
|
{/* 合成对比图片区域 */}
|
||||||
<View className='image-comparison'>
|
<View className='image-comparison'>
|
||||||
<View
|
<View
|
||||||
|
id={containerId}
|
||||||
className='merged-image-container'
|
className='merged-image-container'
|
||||||
ref={containerRef}
|
ref={containerRef}
|
||||||
onTouchMove={handleTouchMove}
|
onTouchMove={handleTouchMove}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue