shenwu vor 5 Monaten
Ursprung
Commit
1dd3e54178
1 geänderte Dateien mit 22 neuen und 17 gelöschten Zeilen
  1. 22 17
      src/pages/classify/index.tsx

+ 22 - 17
src/pages/classify/index.tsx

@@ -27,7 +27,7 @@ const Index = forwardRef((props: Props) => {
     const [showEmpty, setShowEmpty] = useState(false)
     const [isSetOpen, setIsSetOpen] = useState(true)
     const [filterHeight, setFilterHeight] = useState(0)
-    const timeRef = useRef<any>()
+    const lastScrollTop = useRef(0); // 用于跟踪上一次滚动位置
     // 获取分类列表
     useEffect(() => {
         if (pageShow) {
@@ -46,6 +46,7 @@ const Index = forwardRef((props: Props) => {
             console.log("获取书籍列表")
             let { workDirection } = classifyStore
             let { categoryId } = classifyStore
+            lastScrollTop.current = 0
             categoryId.id != 0 && classifyStore.categoryId && getList({ workDirection, categoryId: categoryId.id, pageNum: 1, pageSize: 10, type: 'class' }).then((res: any) => {
                 if (res?.data?.data?.total === 0) {
                     setShowEmpty(true)
@@ -145,29 +146,33 @@ const Index = forwardRef((props: Props) => {
                 <ScrollView
                     lowerThreshold={filterHeight}
                     // refresherTriggered={this.state.isShow}
-                    style={{ height: `calc(100vh - ${filterHeight + 10}px)` }}
+                    style={{ height: `calc(100vh - ${filterHeight+10}px)` }}
                     onScrollToLower={load}
+                    scrollTop={lastScrollTop.current}
                     onScroll={(evt: any) => {
-                        let top = evt.detail.scrollTop
-                        if(timeRef.current){
-                            clearTimeout(timeRef.current)
+                        const top = evt.detail.scrollTop;
+                        // 判断滚动方向
+                        // if (top > lastScrollTop.current && open) {
+                        //     // 向下滚动,执行关闭操作
+                        //     if (top > 100) {
+                        //         callBacn(false);
+                        //     }
+                        // } else if (top < lastScrollTop.current && !open) {
+                        //     // 向上滚动,执行打开操作
+                        //     if (top < 100) {
+                        //         callBacn(true);
+                        //     }
+                        // }
+                        if (open) {
+                            callBacn(false);
                         }
-                        timeRef.current=setTimeout(()=>{
-                            if (isSetOpen) {
-                                if (top > 100 && open) {
-                                    callBacn(false)
-                                }
-                                if (top < 100 && !open) {
-                                    callBacn(true)
-                                }
-                            }
-                        },100)
-                       
+                        // 更新 lastScrollTop 以供下一次判断
+                        lastScrollTop.current = top;
                     }}
                     className="scrollview"
                     scrollY={true}
                     refresherDefaultStyle="black"
-                // scrollWithAnimation={true}
+                    scrollWithAnimation={true}
                 >
                     <View className='w  row for_top1 pd_btm'>
                         {