From fbc929fcf841c2a9c2b10ff07c9d17cff3930475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=8B=A4=E6=B0=91?= Date: Thu, 22 May 2025 19:18:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(SwipeView):=20=E4=BC=98=E5=8C=96=E6=BB=91?= =?UTF-8?q?=E5=8A=A8=E8=A7=86=E5=9B=BE=E7=9A=84=E7=82=B9=E5=87=BB=E5=92=8C?= =?UTF-8?q?=E6=BB=9A=E5=8A=A8=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 UUID 生成和本地存储功能,用于唯一标识每个 SwipeView 实例 - 实现点击 ID 变化时自动滚动到起始位置的功能 - 在触摸事件中添加本地存储操作,确保滑动操作的正确性 --- src/main/ets/view/SwipeView.ets | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/ets/view/SwipeView.ets b/src/main/ets/view/SwipeView.ets index 8edf13e..b68d066 100644 --- a/src/main/ets/view/SwipeView.ets +++ b/src/main/ets/view/SwipeView.ets @@ -1,3 +1,5 @@ +import { SZYXLocalStorageHelper, ToolsHelper } from '../../../../Index' + @Component export struct SwipeView { private _scroller: Scroller = new Scroller() @@ -5,6 +7,17 @@ export struct SwipeView { @State downX: number = 0 onItemClick?: () => void onDelete?: () => void + ids: string = ToolsHelper.getUuid() + @LocalStorageLink('XBasicSwipeClick') @Watch('onClickIdChange') clickId: string | undefined = undefined + + onClickIdChange() { + if (this.clickId !== this.ids) { + this._scroller.scrollTo({ + xOffset: 0, yOffset: 0, + animation: { duration: 100, curve: Curve.Linear } + }) + } + } @Builder doNothingBuilder() { @@ -20,6 +33,7 @@ export struct SwipeView { Column() { this.customBuilderParam() }.width('100%').onClick(() => { + // SZYXLocalStorageHelper.storage.setOrCreate('XBasicSwipeClick', this.ids) this._scroller.scrollTo({ xOffset: 0, yOffset: 0, animation: { duration: 100, curve: Curve.Linear } @@ -35,6 +49,7 @@ export struct SwipeView { .textAlign(TextAlign.Center) .fontSize(16) .onClick(() => { + // SZYXLocalStorageHelper.storage.setOrCreate('XBasicSwipeClick', this.ids) this._scroller.scrollTo({ xOffset: 0, yOffset: 0, animation: { duration: 100, curve: Curve.Linear } @@ -58,6 +73,7 @@ export struct SwipeView { // 根据触摸类型判断 switch (event.type) { case TouchType.Down: // 触摸按下 + SZYXLocalStorageHelper.storage.setOrCreate('XBasicSwipeClick', this.ids) // 记录按下的x轴坐标 this.downX = event.touches[0].x break