From ef819706ab4ac1bf5928adc1c920052df7b13458 Mon Sep 17 00:00:00 2001
From: Tevin <tingquanren@163.com>
Date: Thu, 26 Aug 2021 11:03:18 +0800
Subject: [PATCH] 微调单项框样式

---
 plugins/infiniteScroll/CInfiniteScroll.vue |  106 +++++++++++++++++++++++++++++------------------------
 1 files changed, 58 insertions(+), 48 deletions(-)

diff --git a/plugins/infiniteScroll/CInfiniteScroll.vue b/plugins/infiniteScroll/CInfiniteScroll.vue
index 68e4620..b1ca855 100644
--- a/plugins/infiniteScroll/CInfiniteScroll.vue
+++ b/plugins/infiniteScroll/CInfiniteScroll.vue
@@ -35,12 +35,16 @@
                 </view>
             </view>
         </view>
-        <slot />
+        <view class="c-infinite-content">
+            <slot />
+        </view>
         <view class="c-infinite-bottom">
             <view
                 class="c-infinite-loading"
-                v-if="loading"
-            >加载中,请稍后...</view>
+                v-if="!ending"
+            >
+                <text v-show="loading">加载中,请稍后...</text>
+            </view>
             <view v-if="ending">
                 <text
                     class="c-infinite-ended"
@@ -73,7 +77,7 @@
         // 发起加载页面数据回调
         //   参数 {
         //     current: 当前页页码,
-        //     next: 需要到达的页面页码,
+        //     next: 需要加载的页面页码,
         //     success: 当加载成功后页面调用, 回传参数 { pageTotal: 当前翻页总页数 }
         //     fail: 加载失败后页面调用
         //   }
@@ -122,47 +126,49 @@
             // 开始加载
             this.inital = true;
             this.loading = true;
-            this.onLoadMore({
-                current: this.current,
-                next: this.current + 1,
-                // 加载成功
-                success: options => {
-                    setTimeout(() => {
-                        this.loading = false;
-                        // 没有数据
-                        if (!options.pageTotal || options.pageTotal <= 0) {
-                            this.ending = true;
-                        }
-                        // 有数据
-                        else {
-                            this.pageTotal = options.pageTotal;
-                            this.current = this.current + 1;
-                            // 已到最后一页
-                            if (this.current >= this.pageTotal) {
+            setTimeout(() => {
+                this.onLoadMore({
+                    current: this.current,
+                    next: this.current + 1,
+                    // 加载成功
+                    success: options => {
+                        this.$nextTick(() => {
+                            this.loading = false;
+                            // 没有数据
+                            if (!options.pageTotal || options.pageTotal <= 0) {
                                 this.ending = true;
                             }
-                        }
-                        // 还原下拉
+                            // 有数据
+                            else {
+                                this.pageTotal = options.pageTotal;
+                                this.current = this.current + 1;
+                                // 已到最后一页
+                                if (this.current >= this.pageTotal) {
+                                    this.ending = true;
+                                }
+                            }
+                            // 如果下拉刷新,还原下拉
+                            if (this.touch.dargState === 2) {
+                                this.touch.driftTop = 0;
+                                setTimeout(() => {
+                                    this.touch.dargState = 0;
+                                }, 300);
+                            }
+                        });
+                    },
+                    // 加载失败
+                    fail: () => {
+                        this.loading = false;
+                        // 如果下拉刷新,还原下拉
                         if (this.touch.dargState === 2) {
                             this.touch.driftTop = 0;
                             setTimeout(() => {
                                 this.touch.dargState = 0;
                             }, 300);
                         }
-                    }, 100);
-                },
-                // 加载失败
-                fail: () => {
-                    this.loading = false;
-                    // 还原下拉
-                    if (this.touch.dargState === 2) {
-                        this.touch.driftTop = 0;
-                        setTimeout(() => {
-                            this.touch.dargState = 0;
-                        }, 300);
-                    }
-                },
-            });
+                    },
+                });
+            }, 100);
         },
         onScroll(evt) {
             // 已经滚动(滚动后禁止下拉刷新)
@@ -191,14 +197,6 @@
         // 小程序中滚动到底部
         onScrollToLower() {
             if (process.env.TARO_ENV !== 'weapp') {
-                return;
-            }
-            this.hanldeLoadMore();
-        },
-        // 初始加载
-        initScroll() {
-            // 已初始化,跳过
-            if (this.inital) {
                 return;
             }
             this.hanldeLoadMore();
@@ -288,13 +286,25 @@
                 }
             }
         },
+        // 初始加载
+        $initScroll() {
+            // 已初始化,跳过
+            if (this.inital) {
+                return;
+            }
+            this.hanldeLoadMore();
+        },
+        // 刷新加载
+        $refresh() {
+            this.ending = false;
+            this.current = 0;
+            this.hanldeLoadMore();
+        },
     },
     mounted() {
         // 开启自动初始化
         if (this.autoInit) {
-            setTimeout(() => {
-                this.hanldeLoadMore();
-            }, 200);
+            this.hanldeLoadMore();
         }
     },
 };

--
Gitblit v1.9.1