1
1
<template lang="html">
2
- <div class =" article-detail" >
2
+ <div @scroll = " toScroll($event) " class =" article-detail" >
3
3
4
4
<div v-show =" !isLoading" class =" body" >
5
5
33
33
<router-link :to =" {name: 'user', params: {name: item.author && item.author.loginname}}" >{{item.author.loginname}}</router-link>
34
34
{{index+1}}楼 • {{changeTime(item.create_at)}}
35
35
<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>
37
38
</div>
38
39
</div>
39
40
</div>
@@ -76,9 +77,11 @@ export default {
76
77
replyOneContent: ' ' ,
77
78
isReplyOne: false ,
78
79
isUps: false ,
80
+ flag: true ,
81
+ up: 0 ,
79
82
currentIndex: null , // 回复某个人的 index
80
- currentUps: null
81
-
83
+ currentUps: null ,
84
+ oArticleDetail : {}
82
85
}
83
86
},
84
87
created () {
@@ -88,7 +91,6 @@ export default {
88
91
this .axios .get (' https://cnodejs.org/api/v1/topic/' + this .id )
89
92
.then (result => result .data .data )
90
93
.then (data => this .infos = data)
91
- .then (data => console .log (' data' , data))
92
94
.then (() => this .$store .commit (' viewArcticle' , false ))
93
95
.then (() => {
94
96
this .oImgs = document .querySelector (' .md' ).querySelectorAll (' img' );
@@ -97,6 +99,9 @@ export default {
97
99
}
98
100
})
99
101
},
102
+ mounted () {
103
+ this .oArticleDetail = document .getElementById (' article-detail' );
104
+ },
100
105
computed: {
101
106
isLoading () {
102
107
return this .$store .state .isLoading ;
@@ -126,6 +131,9 @@ export default {
126
131
127
132
},
128
133
methods: {
134
+ toScroll (event ) {
135
+ this .oArticleDetail = event .target ;
136
+ },
129
137
collect () {
130
138
if (! this .ak ) {
131
139
this .$store .commit (' showLogin' , true );
@@ -152,6 +160,7 @@ export default {
152
160
})
153
161
}
154
162
},
163
+
155
164
reply (id , name ) {
156
165
if (! this .ak ) {
157
166
this .$store .commit (' showLogin' , true );
@@ -161,18 +170,48 @@ export default {
161
170
this .axios .post (` https://cnodejs.org/api/v1/topic/${ this .id } /replies` , {
162
171
accesstoken: this .ak ,
163
172
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
+ })
165
182
} else {
166
- console .log (' id' , id);
167
183
this .axios .post (` https://cnodejs.org/api/v1/topic/${ this .id } /replies` , {
168
184
accesstoken: this .ak ,
169
185
content: ' @' + name + ' ' + this .replyOneContent ,
170
186
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
+ })
172
197
}
173
198
},
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
+
176
215
}
177
216
}
178
217
}
@@ -309,11 +348,11 @@ export default {
309
348
padding-left : 10px ;
310
349
.reply-at {
311
350
position : absolute ;
312
- right : 50 px ;
351
+ right : 70 px ;
313
352
}
314
353
.icon-reply-at {
315
354
position : absolute ;
316
- right : 20 px ;
355
+ right : 35 px ;
317
356
top : -2px ;
318
357
display : inline-block ;
319
358
width : 20px ;
@@ -328,6 +367,10 @@ export default {
328
367
background : url (' ../../common/icons/icon-ups-no.svg' ) no-repeat ;
329
368
background-size : contain ;
330
369
}
370
+ span .ups-count {
371
+ position : absolute ;
372
+ right : 20px ;
373
+ }
331
374
}
332
375
}
333
376
}
0 commit comments