1
1
<template >
2
2
<div class =" content" >
3
3
<div class =" detail-box" >
4
+ <h2 class =" detail-title van-ellipsis" >
5
+ <van-tag type =" primary" class =" tag" >{{ articleType }}</van-tag
6
+ >{{ info.articleTitle }}
7
+ </h2 >
8
+ <div class =" flex row" >
9
+ <span >{{ time }}</span >
10
+ <nuxt-link class =" theme-color" :to =" `/about/${authorInfo.authorId}`" >
11
+ {{ authorInfo.authorName }}
12
+ </nuxt-link >
13
+ </div >
14
+ <div class =" flex row" >
15
+ <span >views: {{ info.articleView }}</span >
16
+ <van-button plain type =" info" size =" small" @click =" addStar"
17
+ >star: {{ info.articleStart }}</van-button
18
+ >
19
+ </div >
20
+ <div class =" toc-btn flex" @click =" tocShow = !tocShow" >
21
+ <van-icon v-if =" !tocShow" name =" arrow-left" />
22
+ <van-icon v-else name =" arrow" />
23
+ <span >目录</span >
24
+ </div >
4
25
<div
26
+ :class =" { 'no-toc': !tocShow }"
5
27
class =" detail-article markdown-body"
6
- v-html =" detailInfo. info.articleContentHtml"
28
+ v-html =" info.articleContentHtml"
7
29
></div >
8
30
</div >
9
31
</div >
10
32
</template >
11
33
12
34
<script >
35
+ import dayjs from ' dayjs'
36
+ import ' highlight.js/scss/default.scss'
13
37
import ' github-markdown-css/github-markdown.css'
38
+ import ' highlight.js/styles/vs2015.css'
14
39
15
40
export default {
16
41
name: ' Detail' ,
@@ -26,26 +51,151 @@ export default {
26
51
detailInfo = result .data
27
52
}
28
53
return {
29
- detailInfo
54
+ ... detailInfo
30
55
}
31
56
},
32
57
data () {
33
- return {}
58
+ return {
59
+ tocShow: false
60
+ }
61
+ },
62
+ computed: {
63
+ articleType () {
64
+ let result
65
+ switch (this .info .articleNature ) {
66
+ case 0 :
67
+ result = ' 原创'
68
+ break
69
+ case 1 :
70
+ result = ' 转载'
71
+ break
72
+ case 2 :
73
+ result = ' 翻译'
74
+ break
75
+ default :
76
+ result = ' 原创'
77
+ break
78
+ }
79
+ return result
80
+ },
81
+ time () {
82
+ return dayjs (this .info .articleUpdateTime ).format (' YYYY-MM-DD HH:mm:ss' )
83
+ }
84
+ },
85
+ methods: {
86
+ async addStar () {
87
+ const result = await this .$axios .$post (' /api/vue-blog/addStar' , {
88
+ articleId: this .$route .params .id * 1
89
+ })
90
+ if (result .isok ) {
91
+ this .$toast .success (' Add star success' )
92
+ this .info .articleStart = result .data .articleStart
93
+ }
94
+ }
34
95
}
35
96
}
36
97
</script >
37
98
38
99
<style lang="scss" scoped>
39
100
.detail-box {
40
101
margin : 15px 0 ;
102
+ padding : 0 15px ;
41
103
background-color : #fff ;
104
+ .detail-title {
105
+ padding : 15px 0 10px ;
106
+ font-size : 18px ;
107
+ .tag {
108
+ margin-right : 3px ;
109
+ vertical-align : top ;
110
+ margin-top : 5px ;
111
+ }
112
+ }
113
+ .row {
114
+ justify-content : space-between ;
115
+ font-size : 16px ;
116
+ line-height : 30px ;
117
+ }
118
+ .toc-btn {
119
+ position : fixed ;
120
+ top : 68% ;
121
+ right : 0 ;
122
+ z-index : 1000 ;
123
+ height : 30px ;
124
+ font-size : 14px ;
125
+ padding : 0 8px ;
126
+ background-color : #fff ;
127
+ border : 1px solid #dedede ;
128
+ border-right : 0 ;
129
+ border-radius : 15px 0 0 15px ;
130
+ }
42
131
.detail-article {
43
- padding : 15px ;
132
+ position : relative ;
133
+ padding : 0 0 15px ;
134
+ font-size : 16px ;
44
135
& .markdown-body {
45
136
/deep / {
46
137
ol {
47
138
list-style : decimal ;
48
139
}
140
+ ul {
141
+ list-style : disc ;
142
+ }
143
+ .markdownIt-TOC {
144
+ position : fixed ;
145
+ right : 15px ;
146
+ z-index : 10 ;
147
+ background-color : #fff ;
148
+ box-shadow : -2px 2px 4px #ccc ;
149
+ & .markdownIt-TOC ::before {
150
+ content : ' 文章目录:' ;
151
+ font-weight : 700 ;
152
+ color : currentColor ;
153
+ margin-left : -1.5em ;
154
+ line-height : 26px ;
155
+ }
156
+ }
157
+ pre {
158
+ background : #1e1e1e !important ;
159
+ }
160
+ pre .hljs {
161
+ padding : 14px 2px ;
162
+ border-radius : 5px ;
163
+ position : relative ;
164
+ ol {
165
+ list-style : decimal ;
166
+ margin : 0 ;
167
+ margin-left : 40px ;
168
+ padding : 0 ;
169
+ li {
170
+ list-style : decimal-leading-zero ;
171
+ position : relative ;
172
+ padding-left : 10px ;
173
+ .line-num {
174
+ position : absolute ;
175
+ left : -40px ;
176
+ top : 0 ;
177
+ width : 40px ;
178
+ height : 100% ;
179
+ border-right : 1px solid rgba (0 , 0 , 0 , 0.66 );
180
+ }
181
+ }
182
+ }
183
+ b .name {
184
+ position : absolute ;
185
+ top : 2px ;
186
+ right : 12px ;
187
+ z-index : 10 ;
188
+ color : #999 ;
189
+ pointer-events : none ;
190
+ }
191
+ }
192
+ }
193
+ & .no-toc {
194
+ /deep / {
195
+ .markdownIt-TOC {
196
+ display : none ;
197
+ }
198
+ }
49
199
}
50
200
}
51
201
}
0 commit comments