mycollect.vue
6.1 KB
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<template>
<div class="container">
<div class="flextwo mykind">
<div
class="fenleiword"
:class="fenlei == 0 ? 'fenleiactive' : ''"
@click="getfen(0)"
>
发布
</div>
<div
class="fenleiword"
:class="fenlei == 1 ? 'fenleiactive' : ''"
@click="getfen(1)"
>
关注
</div>
<div
class="fenleiword"
:class="fenlei == 2 ? 'fenleiactive' : ''"
@click="getfen(2)"
>
点赞
</div>
<div
class="fenleiword"
:class="fenlei == 3 ? 'fenleiactive' : ''"
@click="getfen(3)"
>
评论
</div>
</div>
<div class="nodata" v-if="tiezilist.length == 0">暂无数据</div>
<div class="mycollectlist" v-else>
<van-list
v-model="loading"
:finished="finished"
finished-text="没有更多了"
@load="onLoad"
>
<mytiezi :tiezilist="tiezilist" :showpull="showpull" :fenlei="fenlei" :show="show"/>
</van-list>
</div>
</div>
</template>
<script>
import mytiezi from "@/components/mytiezi.vue";
import {richTextFormat} from "../../../utils/base.js" //富文本超出显示省略号
export default {
components: {
mytiezi
},
data() {
return {
page: 1,
tiezilist: [],
showpull: true,
loading: false,
finished: false,
fenlei: 0,
show:false
};
},
created() {
this.fenlei = this.$route.query.type;
if (this.fenlei == 0) {
this.getfabu();
} else if (this.fenlei == 1) {
this.getguanzhu();
} else if (this.fenlei == 2) {
this.getdainzian();
} else if (this.fenlei == 3) {
this.getpinglun();
}
},
methods: {
onLoad() {
// 异步更新数据
// setTimeout 仅做示例,真实场景中一般为 ajax 请求
setTimeout(() => {
let newpage = this.page;
newpage++;
this.page = newpage;
if (this.fenlei == 0) {
this.getfabu();
} else if (this.fenlei == 1) {
this.getguanzhu();
} else if (this.fenlei == 2) {
this.getdainzian();
} else if (this.fenlei == 3) {
this.getpinglun();
}
// 加载状态结束
this.loading = false;
// 数据全部加载完成
if (this.showpull == false) {
this.finished = true;
}
}, 1000);
},
// 头部切换
getfen(id) {
this.fenlei = id;
this.page = 1;
this.tiezilist = [];
if (this.fenlei == 0) {
this.getfabu();
} else if (this.fenlei == 1) {
this.getguanzhu();
} else if (this.fenlei == 2) {
this.getdainzian();
} else if (this.fenlei == 3) {
this.getpinglun();
}
},
// 获取我的发布
getfabu() {
let that = this;
var url = "/api/forum/get_my_forum";
var params = {
page: that.page,
pageNum: 10
};
console.log("参数", params);
that.$axios
.post(url, params)
.then(res => {
console.log(res);
that.tiezilist = that.tiezilist.concat(res.data);
if (that.page > 1) {
if (res.data.length == 0) {
that.showpull = false;
}
}
that.tiezilist.forEach(function(value,index,array){
value.content=richTextFormat(value.content)
})
that.tiezilist=that.tiezilist;
that.$forceUpdate()
})
.catch(err => {
console.log(err);
});
},
// 获取我的关注
getguanzhu() {
let that = this;
var url = "/api/forum/get_my_forum_attention";
var params = {
page: that.page,
pageNum: 10
};
console.log("参数", params);
that.$axios
.post(url, params)
.then(res => {
console.log(res);
that.tiezilist = that.tiezilist.concat(res.data);
if (that.page > 1) {
if (res.data.length == 0) {
that.showpull = false;
}
}
setTimeout(function(){
that.show=true
},200)
console.log('帖子列表',that.tiezilist)
})
.catch(err => {
console.log(err);
});
},
// 获取论我的点赞
getdainzian() {
let that = this;
var url = "/api/forum/get_my_forum_praise";
var params = {
page: that.page,
pageNum: 10
};
console.log("参数", params);
that.$axios
.post(url, params)
.then(res => {
console.log(res);
that.tiezilist = that.tiezilist.concat(res.data);
if (that.page > 1) {
if (res.data.length == 0) {
that.showpull = false;
}
}
that.tiezilist.forEach(function(value,index,array){
value.content=richTextFormat(value.content)
})
that.tiezilist=that.tiezilist;
that.$forceUpdate()
})
.catch(err => {
console.log(err);
});
},
// 获取我的评论
getpinglun() {
let that = this;
var url = "/api/forum/get_my_forum_comments";
var params = {
page: that.page,
pageNum: 10
};
console.log("参数", params);
that.$axios
.post(url, params)
.then(res => {
console.log(res);
that.tiezilist = that.tiezilist.concat(res.data);
if (that.page > 1) {
if (res.data.length == 0) {
that.showpull = false;
}
}
that.tiezilist.forEach(function(value,index,array){
value.content=richTextFormat(value.content)
})
that.tiezilist=that.tiezilist;
that.$forceUpdate()
})
.catch(err => {
console.log(err);
});
}
}
};
</script>
<style scoped>
@import "../../style/homepage.css";
.mycollectlist {
margin-top: 1rem;
}
.nodata {
color: #999;
font-size: 0.28rem;
text-align: center;
margin-top: 1.5rem;
}
</style>