forked from bingoogolapple/bga_issue_blog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlogDetail.Vue
More file actions
executable file
·144 lines (141 loc) · 3.82 KB
/
BlogDetail.Vue
File metadata and controls
executable file
·144 lines (141 loc) · 3.82 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
<template>
<div v-if="issue" class="blog-detail-container">
<div class="title-container">
<span class="title">{{issue.title}}</span>
<ul>
<li class="tag tag-small" v-for="label in issue.labels" :key="label.id" @click="setActiveLabel(label)"
:style="{ backgroundColor: '#' + label.color}">{{label.name}}
</li>
</ul>
<span class="back" @click="back">
<img src="../assets/back-icon.svg"
class="back-icon">返回
</span>
</div>
<div class="comment-container bga-back-top" ref="commentContainer">
<comment :comment="issue"/>
<comment v-for="comment in comments" :key="comment.id" :comment="comment"/>
<add-comment :commentsUrl="issue.comments_url" @addCommentSuccess="handleAddCommentSuccess"/>
</div>
</div>
</template>
<style lang="scss" scoped>
.blog-detail-container {
flex-grow: 1;
display: flex;
overflow-y: auto; // 本来只在 comment-container 上添加 overflow-y: auto 就可以的,在 blog-detail-container 里也添加 overflow-y: auto 是为了兼容 Firefox 和 Android
flex-direction: column;
}
.title-container {
flex: 0 0 48px;
display: flex;
align-items: center;
background-color: #f9fafc;
padding: 0px 50px;
border-top: 1px solid #eeeeee;
border-bottom: 1px solid #eeeeee;
.title {
font-size: 22px;
color: #4b595f;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
ul {
list-style: none;
display: flex;
flex: 1 0 auto;
margin: 0 30px;
}
.back {
flex: 0 0 65px;
font-size: 14px;
color: #4b595f;
margin-right: 30px;
cursor: pointer;
img {
display: inline-block;
margin-right: 10px;
width: 18px;
height: 12px;
object-fit: contain;
}
}
}
.comment-container {
flex-grow: 1;
overflow-y: auto;
padding: 0px 50px;
}
</style>
<script>
import { mapActions } from 'vuex'
import Comment from '../components/Comment.vue'
import AddComment from '../components/AddComment.vue'
export default{
data () {
return {
issue: null,
number: null,
comments: [],
newComment: null
}
},
components: {Comment, AddComment},
methods: {
...mapActions([
'updateActiveLabel'
]),
setActiveLabel (label) {
this.updateActiveLabel(label)
this.$router.push('/')
},
getComments () {
if (this.issue && this.issue.comments > 0) {
this.$gitHubApi.getComments(this, this.issue.comments_url).then(response => {
this.comments = response.data
})
}
},
getIssue () {
this.$gitHubApi.getIssue(this, this.number).then(response => {
this.issue = response.data
this.getComments()
})
},
back () {
this.$router.go(-1)
},
handleAddCommentSuccess (comment) {
this.comments.push(comment)
this.$nextTick(() => {
// 如果这里不加个 setTimeout 的话,Comment 数量太多时不会自动滚动到底部
setTimeout(() => {
let commentContainer = this.$refs.commentContainer
commentContainer.scrollTop = commentContainer.scrollHeight - commentContainer.clientHeight
}, 16)
})
}
},
created () {
if (this.$route.params.issue) {
this.issue = this.$route.params.issue
} else {
if (this.$route.params.number) {
this.number = this.$route.params.number
} else {
this.$router.replace('/')
}
}
},
mounted () {
this.$nextTick(() => {
if (this.issue) {
this.getComments()
} else {
this.getIssue()
}
})
}
}
</script>