Ver código fonte

feat(SwipeView): 为 SwipeView 组件添加点击和删除事件回调

- 在 SwipeView 组件中添加 onItemClick 和 onDelete 属性- 修改 AIDocumentView 中的 SwipeView 使用新增的事件回调- 优化 SwipeView 的点击和删除逻辑,支持外部自定义操作
徐勤民 3 semanas atrás
pai
commit
a872e82cd6
1 arquivos alterados com 23 adições e 3 exclusões
  1. 23 3
      src/main/ets/view/SwipeView.ets

+ 23 - 3
src/main/ets/view/SwipeView.ets

@@ -3,6 +3,8 @@ export struct SwipeView {
   private _scroller: Scroller = new Scroller()
   @State h: Length = 40
   @State downX: number = 0
+  onItemClick?: () => void
+  onDelete?: () => void
 
   @Builder
   doNothingBuilder() {
@@ -15,7 +17,16 @@ export struct SwipeView {
   build() {
     Scroll(this._scroller) {
       Row() {
-        this.customBuilderParam()
+        Column() {
+          this.customBuilderParam()
+        }.width('100%').onClick(() => {
+          this._scroller.scrollTo({
+            xOffset: 0, yOffset: 0,
+            animation: { duration: 100, curve: Curve.Linear }
+          })
+          this.onItemClick && this.onItemClick()
+        })
+
         Text('删除')
           .backgroundColor('red')
           .width(70)
@@ -23,6 +34,13 @@ export struct SwipeView {
           .height(this.h)
           .textAlign(TextAlign.Center)
           .fontSize(16)
+          .onClick(() => {
+            this._scroller.scrollTo({
+              xOffset: 0, yOffset: 0,
+              animation: { duration: 100, curve: Curve.Linear }
+            })
+            this.onDelete && this.onDelete()
+          })
         // if (this.btnBuilder === this.doNothingBuilder) {
         //   Text('删除')
         // }
@@ -59,8 +77,10 @@ export struct SwipeView {
             toxOffset = 70
           }
           // 滑动指定位置,设置动画
-          this._scroller.scrollTo({ xOffset: toxOffset, yOffset: 0,
-            animation: { duration: 300, curve: Curve.Linear } })
+          this._scroller.scrollTo({
+            xOffset: toxOffset, yOffset: 0,
+            animation: { duration: 300, curve: Curve.Linear }
+          })
           // 重置按下的x轴坐标
           this.downX = 0
           break