Browse Source

fix: 修复 imagepreview 动态设置 initNo 显示不正确问题 #1849 && InfiniteLoading 某些情况下会错误触发下拉刷新#1819 (#1853)

yangxiaolu1993 3 years ago
parent
commit
e472f19102

+ 10 - 1
src/packages/__VUE/imagepreview/index.taro.vue

@@ -169,7 +169,7 @@ export default create({
       state.showPop = false;
       state.store.scale = 1;
       scaleNow();
-      state.active = 1;
+      // state.active = 1;
       emit('close');
     };
 
@@ -290,6 +290,15 @@ export default create({
       }
     );
 
+    watch(
+      () => props.initNo,
+      (val) => {
+        if (val != state.active) {
+          state.active = val;
+        }
+      }
+    );
+
     const initPage = computed(() => {
       const maxNo = props.images.length;
       const _initPage = props.initNo > maxNo ? maxNo - 1 : props.initNo - 1;

+ 10 - 1
src/packages/__VUE/imagepreview/index.vue

@@ -191,7 +191,7 @@ export default create({
     // 执行关闭
     const closeDone = () => {
       state.showPop = false;
-      state.active = 1;
+      // state.active = 1;
       emit('close');
     };
 
@@ -215,6 +215,15 @@ export default create({
       }
     );
 
+    watch(
+      () => props.initNo,
+      (val) => {
+        if (val != state.active) {
+          state.active = val;
+        }
+      }
+    );
+
     const initPage = computed(() => {
       const maxNo = props.images.length + props.videos.length;
       const _initPage = props.initNo > maxNo ? maxNo - 1 : props.initNo - 1;

+ 12 - 1
src/packages/__VUE/infiniteloading/index.vue

@@ -42,6 +42,8 @@ import {
 } from 'vue';
 import { createComponent } from '@/packages/utils/create';
 const { componentName, create, translate } = createComponent('infiniteloading');
+import { useTouch } from '@/packages/utils/useTouch';
+
 export default create({
   props: {
     hasMore: {
@@ -92,6 +94,7 @@ export default create({
   emits: ['scroll-change', 'load-more', 'refresh'],
 
   setup(props, { emit, slots }) {
+    const touch: any = useTouch();
     const state = reactive({
       scrollEl: window as Window | HTMLElement | (Node & ParentNode),
       scroller: null as null | HTMLElement,
@@ -198,6 +201,8 @@ export default create({
     };
 
     const touchStart = (event: TouchEvent) => {
+      touch.start(event);
+
       if (state.beforeScrollTop == 0 && !state.isTouching && props.isOpenRefresh) {
         state.y = event.touches[0].pageY;
         state.isTouching = true;
@@ -208,9 +213,11 @@ export default create({
     };
 
     const touchMove = (event: TouchEvent) => {
+      touch.move(event);
+
       state.distance = event.touches[0].pageY - state.y;
 
-      if (state.distance > 0 && state.isTouching) {
+      if ((touch as any).isVertical() && state.distance > 0 && state.isTouching) {
         event.preventDefault();
         if (state.distance >= state.refreshMaxH) state.distance = state.refreshMaxH;
       } else {
@@ -227,6 +234,10 @@ export default create({
           emit('refresh', refreshDone);
         }
       }
+
+      setTimeout(() => {
+        touch.reset();
+      }, 0);
     };
 
     // 滚动监听对象