ソースを参照

docs: popup overlay swiper

suzigang 3 年 前
コミット
a0269bc38a

+ 1 - 1
src/packages/__VUE/overlay/doc.en-US.md

@@ -239,7 +239,7 @@ Set `close on click override` to control whether the click mask is closed. If it
 | ---------------------- | ---------------- | -------------- | ------ |
 | v-model:visible        | Control the display/hide of masks | boolean        | `false`  |
 | z-index                | Custom Mask Level         | string, number | `2000`   |
-| duration               | Display/hide animation duration, in seconds | string, string | `0.3`    |
+| duration               | Display/hide animation duration, in seconds | string, number | `0.3`    |
 | overlay-class          | Custom mask class name   | string         | -      |
 | overlay-style          | Custom Mask Style   | CSSProperties  | -      |
 | lock-scroll            | Whether the background is locked when the mask is displayed     | boolean        | `false`  |

+ 1 - 1
src/packages/__VUE/overlay/doc.md

@@ -237,7 +237,7 @@ app.use(Overlay);
 | ---------------------- | ---------------- | -------------- | ------ |
 | v-model:visible        | 控制遮罩的显示/隐藏 | boolean        | `false`  |
 | z-index                | 自定义遮罩层级         | string, number | `2000`   |
-| duration               | 显示/隐藏的动画时长,单位秒 | string, string | `0.3`    |
+| duration               | 显示/隐藏的动画时长,单位秒 | string, number | `0.3`    |
 | overlay-class          | 自定义遮罩类名   | string         | -      |
 | overlay-style          | 自定义遮罩样式   | CSSProperties  | -      |
 | lock-scroll            | 遮罩显示时的背景是否锁定     | boolean        | `false`  |

+ 1 - 1
src/packages/__VUE/overlay/doc.taro.md

@@ -237,7 +237,7 @@ app.use(Overlay);
 | ---------------------- | ---------------- | -------------- | ------ |
 | v-model:visible        | 控制遮罩的显示/隐藏 | boolean        | `false`  |
 | z-index                | 自定义遮罩层级         | string, number | `2000`   |
-| duration               | 显示/隐藏的动画时长,单位秒 | string, string | `0.3`    |
+| duration               | 显示/隐藏的动画时长,单位秒 | string, number | `0.3`    |
 | overlay-class          | 自定义遮罩类名   | string         | -      |
 | overlay-style          | 自定义遮罩样式   | CSSProperties  | -      |
 | lock-scroll            | 遮罩显示时的背景是否锁定     | boolean        | `false`  |

+ 2 - 0
src/packages/__VUE/popup/doc.en-US.md

@@ -225,6 +225,8 @@ Specify the mount node through `teleport`
 | round                  | Show fillet                                                | boolean        | `false`       |
 | teleport               | Specify the mount node   | string         | `"body"`      |
 | teleport-disable              | Whether the node is allowed to be mounted       | boolean         | `false`      |
+| overlay-class          | Custom mask class name   | string         | -      |
+| overlay-style          | Custom Mask Style   | CSSProperties  | -      |
 | safe-area-inset-bottom	| Whether to enable iPhone series full screen bottom safety zone adaptation, which is only valid when `position` is  `bottom` |	Boolean	|`false`     |
 
 ### Events

+ 2 - 0
src/packages/__VUE/popup/doc.md

@@ -223,6 +223,8 @@ app.use(Popup)
 | round                  | 是否显示圆角                                                |boolean        | `false`       |
 | teleport               | 指定挂载节点                                               | string         | `"body"`      |
 | teleport-disable              | 是否允许挂载节点                 | boolean         | `false`      |
+| overlay-class       | 自定义遮罩层类名 | string  | ''  |
+| overlay-style       | 自定义遮罩层样式  | string  | ''  |
 | safe-area-inset-bottom	| 是否开启 iphone 系列全面屏底部安全区适配,仅当 `position` 为 `bottom` 时有效 |	boolean	|`false`     |
 
 ### Events

+ 2 - 0
src/packages/__VUE/popup/doc.taro.md

@@ -217,6 +217,8 @@ app.use(Popup)
 | close-icon             | [图标名称](#/zh-CN/component/icon) 或图片链接                                                  | string         | `"close"`     |
 | destroy-on-close       | 弹层关闭后 `slot`内容会不会清空                                          | boolean        | `true`        |
 | round                  | 是否显示圆角                                                |boolean        | `false`       |
+| overlay-class       | 自定义遮罩层类名 | string  | ''  |
+| overlay-style       | 自定义遮罩层样式  | string  | ''  |
 | safe-area-inset-bottom	| 是否开启 iphone 系列全面屏底部安全区适配,仅当 `position` 为 `bottom` 时有效 |	boolean	|`false`     |
 
 ### Events

+ 2 - 0
src/packages/__VUE/popup/index.taro.vue

@@ -7,6 +7,8 @@
       :z-index="zIndex"
       :lock-scroll="lockScroll"
       :duration="duration"
+      :overlay-class="overlayClass"
+      :overlay-style="overlayStyle"
       @click="onClickOverlay"
       v-bind="$attrs"
     />

+ 2 - 0
src/packages/__VUE/popup/index.vue

@@ -7,6 +7,8 @@
       :z-index="zIndex"
       :lock-scroll="lockScroll"
       :duration="duration"
+      :overlay-class="overlayClass"
+      :overlay-style="overlayStyle"
       @click="onClickOverlay"
       v-bind="$attrs"
     />

+ 7 - 0
src/packages/__VUE/popup/props.ts

@@ -71,5 +71,12 @@ export const popupProps = {
   safeAreaInsetBottom: {
     type: Boolean,
     default: false
+  },
+  overlayClass: {
+    type: String,
+    default: ''
+  },
+  overlayStyle: {
+    type: Object as PropType<CSSProperties>
   }
 };

+ 0 - 23
src/packages/__VUE/swiper/demo.vue

@@ -84,29 +84,6 @@
         </nut-swiper-item>
       </nut-swiper>
     </view>
-    <h2>{{ translate('horizontalCenter') }}</h2>
-    <view class="demo-box">
-      <nut-swiper :init-page="page4" :loop="false" width="280" height="150" :is-center="true" style="height: 150px">
-        <nut-swiper-item v-for="item in list" :key="item">
-          <img :src="item" alt="" />
-        </nut-swiper-item>
-      </nut-swiper>
-    </view>
-    <h2>{{ translate('verticalCenter') }}</h2>
-    <view class="demo-box vertical-center">
-      <nut-swiper
-        :init-page="page4"
-        :loop="false"
-        direction="vertical"
-        height="220"
-        :is-center="true"
-        style="height: 300px"
-      >
-        <nut-swiper-item v-for="item in list" :key="item">
-          <img :src="item" alt="" />
-        </nut-swiper-item>
-      </nut-swiper>
-    </view>
   </div>
 </template>
 

+ 0 - 1
src/packages/__VUE/swiper/doc.en-US.md

@@ -531,7 +531,6 @@ You can manually switch through `api` (`prev`, `next`)
 | touchable             | if touchable to slide                                                      | Boolean         | true          |
 | is-preventDefault                  | Disable default events during sliding                                              | Boolean  | true           |
 | is-stopPropagation               | Is bubbling prohibited during sliding                    | Boolean         | true    |
-| is-center| The corresponding `width` and `height` must be passed to determine whether to display in the middle`  | Boolean   | false    |
 
 
 

+ 0 - 1
src/packages/__VUE/swiper/doc.md

@@ -533,7 +533,6 @@ app.use(SwiperItem);
 | touchable             | 是否可触摸滑动                                                      | Boolean         | true          |
 | is-preventDefault                  | 滑动过程中是否禁用默认事件                                              | Boolean  | true           |
 | is-stopPropagation               | 滑动过程中是否禁止冒泡                    | Boolean         | true    |
-| is-center               | 是否居中展示,必须传对应的`width` 和 `height`                    | Boolean         | false    |
 
 
 

+ 0 - 1
src/packages/__VUE/swiper/doc.taro.md

@@ -533,7 +533,6 @@ app.use(SwiperItem);
 | touchable             | 是否可触摸滑动                                                      | Boolean         | true          |
 | is-preventDefault                  | 滑动过程中是否禁用默认事件                                              | Boolean  | true           |
 | is-stopPropagation               | 滑动过程中是否禁止冒泡                    | Boolean         | true    |
-| is-center               | 是否居中展示,必须传对应的`width` 和 `height`                    | Boolean         | false    |
 
 
 

+ 57 - 79
src/packages/__VUE/swiper/index.taro.vue

@@ -9,23 +9,11 @@
     @touchcancel="onTouchEnd"
     :catch-move="isPreventDefault"
   >
-    <view
-      :class="{
-        [`${componentName}-inner`]: true,
-        [`${componentName}-vertical`]: isVertical
-      }"
-      :style="state.style"
-    >
+    <view :class="classesInner" :style="state.style">
       <slot></slot>
     </view>
     <slot name="page"></slot>
-    <view
-      :class="{
-        [`${componentName}-pagination`]: true,
-        [`${componentName}-pagination-vertical`]: isVertical
-      }"
-      v-if="paginationVisible && !slots.page"
-    >
+    <view :class="classesPagination" v-if="paginationVisible && !$slots.page">
       <i
         :style="{
           backgroundColor: activePagination === index ? paginationColor : '#ddd'
@@ -52,9 +40,11 @@ import {
   VNode
 } from 'vue';
 import { createComponent } from '@/packages/utils/create';
-import { useTouch } from './use-touch';
+import { useTouch } from '@/packages/utils/useTouch/index';
 import { useTaroRect } from '@/packages/utils/useTaroRect';
 import { useExpose } from '@/packages/utils/useExpose/index';
+import requestAniFrame from '@/packages/utils/raf';
+import { clamp } from '@/packages/utils/util';
 import Taro, { eventCenter, getCurrentInstance } from '@tarojs/taro';
 const { create, componentName } = createComponent('swiper');
 export default create({
@@ -68,7 +58,7 @@ export default create({
       default: 0
     },
     direction: {
-      type: [String],
+      type: String,
       default: 'horizontal' //horizontal and vertical
     },
     paginationVisible: {
@@ -106,10 +96,6 @@ export default create({
     isStopPropagation: {
       type: Boolean,
       default: true
-    },
-    isCenter: {
-      type: Boolean,
-      default: false
     }
   },
   emits: ['change'],
@@ -143,12 +129,28 @@ export default create({
 
     const isVertical = computed(() => props.direction === 'vertical');
 
+    const classesInner = computed(() => {
+      const prefixCls = componentName;
+      return {
+        [`${prefixCls}-inner`]: true,
+        [`${prefixCls}-vertical`]: isVertical.value
+      };
+    });
+
+    const classesPagination = computed(() => {
+      const prefixCls = componentName;
+      return {
+        [`${prefixCls}-pagination`]: true,
+        [`${prefixCls}-pagination-vertical`]: isVertical.value
+      };
+    });
+
     const delTa = computed(() => {
-      return isVertical.value ? touch.state.deltaY : touch.state.deltaX;
+      return isVertical.value ? touch.deltaY.value : touch.deltaX.value;
     });
 
     const isCorrectDirection = computed(() => {
-      return touch.state.direction === props.direction;
+      return touch.direction.value === props.direction;
     });
 
     const childCount = computed(() => state.children.length);
@@ -169,14 +171,7 @@ export default create({
 
     const getStyle = () => {
       let offset = 0;
-      if (!props.isCenter) {
-        offset = state.offset;
-      } else {
-        let val = isVertical.value
-          ? (state.rect as DOMRect).height - size.value
-          : (state.rect as DOMRect).width - size.value;
-        offset = state.offset + (state.active === childCount.value - 1 ? -val / 2 : val / 2);
-      }
+      offset = state.offset;
       state.style = {
         transitionDuration: `${state.moving ? 0 : props.duration}ms`,
         transform: `translate${isVertical.value ? 'Y' : 'X'}(${offset}px)`,
@@ -187,26 +182,27 @@ export default create({
 
     const relation = (child: ComponentInternalInstance) => {
       let children = [] as VNode[];
+      const childrenVNodeLen = state.childrenVNode.length;
       let slot = slots?.default?.() as VNode[];
       slot = slot.filter((item: VNode) => item.children && Array.isArray(item.children));
       slot.forEach((item: VNode) => {
         children = children.concat(item.children as VNode[]);
       });
-      if (!state.childrenVNode.length) {
+      if (!childrenVNodeLen) {
         state.childrenVNode = children.slice();
         child.proxy && state.children.push(child.proxy);
       } else {
-        if (state.childrenVNode.length > children.length) {
+        if (childrenVNodeLen > children.length) {
           state.children = state.children.filter((item: ComponentPublicInstance) => child.proxy !== item);
-        } else if (state.childrenVNode.length < children.length) {
-          for (let i = 0; i < state.childrenVNode.length; i++) {
+        } else if (childrenVNodeLen < children.length) {
+          for (let i = 0; i < childrenVNodeLen; i++) {
             if ((children[i] as VNode).key !== (state.childrenVNode[i] as VNode).key) {
               child.proxy && state.children.splice(i, 0, child.proxy);
               child.vnode && state.childrenVNode.splice(i, 0, child.vnode);
               break;
             }
           }
-          if (state.childrenVNode.length !== children.length) {
+          if (childrenVNodeLen !== children.length) {
             child.proxy && state.children.push(child.proxy);
             child.vnode && state.childrenVNode.push(child.vnode);
           }
@@ -217,14 +213,6 @@ export default create({
       }
     };
 
-    const range = (num: number, min: number, max: number) => {
-      return Math.min(Math.max(num, min), max);
-    };
-
-    const requestFrame = (fn: FrameRequestCallback) => {
-      requestAnimationFrame.call(null, fn);
-    };
-
     const getOffset = (active: number, offset = 0) => {
       let currentPosition = active * size.value;
       if (!props.loop) {
@@ -233,7 +221,7 @@ export default create({
 
       let targetOffset = offset - currentPosition;
       if (!props.loop) {
-        targetOffset = range(targetOffset, minOffset.value, 0);
+        targetOffset = clamp(targetOffset, minOffset.value, 0);
       }
 
       return targetOffset;
@@ -243,9 +231,9 @@ export default create({
       const { active } = state;
       if (pace) {
         if (props.loop) {
-          return range(active + pace, -1, childCount.value);
+          return clamp(active + pace, -1, childCount.value);
         }
-        return range(active + pace, 0, childCount.value - 1);
+        return clamp(active + pace, 0, childCount.value - 1);
       }
       return active;
     };
@@ -294,34 +282,27 @@ export default create({
       clearTimeout(state.autoplayTimer);
     };
 
-    const prev = () => {
+    const jump = (pace: number) => {
       resettPosition();
       touch.reset();
 
-      requestFrame(() => {
-        requestFrame(() => {
+      requestAniFrame(() => {
+        requestAniFrame(() => {
           state.moving = false;
           move({
-            pace: -1,
+            pace,
             isEmit: true
           });
         });
       });
     };
 
-    const next = () => {
-      resettPosition();
-      touch.reset();
+    const prev = () => {
+      jump(-1);
+    };
 
-      requestFrame(() => {
-        requestFrame(() => {
-          state.moving = false;
-          move({
-            pace: 1,
-            isEmit: true
-          });
-        });
-      });
+    const next = () => {
+      jump(1);
     };
 
     const to = (index: number) => {
@@ -329,19 +310,17 @@ export default create({
 
       touch.reset();
 
-      requestFrame(() => {
-        requestFrame(() => {
-          state.moving = false;
-          let targetIndex;
-          if (props.loop && childCount.value === index) {
-            targetIndex = state.active === 0 ? 0 : index;
-          } else {
-            targetIndex = index % childCount.value;
-          }
-          move({
-            pace: targetIndex - state.active,
-            isEmit: true
-          });
+      requestAniFrame(() => {
+        state.moving = false;
+        let targetIndex;
+        if (props.loop && childCount.value === index) {
+          targetIndex = state.active === 0 ? 0 : index;
+        } else {
+          targetIndex = index % childCount.value;
+        }
+        move({
+          pace: targetIndex - state.active,
+          isEmit: true
         });
       });
     };
@@ -400,7 +379,7 @@ export default create({
 
       if (isShouldMove && isCorrectDirection.value) {
         let pace = 0;
-        const offset = isVertical.value ? touch.state.offsetY : touch.state.offsetX;
+        const offset = isVertical.value ? touch.offsetY.value : touch.offsetX.value;
         if (props.loop) {
           pace = offset > 0 ? (delTa.value > 0 ? -1 : 1) : 0;
         } else {
@@ -475,10 +454,9 @@ export default create({
       state,
       refRandomId,
       classes,
+      classesPagination,
+      classesInner,
       container,
-      componentName,
-      isVertical,
-      slots,
       activePagination,
       onTouchStart,
       onTouchMove,

+ 57 - 75
src/packages/__VUE/swiper/index.vue

@@ -7,23 +7,11 @@
     @touchend="onTouchEnd"
     @touchcancel="onTouchEnd"
   >
-    <view
-      :class="{
-        [`${componentName}-inner`]: true,
-        [`${componentName}-vertical`]: isVertical
-      }"
-      :style="state.style"
-    >
+    <view :class="classesInner" :style="state.style">
       <slot></slot>
     </view>
     <slot name="page"></slot>
-    <view
-      :class="{
-        [`${componentName}-pagination`]: true,
-        [`${componentName}-pagination-vertical`]: isVertical
-      }"
-      v-if="paginationVisible && !slots.page"
-    >
+    <view :class="classesPagination" v-if="paginationVisible && !$slots.page">
       <i
         :style="{
           backgroundColor: activePagination === index ? paginationColor : '#ddd'
@@ -51,8 +39,10 @@ import {
   VNode
 } from 'vue';
 import { createComponent } from '@/packages/utils/create';
-import { useTouch } from './use-touch';
+import { useTouch } from '@/packages/utils/useTouch/index';
 import { useExpose } from '@/packages/utils/useExpose/index';
+import { clamp } from '@/packages/utils/util';
+import requestAniFrame from '@/packages/utils/raf';
 const { create, componentName } = createComponent('swiper');
 export default create({
   props: {
@@ -65,7 +55,7 @@ export default create({
       default: 0
     },
     direction: {
-      type: [String],
+      type: String,
       default: 'horizontal' //horizontal and vertical
     },
     paginationVisible: {
@@ -139,12 +129,28 @@ export default create({
 
     const isVertical = computed(() => props.direction === 'vertical');
 
+    const classesInner = computed(() => {
+      const prefixCls = componentName;
+      return {
+        [`${prefixCls}-inner`]: true,
+        [`${prefixCls}-vertical`]: isVertical.value
+      };
+    });
+
+    const classesPagination = computed(() => {
+      const prefixCls = componentName;
+      return {
+        [`${prefixCls}-pagination`]: true,
+        [`${prefixCls}-pagination-vertical`]: isVertical.value
+      };
+    });
+
     const delTa = computed(() => {
-      return isVertical.value ? touch.state.deltaY : touch.state.deltaX;
+      return isVertical.value ? touch.deltaY.value : touch.deltaX.value;
     });
 
     const isCorrectDirection = computed(() => {
-      return touch.state.direction === props.direction;
+      return touch.direction.value === props.direction;
     });
 
     const childCount = computed(() => state.children.length);
@@ -165,14 +171,7 @@ export default create({
 
     const getStyle = () => {
       let offset = 0;
-      if (!props.isCenter) {
-        offset = state.offset;
-      } else {
-        let val = isVertical.value
-          ? (state.rect as DOMRect).height - size.value
-          : (state.rect as DOMRect).width - size.value;
-        offset = state.offset + (state.active === childCount.value - 1 ? -val / 2 : val / 2);
-      }
+      offset = state.offset;
       state.style = {
         transitionDuration: `${state.moving ? 0 : props.duration}ms`,
         transform: `translate${isVertical.value ? 'Y' : 'X'}(${offset}px)`,
@@ -183,26 +182,27 @@ export default create({
 
     const relation = (child: ComponentInternalInstance) => {
       let children = [] as VNode[];
+      const childrenVNodeLen = state.childrenVNode.length;
       let slot = slots?.default?.() as VNode[];
       slot = slot.filter((item: VNode) => item.children && Array.isArray(item.children));
       slot.forEach((item: VNode) => {
         children = children.concat(item.children as VNode[]);
       });
-      if (!state.childrenVNode.length) {
+      if (!childrenVNodeLen) {
         state.childrenVNode = children.slice();
         child.proxy && state.children.push(child.proxy);
       } else {
-        if (state.childrenVNode.length > children.length) {
+        if (childrenVNodeLen > children.length) {
           state.children = state.children.filter((item: ComponentPublicInstance) => child.proxy !== item);
-        } else if (state.childrenVNode.length < children.length) {
-          for (let i = 0; i < state.childrenVNode.length; i++) {
+        } else if (childrenVNodeLen < children.length) {
+          for (let i = 0; i < childrenVNodeLen; i++) {
             if ((children[i] as VNode).key !== (state.childrenVNode[i] as VNode).key) {
               child.proxy && state.children.splice(i, 0, child.proxy);
               child.vnode && state.childrenVNode.splice(i, 0, child.vnode);
               break;
             }
           }
-          if (state.childrenVNode.length !== children.length) {
+          if (childrenVNodeLen !== children.length) {
             child.proxy && state.children.push(child.proxy);
             child.vnode && state.childrenVNode.push(child.vnode);
           }
@@ -213,14 +213,6 @@ export default create({
       }
     };
 
-    const range = (num: number, min: number, max: number) => {
-      return Math.min(Math.max(num, min), max);
-    };
-
-    const requestFrame = (fn: FrameRequestCallback) => {
-      window.requestAnimationFrame.call(window, fn);
-    };
-
     const getOffset = (active: number, offset = 0) => {
       let currentPosition = active * size.value;
       if (!props.loop) {
@@ -229,7 +221,7 @@ export default create({
 
       let targetOffset = offset - currentPosition;
       if (!props.loop) {
-        targetOffset = range(targetOffset, minOffset.value, 0);
+        targetOffset = clamp(targetOffset, minOffset.value, 0);
       }
 
       // console.log(offset, currentPosition, targetOffset);
@@ -241,9 +233,9 @@ export default create({
       const { active } = state;
       if (pace) {
         if (props.loop) {
-          return range(active + pace, -1, childCount.value);
+          return clamp(active + pace, -1, childCount.value);
         }
-        return range(active + pace, 0, childCount.value - 1);
+        return clamp(active + pace, 0, childCount.value - 1);
       }
       return active;
     };
@@ -292,34 +284,27 @@ export default create({
       clearTimeout(state.autoplayTimer);
     };
 
-    const prev = () => {
+    const jump = (pace: number) => {
       resettPosition();
       touch.reset();
 
-      requestFrame(() => {
-        requestFrame(() => {
+      requestAniFrame(() => {
+        requestAniFrame(() => {
           state.moving = false;
           move({
-            pace: -1,
+            pace,
             isEmit: true
           });
         });
       });
     };
 
-    const next = () => {
-      resettPosition();
-      touch.reset();
+    const prev = () => {
+      jump(-1);
+    };
 
-      requestFrame(() => {
-        requestFrame(() => {
-          state.moving = false;
-          move({
-            pace: 1,
-            isEmit: true
-          });
-        });
-      });
+    const next = () => {
+      jump(1);
     };
 
     const to = (index: number) => {
@@ -327,19 +312,17 @@ export default create({
 
       touch.reset();
 
-      requestFrame(() => {
-        requestFrame(() => {
-          state.moving = false;
-          let targetIndex;
-          if (props.loop && childCount.value === index) {
-            targetIndex = state.active === 0 ? 0 : index;
-          } else {
-            targetIndex = index % childCount.value;
-          }
-          move({
-            pace: targetIndex - state.active,
-            isEmit: true
-          });
+      requestAniFrame(() => {
+        state.moving = false;
+        let targetIndex;
+        if (props.loop && childCount.value === index) {
+          targetIndex = state.active === 0 ? 0 : index;
+        } else {
+          targetIndex = index % childCount.value;
+        }
+        move({
+          pace: targetIndex - state.active,
+          isEmit: true
         });
       });
     };
@@ -396,7 +379,7 @@ export default create({
 
       if (isShouldMove && isCorrectDirection.value) {
         let pace = 0;
-        const offset = isVertical.value ? touch.state.offsetY : touch.state.offsetX;
+        const offset = isVertical.value ? touch.offsetY.value : touch.offsetX.value;
         if (props.loop) {
           pace = offset > 0 ? (delTa.value > 0 ? -1 : 1) : 0;
         } else {
@@ -462,10 +445,9 @@ export default create({
     return {
       state,
       classes,
+      classesInner,
+      classesPagination,
       container,
-      componentName,
-      isVertical,
-      slots,
       activePagination,
       onTouchStart,
       onTouchMove,

+ 0 - 55
src/packages/__VUE/swiper/use-touch.ts

@@ -1,55 +0,0 @@
-import { reactive } from 'vue';
-
-const DISTANCE = 5;
-
-type Direction = 'horizontal' | 'vertical' | '';
-
-export function useTouch() {
-  const state = reactive({
-    startX: 0,
-    startY: 0,
-    deltaX: 0,
-    deltaY: 0,
-    offsetX: 0,
-    offsetY: 0,
-    direction: '' as Direction
-  });
-  const getDirection = (x: number, y: number) => {
-    if (x > y && x > DISTANCE) return 'horizontal';
-    if (y > x && y > DISTANCE) return 'vertical';
-    return '';
-  };
-  const reset = () => {
-    state.startX = 0;
-    state.startY = 0;
-    state.deltaX = 0;
-    state.deltaY = 0;
-    state.offsetX = 0;
-    state.offsetY = 0;
-    state.direction = '';
-  };
-
-  const start = ((e: TouchEvent) => {
-    reset();
-    state.startX = e.touches[0].clientX;
-    state.startY = e.touches[0].clientY;
-  }) as EventListener;
-
-  const move = ((e: TouchEvent) => {
-    state.deltaX = e.touches[0].clientX - state.startX;
-    state.deltaY = e.touches[0].clientY - state.startY;
-    state.offsetX = Math.abs(state.deltaX);
-    state.offsetY = Math.abs(state.deltaY);
-
-    if (!state.direction) {
-      state.direction = getDirection(state.offsetX, state.offsetY);
-    }
-  }) as EventListener;
-
-  return {
-    state,
-    start,
-    reset,
-    move
-  };
-}

+ 1 - 0
src/sites/mobile-taro/vue/src/app.ts

@@ -3,6 +3,7 @@ import './app.scss';
 import NutUI from '../../../../packages/nutui.taro.vue';
 // import NutUI from '@nutui/nutui-taro';
 // import '@nutui/nutui-taro/dist/style.css';
+import '../../../../packages/utils/touchEmulator'; // 适配 taro h5 示例桌面端预览
 const App = createApp({
   onShow(options) {}
   // 入口组件不需要实现 render 方法,即使实现了也会被 taro所覆盖

+ 0 - 23
src/sites/mobile-taro/vue/src/exhibition/pages/swiper/index.vue

@@ -86,29 +86,6 @@
         </nut-swiper-item>
       </nut-swiper>
     </view>
-    <h2>水平居中展示</h2>
-    <view class="demo-box">
-      <nut-swiper :init-page="page4" :loop="false" width="280" height="150" :is-center="true" style="height: 150px">
-        <nut-swiper-item v-for="item in list" :key="item">
-          <img :src="item" alt="" />
-        </nut-swiper-item>
-      </nut-swiper>
-    </view>
-    <h2>垂直居中展示</h2>
-    <view class="demo-box vertical-center">
-      <nut-swiper
-        :init-page="page4"
-        :loop="false"
-        direction="vertical"
-        height="220"
-        :is-center="true"
-        style="height: 300px"
-      >
-        <nut-swiper-item v-for="item in list" :key="item">
-          <img :src="item" alt="" />
-        </nut-swiper-item>
-      </nut-swiper>
-    </view>
   </div>
 </template>