inleft
2022-03-02 e33959d3ca88b9fae5f6fe1048c8a1f7751e6f21
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<template>
    <div>
        <div v-infinite-scroll="loadMore" infinite-scroll-disabled="busy" :infinite-scroll-distance="10">
            <div class="mySecret" v-if="data.length==0">
                <p>空空如也..</p>
            </div>
            
            <div v-for="(temp,index) in data" >
                <newArticle v-bind="temp" :index="index"></newArticle>
                <!-- <box5 v-bind="temp"></box5> -->
            </div>
 
 
            <div v-if="loading && !busy" class="demo-loading-container">
                <a-spin />
            </div>
        </div>
        <a-row type="flex" justify="center">
            <div style="position:fixed;bottom: 10px;" >
                <a-pagination @change="onChange" :showQuickJumper="true" :size="size" v-model="current"
                    :defaultPageSize="defaultPageSize" :pageSize="pageSize" :total="total" />
            </div>
        </a-row>
 
    </div>
</template>
<script>
    import infiniteScroll from 'vue-infinite-scroll';
    import box5 from "../mini/box5-article.vue"
    import babyActicle from '../../assets/baby.htm'
    import newArticle from "../mini/box-new-article.vue"
    import shijie from '../../assets/shijie.htm'
    import {
        queryBlogArticleList
    } from '../../api/blogArticle.js'
 
    var obj1 = {
        "source": babyActicle,
        "title": "陈奕迅-Body Song 歌词",
        "read": 1101,
        "like": 233,
        "folder": "歌词",
        "publishTime": "2021-05-26",
    }
    var obj2 = {
        "source": shijie,
        "title": "这世界那么多人-吉他谱",
        "read": 3101,
        "like": 113,
        "folder": "吉他谱",
        "publishTime": "2020-05-26",
    }
    var obj3 = {
        "source": shijie,
        "title": "遥远的它-吉他谱",
        "read": 201,
        "like": 13,
        "folder": "吉他谱",
        "publishTime": "2022-07-26",
    }
 
    export default {
        components: {
            box5,
            newArticle
        },
        directives: {
            infiniteScroll
        },
 
        data() {
            return {
                typeId: "",
                data: [],
                loading: false,
                busy: false,
                size: "small",
                total: 1,
                pageSize: 6,
                current: 1,
                defaultPageSize:10
            };
        },
        watch: {
            '$route'(to, from) {
                if ("articleList" === to.name) {
                    this.typeId = this.$route.query.typeId;
                }
            },
            typeId: function(newValue, oldValue) {
                this.busy = true;
                this.$message.info('loading', 0.3);
                this.onChange(1);
            },
        },
        activated() {
            window.addEventListener('scroll', this);
        },
        deactivated() {
            window.removeEventListener('scroll', this);
        },
        beforeMount() {
            queryBlogArticleList({
                pageNo: this.current,
                pageSize:this.pageSize,
                typeId: this.typeId
            }).then((res) => {
                this.total = Number(res.data.total)
                this.pageSize = Number(res.data.size);
                this.data = res.data.records;
                return res
            })
        },
        methods: {
            onChange(current) {
                this.current = current;
                queryBlogArticleList({
                    pageNo: current,
                    pageSize:this.pageSize,
                    typeId: this.typeId
                }).then((res) => {
                    this.busy = false;
                    this.total = Number(res.data.total)
                    this.pageSize = Number(res.data.size);
                    this.data = res.data.records;
                    return res
                })
            },
            loadMore() {
                this.loading = true;
                this.busy = true;
 
                queryBlogArticleList({
                    pageNo: this.current + 1,
                    pageSize:this.pageSize,
                    typeId: this.typeId
                }).then((res) => {
 
                    this.total = Number(res.data.total)
                    this.pageSize = Number(res.data.size);
                    this.data = this.data.concat(res.data.records);
                    this.busy = false;
                    if (res.data.records.length == 0) {
                        //this.$message.warning('别滑了,别滑了,到底了..');
                        this.busy = true;
                        this.loading = false;
                        return;
                    } else {
                        this.current += 1;
                    }
 
                    return res
                })
 
                setTimeout(function() {
                    this.loading = false;
                }, 100);
 
 
            },
        },
    };
</script>
<style>
    /* .test {
        overflow: hidden;
        height: 700px;
    }
 
    .infinite-container {
        overflow: auto;
    }
 
    .infinite-container::-webkit-scrollbar {
        display: none;
    } */
 
    .demo-loading-container {
        position: absolute;
        bottom: 40px;
        width: 100%;
        text-align: center;
    }
</style>