|
|
@@ -1,10 +1,10 @@
|
|
|
<template>
|
|
|
- <div class="invite">
|
|
|
+ <div class="invite" @scroll="handleScroll">
|
|
|
<div class="head">
|
|
|
<img @click="back" src="@/assets/images/back.png" class="arrow_img" />
|
|
|
<span>{{ $t('lang219') }}</span>
|
|
|
</div>
|
|
|
- <van-list v-model="loading" :finished="finished" :finished-text="finishText" @load="onLoad">
|
|
|
+ <div v-if="list.length > 0">
|
|
|
<div class="notice" v-for="(item, index) in list" :key="index" @click="navigatorTo('bulletinDetail', item.id)">
|
|
|
<img class="notice_img" :src="item.img_url" alt="" v-if="item.img_url" />
|
|
|
<div class="right">
|
|
|
@@ -12,7 +12,10 @@
|
|
|
<span class="time_text">{{ dateFormatFn(item.createtime) }}</span>
|
|
|
</div>
|
|
|
</div>
|
|
|
- </van-list>
|
|
|
+ </div>
|
|
|
+ <div class="bare" v-else>
|
|
|
+ <span>{{ $t('lang60') }}</span>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
@@ -23,46 +26,60 @@ export default {
|
|
|
data() {
|
|
|
return {
|
|
|
list: [],
|
|
|
- page: 0,
|
|
|
+ page: 1,
|
|
|
loading: false,
|
|
|
finished: false,
|
|
|
- total: 1,
|
|
|
+ total: 0,
|
|
|
finishText: this.$t('lang200'),
|
|
|
};
|
|
|
},
|
|
|
mounted() {
|
|
|
- this.onLoad();
|
|
|
- window.addEventListener('scroll', this.scrollBottom);
|
|
|
+ this.getAnnouncement();
|
|
|
+ // window.addEventListener('scroll', this.scrollBottom);
|
|
|
},
|
|
|
destroyed() {
|
|
|
- window.removeEventListener('scroll', this.scrollBottom);
|
|
|
+ // window.removeEventListener('scroll', this.scrollBottom);
|
|
|
},
|
|
|
methods: {
|
|
|
//返回上一页
|
|
|
back() {
|
|
|
this.$router.back();
|
|
|
},
|
|
|
- scrollBottom() {
|
|
|
- //加载更多
|
|
|
- var scrollTop = document.documentElement.scrollTop || document.body.scrollTop; //变量windowHeight是可视区的高度
|
|
|
- var windowHeight = document.documentElement.clientHeight || document.body.clientHeight; //变量scrollHeight是滚动条的总高度
|
|
|
- var scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight; //滚动条到底部的条件
|
|
|
- console.log(scrollTop, 'scrollTop');
|
|
|
- console.log(windowHeight, 'windowHeight');
|
|
|
- console.log(scrollHeight, 'scrollHeight');
|
|
|
- if (scrollTop + windowHeight >= scrollHeight && scrollTop > 0) {
|
|
|
- //写后台加载数据的函数
|
|
|
- // console.log('滚动到底部啦');
|
|
|
- if (this.finished) {
|
|
|
- this.loading = true; // 关闭加载状态
|
|
|
- this.finished = false; // 加载开始
|
|
|
- this.finishText = this.$t('lang200');
|
|
|
- this.onLoad();
|
|
|
+ handleScroll(event) {
|
|
|
+ const container = event.target;
|
|
|
+ const scrollTop = container.scrollTop; // 滚动距离
|
|
|
+ const scrollHeight = container.scrollHeight; // 内容总高度
|
|
|
+ const clientHeight = container.clientHeight; // 可视区域高度
|
|
|
+ // 判断是否滑动到底部
|
|
|
+ if (scrollTop + clientHeight >= scrollHeight - 10) {
|
|
|
+ console.log('Bottom', this.page);
|
|
|
+ if (this.page != -1) {
|
|
|
+ this.page++; // 页数加 1
|
|
|
+ this.getAnnouncement(); // 触发加载更多
|
|
|
}
|
|
|
- } else {
|
|
|
- // this.loading = false; // 关闭加载状态
|
|
|
}
|
|
|
},
|
|
|
+ // scrollBottom() {
|
|
|
+ // //加载更多
|
|
|
+ // var scrollTop = document.documentElement.scrollTop || document.body.scrollTop; //变量windowHeight是可视区的高度
|
|
|
+ // var windowHeight = document.documentElement.clientHeight || document.body.clientHeight; //变量scrollHeight是滚动条的总高度
|
|
|
+ // var scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight; //滚动条到底部的条件
|
|
|
+ // console.log(scrollTop, 'scrollTop');
|
|
|
+ // console.log(windowHeight, 'windowHeight');
|
|
|
+ // console.log(scrollHeight, 'scrollHeight');
|
|
|
+ // if (scrollTop + windowHeight >= scrollHeight && scrollTop > 0) {
|
|
|
+ // //写后台加载数据的函数
|
|
|
+ // // console.log('滚动到底部啦');
|
|
|
+ // if (this.finished) {
|
|
|
+ // this.loading = true; // 关闭加载状态
|
|
|
+ // this.finished = false; // 加载开始
|
|
|
+ // this.finishText = this.$t('lang200');
|
|
|
+ // this.onLoad();
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ // // this.loading = false; // 关闭加载状态
|
|
|
+ // }
|
|
|
+ // },
|
|
|
navigatorTo(name, id) {
|
|
|
this.$router.push({ name, query: { id: id } });
|
|
|
},
|
|
|
@@ -73,53 +90,65 @@ export default {
|
|
|
let params = {
|
|
|
page: this.page,
|
|
|
query: {},
|
|
|
- type_id: 1
|
|
|
+ type_id: 1,
|
|
|
};
|
|
|
homeApi.getAnnouncement(params).then(res => {
|
|
|
+ // if (res.code == 200) {
|
|
|
+ // let rows = res.data.rows;
|
|
|
+ // // 如果返回的数组是空或数组长度是0
|
|
|
+ // if (rows == null || rows.length === 0) {
|
|
|
+ // this.loading = false; // 关闭加载状态
|
|
|
+ // this.finished = true; // 加载结束
|
|
|
+ // this.finishText = this.$t('lang202');
|
|
|
+ // if (this.list.length <= 0) {
|
|
|
+ // this.total = 0;
|
|
|
+ // }
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // this.loading = false; // 关闭加载状态
|
|
|
+ // this.finishText = this.$t('lang203');
|
|
|
+ // this.finished = true;
|
|
|
+ // this.total = res.data.total; //数据总条数
|
|
|
+ // this.list = this.list.concat(rows); //合并数组
|
|
|
+ // console.log(this.list);
|
|
|
+
|
|
|
+ // // 如果合并之后的数组长度大于返回的数据总条数
|
|
|
+ // if (this.list.length >= this.total) {
|
|
|
+ // this.finished = true; // 加载结束
|
|
|
+ // this.finishText = this.$t('lang202');
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ // this.total = 0;
|
|
|
+ // this.loading = false; // 关闭加载状态
|
|
|
+ // this.finished = true; // 加载结束
|
|
|
+ // this.finishText = this.$t('lang202');
|
|
|
+ // }
|
|
|
if (res.code == 200) {
|
|
|
- let rows = res.data.rows;
|
|
|
- // 如果返回的数组是空或数组长度是0
|
|
|
- if (rows == null || rows.length === 0) {
|
|
|
- this.loading = false; // 关闭加载状态
|
|
|
- this.finished = true; // 加载结束
|
|
|
- this.finishText = this.$t('lang202');
|
|
|
- if (this.list.length <= 0) {
|
|
|
- this.total = 0;
|
|
|
+ if (this.list.length >= res.data.total) {
|
|
|
+ this.page = -1; // 重置为 -1,表示没有更多数据
|
|
|
+ } else {
|
|
|
+ this.list = [...this.list, ...res.data.rows];
|
|
|
+ if (this.list.length >= res.data.total) {
|
|
|
+ this.page = -1; // 重置为 -1,表示没有更多数据
|
|
|
}
|
|
|
- return;
|
|
|
- }
|
|
|
- this.loading = false; // 关闭加载状态
|
|
|
- this.finishText = this.$t('lang203');
|
|
|
- this.finished = true;
|
|
|
- this.total = res.data.total; //数据总条数
|
|
|
- this.list = this.list.concat(rows); //合并数组
|
|
|
- console.log(this.list);
|
|
|
-
|
|
|
- // 如果合并之后的数组长度大于返回的数据总条数
|
|
|
- if (this.list.length >= this.total) {
|
|
|
- this.finished = true; // 加载结束
|
|
|
- this.finishText = this.$t('lang202');
|
|
|
}
|
|
|
} else {
|
|
|
- this.total = 0;
|
|
|
- this.loading = false; // 关闭加载状态
|
|
|
- this.finished = true; // 加载结束
|
|
|
- this.finishText = this.$t('lang202');
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
- onLoad() {
|
|
|
- this.page += 1;
|
|
|
- this.getAnnouncement();
|
|
|
- },
|
|
|
+ // onLoad() {
|
|
|
+ // this.page += 1;
|
|
|
+ // this.getAnnouncement();
|
|
|
+ // },
|
|
|
},
|
|
|
};
|
|
|
</script>
|
|
|
|
|
|
<style lang="less" scoped>
|
|
|
.invite {
|
|
|
- min-height: calc(100vh + 50px);
|
|
|
padding: 66px 16px;
|
|
|
+ height: 100vh;
|
|
|
+ overflow: auto;
|
|
|
.head {
|
|
|
position: fixed;
|
|
|
top: 0;
|
|
|
@@ -170,5 +199,12 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ .bare {
|
|
|
+ text-align: center;
|
|
|
+ font-size: 14px;
|
|
|
+ padding: 60px 14px;
|
|
|
+ color: #888;
|
|
|
+ }
|
|
|
}
|
|
|
</style>
|