Explorar el Código

修改文章下拉加载

aaa hace 4 años
padre
commit
f2351ed0a8

+ 1 - 1
src/views/home/exam/page-exam.vue

@@ -86,7 +86,7 @@ export default {
     window.addEventListener("scroll", this.handleExamScroll, true);
   },
   destroyed () {
-    window.removeEventListener("scroll", this.scrollHander);
+    window.removeEventListener("scroll", this.handleExamScroll);
   },
   methods: {
     // 查询:考试场次的列表信息

+ 44 - 5
src/views/home/learn/page-learn-child.vue

@@ -56,6 +56,7 @@
 </template>
 
 <script>
+import { Toast } from "vant";
 import { getTodayStr } from "@/utils/date";
 import { mapState } from "vuex";
 export default {
@@ -78,7 +79,10 @@ export default {
       contentList: [],
       loading: false,
       finished: false,
-      learnChildList: []
+      learnChildList: [],
+      learnPage: 0,
+      learnSize: 10,
+      canLearnFlag: true // 加载考试标志
     };
   },
   computed: {
@@ -89,6 +93,10 @@ export default {
   created() {},
   mounted() {
     this.getChildList();
+    window.addEventListener("scroll", this.handleLearnScroll, true);
+  },
+  destroyed () {
+    window.removeEventListener("scroll", this.handleLearnScroll);
   },
   watch: {
     // 监听:工种
@@ -111,6 +119,7 @@ export default {
           res.data.shift();
           this.learnChildList = res.data;
           this.$store.commit("toggleLoading", false);
+          this.learnPage = 0;
           this.getContentList();
         })
         .catch(() => {
@@ -118,8 +127,10 @@ export default {
         });
     },
     childChange(index) {
-      this.finished = false;
+      this.canLearnFlag = true;
+      this.finished = !this.canLearnFlag;
       this.choosedChildIndex = index;
+      this.learnPage = 0;
       this.getContentList();
     },
     //   查询子目录
@@ -129,7 +140,9 @@ export default {
         categoryId: this.learnChildList[this.choosedChildIndex].id
       };
       let params = {
-        type: this.chooseEngneeringWork.value
+        type: this.chooseEngneeringWork.value,
+        page: this.learnPage,
+        size: this.learnSize
       };
       this.$_http
         .get(
@@ -140,14 +153,40 @@ export default {
           { params }
         )
         .then(res => {
-          this.formatNeedStudyTodayFun(res.data);
-          this.finished = true;
+          this.formatNeedStudyTodayFun(res.data.content);
+
+          // 分页到底了
+          if (res.data.last) {
+            this.canLearnFlag = false;
+          } else {
+            this.canLearnFlag = true;
+          }
+          // 不能上拉了就是加载玩了
+          this.finished = !this.canLearnFlag;
           this.$store.commit("toggleLoading", false);
         })
         .catch(() => {
+          this.canLearnFlag = false;
+          Toast("系统异常");
           this.$store.commit("toggleLoading", false);
         });
     },
+    async handleLearnScroll() {
+      let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
+      var windowHeight =
+        document.documentElement.clientHeight || document.body.clientHeight;
+      var scrollHeight =
+        document.documentElement.scrollHeight || document.body.scrollHeight;
+      //   console.log("---scrollTop-----" + scrollTop);
+      //   console.log("---windowHeight-----" + windowHeight);
+      //   console.log("---scrollHeight-----" + scrollHeight);
+      if (this.canLearnFlag && scrollTop + windowHeight >= scrollHeight - 100) {
+        this.canLearnFlag = false;
+        console.log("触底");
+        this.learnPage = this.learnPage + 1;
+        await this.getContentList();
+      }
+    },
     // 判断是否今日必学
     formatNeedStudyTodayFun(datas) {
       let todayStr = getTodayStr();

+ 42 - 4
src/views/home/learn/page-learn-content.vue

@@ -121,7 +121,10 @@ export default {
       commentList: [], // 评论列表内容
       commentValue: "", // 即将评论的内容
       startStudyInterval: null,
-      isReadable: true
+      isReadable: true,
+      commentPage: 0,
+      commentSize: 10,
+      canCommentFlag: true // 加载考试标志
     };
   },
   computed: {
@@ -130,7 +133,13 @@ export default {
       favorite: state => state.favorite
     })
   },
-  created() { this.setLanXinNavigator(); },
+  created() {
+    this.setLanXinNavigator();
+    window.addEventListener("scroll", this.handleCommentScroll, true);
+  },
+  destroyed () {
+    window.removeEventListener("scroll", this.handleCommentScroll);
+  },
   activated() {
     this.setLanXinNavigator();
   },
@@ -178,16 +187,45 @@ export default {
       // !!!需要查询评论列表内容!!!
       let path = {
         materialId: this.materialId
+
+      };
+      let params = {
+        page: this.commentPage,
+        size: this.commentSize
       };
       this.$_http
-        .get(this.$pathParams(this.$_API.JTXT_GET_MATERIALS_COMMENTS, path))
+        .get(this.$pathParams(this.$_API.JTXT_GET_MATERIALS_COMMENTS, path), { params })
         .then(res => {
-          this.commentList = res.data;
+          this.commentList = res.data.content;
+          // 分页到底了
+          if (res.data.last) {
+            this.canCommentFlag = false;
+          } else {
+            this.canCommentFlag = true;
+          }
         })
         .catch(() => {
+          this.canCommentFlag = false;
+          Toast("系统异常");
           this.$store.commit("toggleLoading", false);
         });
     },
+    async handleCommentScroll() {
+      let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
+      var windowHeight =
+        document.documentElement.clientHeight || document.body.clientHeight;
+      var scrollHeight =
+        document.documentElement.scrollHeight || document.body.scrollHeight;
+      //   console.log("---scrollTop-----" + scrollTop);
+      //   console.log("---windowHeight-----" + windowHeight);
+      //   console.log("---scrollHeight-----" + scrollHeight);
+      if (this.canCommentFlag && scrollTop + windowHeight >= scrollHeight - 100) {
+        this.canCommentFlag = false;
+        console.log("触底");
+        this.commentPage = this.commentPage + 1;
+        await this.getCommentListFun();
+      }
+    },
     // 操作:返回
     onClickLeft() {
       this.$router.back();