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
| <template>
| <view class="box">
| <filter-box :categories1="scenes" :categories2="categories" :cid1="pagination.scene" :cid2="pagination.cid"
| @change="filterChange"></filter-box>
|
| <view class="section-box" v-if="list&&list.length>0">
| <article-item v-for="(item,index) in list" :key="index" :item="item"></article-item>
| </view>
| <empty v-else :loading="loading"></empty>
|
| <view class="loadmore" v-if="list&&list.length>0">
| <u-loadmore @loadmore="getData(true)" :status="loadStatus" />
| </view>
| </view>
| </template>
|
| <script>
| var that; // 当前页面对象
| var vk; // vk依赖
| export default {
| data() {
| return {
| scenes: [{
| id: "default",
| name: "全部",
| },
| {
| id: "essence",
| name: "推荐",
| },
| {
| id: "sticky",
| name: "置顶",
| }
| ],
| list: [],
| pagination: {
| pageIndex: 1,
| pageSize: 10,
| scene: 0,
| cid: 0,
| },
| categories: [],
| over: false,
| loading: false,
| };
| },
| computed: {
| loadStatus() {
| if (this.over) {
| return "nomore";
| }
| if (this.loading) {
| return "loading";
| }
| return "loadmore";
| },
| },
| onLoad(options) {
| that = this;
| vk = that.vk;
| this.pagination.scene = options.scene ?? 'default'
| this.pagination.cid = options.cid ?? 0
|
| this.getData();
| this.getCategories();
| },
| onReachBottom() {
| this.getData(true);
| },
| onPullDownRefresh() {
| this.resetData();
| this.getData();
| setTimeout(() => {
| uni.stopPullDownRefresh()
| }, 500);
| },
| methods: {
| filterChange(scene, cid) {
| this.pagination.scene = scene;
| this.pagination.cid = cid;
| this.resetData();
| this.getData();
| },
| resetData() {
| this.list = [];
| this.pagination.pageIndex = 1;
| this.over = false;
| },
| getCategories() {
| vk.callFunction({
| url: 'client/articles/pub/categories',
| success(data) {
| let categories = [];
| categories.push(...data.rows);
| console.log(categories)
| that.categories.push(...categories);
| }
| });
| },
| getData(more = false) {
| if (this.loading) {
| return;
| }
| if (more) {
| this.pagination.pageIndex++;
| }
| this.loading = true;
|
| vk.callFunction({
| url: 'client/articles/pub/article_list',
| data: that.pagination,
| success(data) {
| let list = data.rows;
| if (list.length > 0) {
| that.list.push(...list);
| }
| setTimeout(() => {
| that.loading = false;
| if (list.length < that.pagination.pageSize) {
| that.over = true;
| }
| }, 200);
| }
| });
| },
| }
| }
| </script>
|
| <style lang="scss" scoped>
| .section-box {
| position: relative;
| display: flex;
| flex-direction: column;
| background: #FFFFFF;
| }
| </style>
|
|