|
@@ -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();
|