Browse Source

feat(swipe): add props prevent-default、stop-propagation

richard1015 4 years ago
parent
commit
899aedb113

+ 6 - 5
src/packages/__VUE/swipe/doc.md

@@ -125,11 +125,12 @@ app.use(Swipe);
 
 ### Props
 
-| 参数     | 说明         | 类型   | 默认值 |
-|----------|--------------|--------|--------|
-| name     | 唯一标识     | String | -      |
-| disabled | 是否禁用滑动 | String | false  |
-
+| 参数                     | 说明                 | 类型    | 默认值 |
+|--------------------------|----------------------|---------|--------|
+| name                     | 唯一标识             | String  | -      |
+| disabled                 | 是否禁用滑动         | String  | false  |
+| touch-move-prevent-default  | 是否阻止滑动事件行为 | boolean | false  |
+| touch-move-stop-propagation | 是否阻止滑动事件冒泡 | boolean | false  |
 ### Events
 
 | 事件名 | 说明       | 回调参数               |

+ 16 - 3
src/packages/__VUE/swipe/index.taro.vue

@@ -34,6 +34,14 @@ export default create({
       type: String,
       default: ''
     },
+    touchMoveStopPropagation: {
+      type: Boolean,
+      default: false
+    },
+    touchMovePreventDefault: {
+      type: Boolean,
+      default: false
+    },
     disabled: {
       type: Boolean,
       default: false
@@ -136,11 +144,16 @@ export default create({
       },
       async onTouchMove(event: Event) {
         if (props.disabled) return;
-        if (touch.isVertical() == false) {
+        touch.move(event);
+        if (touch.isHorizontal()) {
           state.moving = true;
-          touch.move(event);
           setoffset(touch.deltaX.value);
-          event.preventDefault();
+          if (props.touchMovePreventDefault) {
+            event.preventDefault();
+          }
+          if (props.touchMoveStopPropagation) {
+            event.stopPropagation();
+          }
         }
       },
       onTouchEnd() {

+ 18 - 12
src/packages/__VUE/swipe/index.vue

@@ -33,6 +33,14 @@ export default create({
       type: String,
       default: ''
     },
+    touchMoveStopPropagation: {
+      type: Boolean,
+      default: false
+    },
+    touchMovePreventDefault: {
+      type: Boolean,
+      default: false
+    },
     disabled: {
       type: Boolean,
       default: false
@@ -104,20 +112,14 @@ export default create({
           if (opened && oldPosition === position) {
             offset = -rightRefWidth.value;
           } else {
-            offset =
-              Math.abs(deltaX) > rightRefWidth.value
-                ? -rightRefWidth.value
-                : deltaX;
+            offset = Math.abs(deltaX) > rightRefWidth.value ? -rightRefWidth.value : deltaX;
           }
           break;
         case 'right':
           if (opened && oldPosition === position) {
             offset = leftRefWidth.value;
           } else {
-            offset =
-              Math.abs(deltaX) > leftRefWidth.value
-                ? leftRefWidth.value
-                : deltaX;
+            offset = Math.abs(deltaX) > leftRefWidth.value ? leftRefWidth.value : deltaX;
           }
           break;
       }
@@ -132,12 +134,16 @@ export default create({
       },
       onTouchMove(event: Event) {
         if (props.disabled) return;
-        if (touch.isVertical() == false) {
+        touch.move(event);
+        if (touch.isHorizontal()) {
           state.moving = true;
-          touch.move(event);
           setoffset(touch.deltaX.value);
-
-          event.preventDefault();
+          if (props.touchMovePreventDefault) {
+            event.preventDefault();
+          }
+          if (props.touchMoveStopPropagation) {
+            event.stopPropagation();
+          }
         }
       },
       onTouchEnd() {