inleft
2022-08-11 af029bdfb645bd2b75fbab687c1a5f45b428d801
commit | author | age
aab811 1 <template>
af029b 2     <div class="fade">
aab811 3         <div v-infinite-scroll="loadMore" infinite-scroll-disabled="busy" :infinite-scroll-distance="10">
81c155 4             <div class="mySecret" v-if="data.length==0">
I 5                 <p>空空如也..</p>
6             </div>
74344a 7
I 8             <div v-for="(temp,index) in data">
f60b31 9                 <newArticle v-bind="temp" :index="index"></newArticle>
I 10                 <!-- <box5 v-bind="temp"></box5> -->
11             </div>
12
13
af029b 14             <div v-if="loading && !busy" class="loading-container">
aab811 15                 <a-spin />
I 16             </div>
17         </div>
019990 18         <a-row type="flex" justify="center">
74344a 19             <div style="position:fixed;bottom: 10px;">
019990 20                 <a-pagination @change="onChange" :showQuickJumper="true" :size="size" v-model="current"
f60b31 21                     :defaultPageSize="defaultPageSize" :pageSize="pageSize" :total="total" />
019990 22             </div>
I 23         </a-row>
63af45 24
aab811 25     </div>
I 26 </template>
27 <script>
28     import infiniteScroll from 'vue-infinite-scroll';
29     import box5 from "../mini/box5-article.vue"
30     import babyActicle from '../../assets/baby.htm'
06ee76 31     import newArticle from "../mini/box-new-article.vue"
aab811 32     import shijie from '../../assets/shijie.htm'
63af45 33     import {
I 34         queryBlogArticleList
35     } from '../../api/blogArticle.js'
aab811 36
3a5d66 37
I 38
aab811 39     export default {
I 40         components: {
06ee76 41             box5,
L 42             newArticle
aab811 43         },
I 44         directives: {
45             infiniteScroll
46         },
f60b31 47
aab811 48         data() {
I 49             return {
4b854c 50                 typeId: "",
aab811 51                 data: [],
I 52                 loading: false,
53                 busy: false,
54                 size: "small",
63af45 55                 total: 1,
a71b64 56                 pageSize: 6,
aab811 57                 current: 1,
74344a 58                 defaultPageSize: 10
aab811 59             };
74344a 60         },
I 61         created() {
62             this.typeId = this.$route.query.typeId;
aab811 63         },
4b854c 64         watch: {
I 65             '$route'(to, from) {
74344a 66                 if ("articleList" === to.name || "home" === to.name) {
4b854c 67                     this.typeId = this.$route.query.typeId;
I 68                 }
69             },
70             typeId: function(newValue, oldValue) {
105729 71                 //有条件不刷新
af029b 72                 // if (newValue == undefined || oldValue == "") {
I 73                 //     return
74                 // }
75
76                 this.busy = true;
859ec7 77                 this.$message.info('loading', 0.3);
4b854c 78                 this.onChange(1);
f60b31 79             },
4b854c 80         },
I 81         activated() {
af029b 82             this.busy = false;
4b854c 83             window.addEventListener('scroll', this);
I 84         },
85         deactivated() {
af029b 86             this.busy = true;
4b854c 87             window.removeEventListener('scroll', this);
I 88         },
aab811 89         methods: {
I 90             onChange(current) {
91                 this.current = current;
63af45 92                 queryBlogArticleList({
4b854c 93                     pageNo: current,
74344a 94                     pageSize: this.pageSize,
4b854c 95                     typeId: this.typeId
63af45 96                 }).then((res) => {
I 97                     this.busy = false;
98                     this.total = Number(res.data.total)
99                     this.pageSize = Number(res.data.size);
100                     this.data = res.data.records;
101                     return res
102                 })
aab811 103             },
I 104             loadMore() {
105                 this.loading = true;
63af45 106                 this.busy = true;
4b854c 107
63af45 108                 queryBlogArticleList({
4b854c 109                     pageNo: this.current + 1,
74344a 110                     pageSize: this.pageSize,
4b854c 111                     typeId: this.typeId
63af45 112                 }).then((res) => {
aab811 113
63af45 114                     this.total = Number(res.data.total)
I 115                     this.pageSize = Number(res.data.size);
116                     this.data = this.data.concat(res.data.records);
117                     this.busy = false;
118                     if (res.data.records.length == 0) {
4b854c 119                         //this.$message.warning('别滑了,别滑了,到底了..');
63af45 120                         this.busy = true;
I 121                         this.loading = false;
122                         return;
123                     } else {
124                         this.current += 1;
125                     }
aab811 126
63af45 127                     return res
I 128                 })
aab811 129
I 130                 setTimeout(function() {
131                     this.loading = false;
63af45 132                 }, 100);
aab811 133
I 134
135             },
136         },
137     };
138 </script>
139 <style>
af029b 140     .loading-container {
aab811 141         position: absolute;
I 142         bottom: 40px;
143         width: 100%;
144         text-align: center;
145     }
146 </style>