Skip to content

Commit bc21348

Browse files
committed
加入点赞
1 parent dc9a04f commit bc21348

File tree

1 file changed

+55
-12
lines changed

1 file changed

+55
-12
lines changed

src/components/Content/Article.vue

+55-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template lang="html">
2-
<div class="article-detail">
2+
<div @scroll="toScroll($event)" class="article-detail">
33

44
<div v-show="!isLoading" class="body">
55

@@ -33,7 +33,8 @@
3333
<router-link :to="{name: 'user', params: {name: item.author && item.author.loginname}}">{{item.author.loginname}}</router-link>
3434
{{index+1}}楼 • {{changeTime(item.create_at)}}
3535
<span @click="currentIndex=index" class="reply-at">回复</span>
36-
<i @click="ups(index)" :class="[currentUps===index ? 'ups-yes' : 'ups-no']" class="icon-reply-at"></i>
36+
<i @click="ups(index, item.id, item)" :class="[item.ups.indexOf(userInfo.id) !== -1 ? 'ups-yes' : 'ups-no']" class="icon-reply-at"></i>
37+
<span class="ups-count">{{ item.ups.length }}</span>
3738
</div>
3839
</div>
3940
</div>
@@ -76,9 +77,11 @@ export default {
7677
replyOneContent: '',
7778
isReplyOne: false,
7879
isUps: false,
80+
flag: true,
81+
up: 0,
7982
currentIndex: null, // 回复某个人的 index
80-
currentUps: null
81-
83+
currentUps: null,
84+
oArticleDetail: {}
8285
}
8386
},
8487
created() {
@@ -88,7 +91,6 @@ export default {
8891
this.axios.get('https://cnodejs.org/api/v1/topic/' + this.id)
8992
.then(result => result.data.data)
9093
.then(data => this.infos = data)
91-
.then(data => console.log('data', data))
9294
.then(() => this.$store.commit('viewArcticle', false))
9395
.then(() => {
9496
this.oImgs = document.querySelector('.md').querySelectorAll('img');
@@ -97,6 +99,9 @@ export default {
9799
}
98100
})
99101
},
102+
mounted() {
103+
this.oArticleDetail = document.getElementById('article-detail');
104+
},
100105
computed: {
101106
isLoading() {
102107
return this.$store.state.isLoading;
@@ -126,6 +131,9 @@ export default {
126131
127132
},
128133
methods: {
134+
toScroll(event) {
135+
this.oArticleDetail = event.target;
136+
},
129137
collect() {
130138
if (!this.ak) {
131139
this.$store.commit('showLogin', true);
@@ -152,6 +160,7 @@ export default {
152160
})
153161
}
154162
},
163+
155164
reply(id, name) {
156165
if (!this.ak) {
157166
this.$store.commit('showLogin', true);
@@ -161,18 +170,48 @@ export default {
161170
this.axios.post(`https://cnodejs.org/api/v1/topic/${this.id}/replies`, {
162171
accesstoken: this.ak,
163172
content: this.replyContent
164-
}).then(() => location.reload())
173+
}).then(() => {
174+
this.axios.get('https://cnodejs.org/api/v1/topic/' + this.id)
175+
.then(result => result.data.data)
176+
.then(data => this.infos = data)
177+
.then(() => {
178+
this.oArticleDetail.scrollTop = this.oArticleDetail.scrollHeight;
179+
this.replyContent ='';
180+
})
181+
})
165182
} else {
166-
console.log('id', id);
167183
this.axios.post(`https://cnodejs.org/api/v1/topic/${this.id}/replies`, {
168184
accesstoken: this.ak,
169185
content: '@' + name + ' ' + this.replyOneContent,
170186
reply_id: id
171-
}).then(() => location.reload())
187+
}).then(() => {
188+
this.axios.get('https://cnodejs.org/api/v1/topic/' + this.id)
189+
.then(result => result.data.data)
190+
.then(data => this.infos = data)
191+
.then(() => {
192+
this.oArticleDetail.scrollTop = this.oArticleDetail.scrollHeight;
193+
this.currentIndex = null;
194+
this.replyOneContent = ''
195+
})
196+
})
172197
}
173198
},
174-
ups(index) {
175-
this.currentUps === index ? this.currentUps = null : this.currentUps = index;
199+
200+
//点赞
201+
ups(index, upsId, item) {
202+
if (item.author.loginname === this.userInfo.loginname) {
203+
alert('不能自己为自己点赞哦😯')
204+
return;
205+
}
206+
this.axios.post(`https://cnodejs.org/api/v1/reply/${upsId}/ups`, {accesstoken: this.ak})
207+
.then(result => {
208+
if (result.data.success) {
209+
this.axios.get('https://cnodejs.org/api/v1/topic/' + this.id)
210+
.then(result => result.data.data)
211+
.then(data => this.infos = data)
212+
}
213+
})
214+
176215
}
177216
}
178217
}
@@ -309,11 +348,11 @@ export default {
309348
padding-left: 10px;
310349
.reply-at {
311350
position: absolute;
312-
right: 50px;
351+
right: 70px;
313352
}
314353
.icon-reply-at {
315354
position: absolute;
316-
right: 20px;
355+
right: 35px;
317356
top: -2px;
318357
display: inline-block;
319358
width: 20px;
@@ -328,6 +367,10 @@ export default {
328367
background: url('../../common/icons/icon-ups-no.svg') no-repeat;
329368
background-size: contain;
330369
}
370+
span.ups-count {
371+
position: absolute;
372+
right: 20px;
373+
}
331374
}
332375
}
333376
}

0 commit comments

Comments
 (0)