Skip to content
This repository was archived by the owner on Jul 30, 2020. It is now read-only.

Commit c12e541

Browse files
committed
添加到顶部和评论惰性渲染
1 parent ca4a67d commit c12e541

File tree

3 files changed

+58
-21
lines changed

3 files changed

+58
-21
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,22 @@ npm run dev
4141

4242
目前存在的问题
4343

44-
~~小程序无法动态插入dom,markdwon的解析有点问题, [wemark](https://github.com/TooBug/wemark)在mpvue上使用需要改造下。已封装[mpvue-wemark](https://github.com/673800357/mpvue-wemark)解决
44+
小程序无法动态插入dom,markdwon的解析有点问题, [wemark](https://github.com/TooBug/wemark)在mpvue上使用需要改造下。已封装[mpvue-wemark](https://github.com/673800357/mpvue-wemark)解决
4545

4646

4747
todo
4848

4949
- 帖子收藏和取消收藏功能
5050
- 评论点赞和收藏的UI同步 // 好像后端有bug
51-
- 帖子详情页加载评论时惰性渲染和回到顶部
5251
- 编辑自己发过的主题
5352
- 展示未读消息数和消息已读
54-
- 部分页面添加下拉刷新
55-
- 请求失败状态码非200会抛异常,如何统一优雅处理
53+
54+
55+
优化
56+
- 请求失败状态码非200会抛异常,如何统一优雅处理
57+
- 部分页面添加下拉刷新
58+
- 到顶部代码不清真。
59+
5660
后话:
5761

5862
这个项目没有涉及到太多复杂的部分,主要到是业务逻辑的开发,对于作为一个vue和mpvue小程序入门项目是非常合适的。由于开发时间短,部分代码质量和交互做得不太好。对于未完成的部分和部分未知bug欢迎各位star、提issue、提pr一起来玩2333.

src/pages/detail/index.vue

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class='container'>
2+
<div class='container'>
33
<div v-if='sendVisible'>
44
<sendReply @close-modal='closeModal' @reply-success='replySuccess' :content='content' :topicId='id' :replyId='replyId'></sendReply>
55
</div>
@@ -11,7 +11,8 @@
1111
</div>
1212
<span>楼主</span>
1313
</div>
14-
<div class='body'>
14+
15+
<scroll-view class='body' scroll-y='true' :scroll-top="top" enable-back-to-top='true' @scrolltolower='getMore'>
1516
<div class='title'>
1617
<p class='big'>{{detailData.title}}</p>
1718
<div class='time-info'>
@@ -20,6 +21,7 @@
2021
<span>评论:{{detailData.reply_count}}</span>
2122
</div>
2223
</div>
24+
<img class='up-png' src="../../../static/up.png" mode='widthFix' @click.stop="goTop">
2325
<div v-if='!sendVisible' class='reply-buton' @click.stop="showReplyModal">评论</div>
2426
<div class='content'>
2527
<wemark :mdData='detailData.content'></wemark>
@@ -43,7 +45,7 @@
4345
</div>
4446
</div>
4547
</div>
46-
</div>
48+
</scroll-view>
4749
</div>
4850
</div>
4951
</template>
@@ -66,18 +68,12 @@ export default {
6668
return passTime(this.detailData.create_at);
6769
},
6870
formatReplies() {
69-
return (
70-
this.detailData &&
71-
this.detailData.replies &&
72-
this.detailData.replies
73-
.map(_ => {
74-
return {
75-
..._,
76-
create_at: passTime(_.create_at)
77-
};
78-
})
79-
.reverse()
80-
);
71+
return this.currentReplies.map(_ => {
72+
return {
73+
..._,
74+
create_at: passTime(_.create_at)
75+
};
76+
});
8177
}
8278
},
8379
@@ -93,10 +89,35 @@ export default {
9389
wx.hideLoading();
9490
if (res.data.success) {
9591
this.detailData = res.data.data;
92+
this.currentReplies = res.data.data.replies.reverse().splice(0, 10);
93+
this.remainReplies = res.data.data.replies;
9694
//this.article = res.data.content;
9795
} else {
9896
}
9997
},
98+
goTop() {
99+
console.log(11);
100+
setTimeout(() => (this.top = 0));
101+
this.top = 1;
102+
// wx.pageScrollTo({
103+
// scrollTop: 500,
104+
// duration: 300
105+
// });
106+
},
107+
getMore() {
108+
if (this.remainReplies.length > 0) {
109+
this.currentReplies = [
110+
...this.currentReplies,
111+
...this.remainReplies.splice(0, 10)
112+
];
113+
} else {
114+
wx.showToast({
115+
title: "无更多数据",
116+
icon: "none",
117+
duration: 2000
118+
});
119+
}
120+
},
100121
async upOrCancel(e) {
101122
// / todo 防抖
102123
// console.log(e);
@@ -161,10 +182,13 @@ export default {
161182
data() {
162183
return {
163184
detailData: {},
185+
remainReplies: [],
186+
currentReplies: [],
164187
content: "",
165188
sendVisible: false,
166189
id: "",
167-
replyId: ""
190+
replyId: "",
191+
top: 0
168192
};
169193
}
170194
};
@@ -173,7 +197,7 @@ export default {
173197
<style lang='scss' scoped>
174198
$color: rgb(65, 184, 131);
175199
.container {
176-
min-height: 100vh;
200+
height: 100vh;
177201
background-color: rgb(245, 245, 239);
178202
.header {
179203
display: flex;
@@ -191,6 +215,9 @@ $color: rgb(65, 184, 131);
191215
}
192216
}
193217
}
218+
.body {
219+
height: 90vh;
220+
}
194221
.title {
195222
background-color: white;
196223
margin-bottom: 20rpx;
@@ -216,6 +243,12 @@ $color: rgb(65, 184, 131);
216243
left: 81vw;
217244
color: white;
218245
}
246+
.up-png {
247+
width: 100rpx;
248+
top: 75vh;
249+
left: 81vw;
250+
position: fixed;
251+
}
219252
.content {
220253
background-color: white;
221254
margin-bottom: 20rpx;

static/up.png

2.77 KB
Loading

0 commit comments

Comments
 (0)