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

Commit ee52a71

Browse files
committed
收藏功能和跳转优化
1 parent c12e541 commit ee52a71

File tree

7 files changed

+54
-14
lines changed

7 files changed

+54
-14
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ npm run dev
3737
- const.js 常量
3838
- utils 一些工具函数
3939
- static 静态图片部分
40+
4041
目前已经完成了绝大部分功能,尚未完成的功能在和遇到的问题在todo中
4142

4243
目前存在的问题
@@ -46,8 +47,8 @@ npm run dev
4647

4748
todo
4849

49-
- 帖子收藏和取消收藏功能
50-
- 评论点赞和收藏的UI同步 // 好像后端有bug
50+
- 帖子收藏和取消收藏功能 // API字段有问题
51+
- 评论点赞和收藏的UI同步 // API那个字段有点问题
5152
- 编辑自己发过的主题
5253
- 展示未读消息数和消息已读
5354

@@ -59,7 +60,7 @@ todo
5960

6061
后话:
6162

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

6465
效果图
6566

src/App.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<script>
22
export default {
3-
}
3+
onError(err) {
4+
console.log(err);
5+
}
6+
};
47
</script>

src/components/card.vue

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,11 @@ export default {
4444
methods: {
4545
goAuthorPage(e) {
4646
// e.currentTarget.dataset.author
47-
console.log(e);
48-
wx.setStorageSync("loginname", e.currentTarget.dataset.loginname);
49-
wx.navigateTo({ url: "../user/main" });
47+
wx.navigateTo({ url: `../user/main?loginname=${e.currentTarget.dataset.loginname}`});
5048
},
5149
goDetail() {
52-
wx.setStorageSync("topicid", this.item.id);
5350
wx.navigateTo({
54-
url: "../detail/main"
51+
url: `../detail/main?topicid=${this.item.id}`
5552
});
5653
}
5754
}

src/pages/detail/index.vue

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
<img class='author-img' :src='detailData.author && detailData.author.avatar_url' alt="头像">
1010
<span class='name'>{{detailData.author&& detailData.author.loginname}}</span>
1111
</div>
12-
<span>楼主</span>
12+
<div class='list'><img @click.stop="collect" :src="detailData.is_collect?'../../../static/star2.png':'../../../static/star1.png'" style='width:40rpx;height:40rpx;'><span>楼主</span></div>
1313
</div>
14-
1514
<scroll-view class='body' scroll-y='true' :scroll-top="top" enable-back-to-top='true' @scrolltolower='getMore'>
1615
<div class='title'>
1716
<p class='big'>{{detailData.title}}</p>
@@ -79,7 +78,7 @@ export default {
7978
8079
methods: {
8180
async getData() {
82-
this.id = wx.getStorageSync("topicid");
81+
//this.id = wx.getStorageSync("topicid");
8382
wx.showLoading({
8483
title: "加载中"
8584
});
@@ -95,8 +94,41 @@ export default {
9594
} else {
9695
}
9796
},
97+
async collect() {
98+
const accesstoken = wx.getStorageSync("accesstoken");
99+
const topic_id = this.id;
100+
if (this.detailData.is_collect) {
101+
// /topic_collect/de_collect
102+
const res = await this.$http.post(`${api}/topic_collect/de_collect`, {
103+
accesstoken,
104+
topic_id
105+
});
106+
if (res.data.success) {
107+
wx.showToast({
108+
title: "取消收藏成功",
109+
icon: "none",
110+
duration: 2000
111+
});
112+
this.detailData.is_collect = false;
113+
}
114+
} else {
115+
// /topic_collect/collect
116+
const res = await this.$http.post(`${api}/topic_collect/collect`, {
117+
accesstoken,
118+
topic_id
119+
});
120+
if (res.data.success) {
121+
wx.showToast({
122+
title: "收藏成功",
123+
icon: "none",
124+
duration: 2000
125+
});
126+
}
127+
this.detailData.is_collect = true;
128+
}
129+
},
98130
goTop() {
99-
console.log(11);
131+
// console.log(11);
100132
setTimeout(() => (this.top = 0));
101133
this.top = 1;
102134
// wx.pageScrollTo({
@@ -179,6 +211,9 @@ export default {
179211
this.sendVisible = false;
180212
}
181213
},
214+
onLoad() {
215+
this.id = this.$root.$mp.query.topicid;
216+
},
182217
data() {
183218
return {
184219
detailData: {},
@@ -214,6 +249,10 @@ $color: rgb(65, 184, 131);
214249
height: 64rpx;
215250
}
216251
}
252+
.list {
253+
display: flex;
254+
align-items: center;
255+
}
217256
}
218257
.body {
219258
height: 90vh;

src/pages/user/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default {
4444
this.tab = e.target.dataset.tab;
4545
},
4646
async getData() {
47-
const loginname = wx.getStorageSync("loginname");
47+
const loginname = this.$root.$mp.query.loginname;
4848
if (loginname) {
4949
const res = await this.$http.get(`${api}/user/${loginname}`);
5050
if (res.data.success) {

static/star1.png

7.32 KB
Loading

static/star2.png

7.72 KB
Loading

0 commit comments

Comments
 (0)