From 083c818af77d33d619dba3dc20f94e996225a1c7 Mon Sep 17 00:00:00 2001
From: value <z1292839451@163.com>
Date: 星期四, 16 五月 2024 10:28:39 +0800
Subject: [PATCH] 增加人事系统对接

---
 src/components/tool/scroll-paging.vue |   68 +++++++++++++++++++++++-----------
 1 files changed, 46 insertions(+), 22 deletions(-)

diff --git a/src/components/tool/scroll-paging.vue b/src/components/tool/scroll-paging.vue
index c60265f..367409d 100644
--- a/src/components/tool/scroll-paging.vue
+++ b/src/components/tool/scroll-paging.vue
@@ -1,15 +1,15 @@
 <template>
-  <div class="scroll-pagination"  ref="content" @scroll="scrollFn">
+  <div class="scroll-pagination"  ref="content" @scroll="onScroll">
     <slot></slot>
     <el-button
-        v-if="isLoding"
+        v-show="isLoding"
         type="text"
         style="display: flex; margin: 0 auto; color: #909399"
         ><i class="el-icon-loading" style="font-size:20px"></i
       ></el-button>
     <el-button
       type="text"
-      v-if="finishLoding"
+      v-show="finishLoding"
       style="display: flex; margin: 0 auto; color: #909399"
       >宸茬粡娌℃湁鏇村鍟</el-button
     >
@@ -23,6 +23,18 @@
     finishLoding: {
       type:Boolean,
       default:false
+    },
+    list:{
+      type:Array,
+      default:()=>[]
+    }
+  },
+  watch: {
+    list:{
+      deep:true,
+      handler(){
+        this.isLoding = false
+      }
     }
   },
   data() {
@@ -30,13 +42,19 @@
       isLoding: false,
     }
   },
+  created(){
+    // 闃叉姈
+    this.onScroll = this.debounce(this.scrollFn,500);
+    // 鑺傛祦
+    // this.onScroll = this.throttle(this.scrollFn,1000);
+  },
   mounted(){
-    window.addEventListener("scroll", this.throttle(this.scrollFn, 20000));
   },
   methods: {
+    onScroll(){},
     scrollFn() {
       let content = this.$refs.content
-      if (content.scrollTop + content.clientHeight >= content.scrollHeight) {
+      if (content.scrollTop + content.clientHeight+1 >= content.scrollHeight) {
         if(!this.finishLoding){
           this.loadMore()
         }else{
@@ -47,30 +65,36 @@
     loadMore(){
       if (this.isLoding) return
       this.isLoding = true
-      // Simulate loading data (replace with your own API call)
       setTimeout(() => {
         this.$emit('load')
-        this.isLoding = false
-      }, 1000)
+      }, 500)
     },
-    throttle(fn, wait) {
-      // 灏佽鍑芥暟杩涜鑺傛祦
-      var timer = null;
+    debounce(func, delay) {
+      let timer = null;
       return function () {
-        var context = this;
-        var args = arguments;
-        if (!timer) {
-          timer = setTimeout(function () {
-            fn.apply(context, args);
-            timer = null;
-          }, wait);
+        if (timer) {
+          clearTimeout(timer);
+          timer = null;
         }
+        timer = setTimeout(() => {
+          func(...arguments);
+        }, delay);
       };
     },
-  },
-  destroyed() {
-    window.removeEventListener("scroll", this.throttle(), false);
-  },
+    throttle(func, delay) {
+      let time = null;
+      return function () {
+        let args = Array.from(arguments);
+        if (time === null) {
+          time = setTimeout(() => {
+            func(...args);
+            clearTimeout(time);
+            time = null;
+          }, delay);
+        }
+      };
+    }
+  }
 }
 </script>
 

--
Gitblit v1.9.3