Skip to content

Commit 392de18

Browse files
author
reco_luan
committed
fix: Fix bug in tag page
Switch tab button does not display the number of readings.
1 parent b3bd1dd commit 392de18

File tree

7 files changed

+144
-40
lines changed

7 files changed

+144
-40
lines changed

components/Common.vue

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export default {
170170
},
171171
172172
created () {
173-
this.getPostData()
173+
this._getPostData()
174174
},
175175
176176
mounted () {
@@ -233,23 +233,6 @@ export default {
233233
this.firstLoad = false
234234
if (sessionStorage.getItem('firstLoad') == undefined) sessionStorage.setItem('firstLoad', false)
235235
}, time)
236-
},
237-
getPostData () {
238-
if (!this.$themeConfig.posts) {
239-
const {
240-
$categories: { list: articles },
241-
_filterPostData,
242-
_sortPostData
243-
} = this
244-
245-
let posts = articles.reduce((allData, currnetData) => {
246-
return [...allData, ...currnetData.pages]
247-
}, [])
248-
posts = _filterPostData(posts)
249-
_sortPostData(posts)
250-
251-
this.$themeConfig.posts = posts
252-
}
253236
}
254237
},
255238

components/HomeBlog.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ export default {
127127
// reverse()是为了按时间最近排序排序
128128
this.pages = pages.length == 0 ? [] : pages
129129
},
130-
getPagesByTags (currentTag) {
130+
getPagesByTags (tagInfo) {
131+
const currentTag = tagInfo.name
131132
const base = this.$site.base
132133
window.location.href = `${base}tag/?tag=${currentTag}`
133134
},

components/PageInfo.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ export default {
8686
},
8787
methods: {
8888
goTags (tag) {
89-
const base = this.$site.base
90-
window.location.href = `${base}tag/?tag=${tag}`
89+
this.$router.push({ path: `/tags/${tag}/` })
9190
}
9291
}
9392
}

components/TagList.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
:key="index"
66
:class="{'active': item.name == currentTag}"
77
:style="{ 'backgroundColor': _tagColor() }"
8-
@click="tagClick(item.name)">{{item.name}}</span>
8+
@click="tagClick(item)">{{item.name}}</span>
99
</div>
1010
</template>
1111

@@ -22,7 +22,7 @@ export default {
2222
},
2323
computed: {
2424
tags () {
25-
return [{ name: '全部' }, ...this.$tags.list]
25+
return [{ name: '全部', path: '/tag/' }, ...this.$tags.list]
2626
}
2727
},
2828
methods: {

layouts/Tag.vue

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<template>
2+
<div class="tag-wrapper" :class="recoShow ?'reco-show' : 'reco-hide'">
3+
<!-- 公共布局 -->
4+
<Common :sidebar="false" :isComment="false">
5+
<!-- 标签集合 -->
6+
<TagList class="tags" :currentTag="$currentTags.key" @getCurrentTag="tagClick"></TagList>
7+
8+
<!-- 博客列表 -->
9+
<note-abstract
10+
class="list"
11+
:data="posts"
12+
:currentPage="currentPage"
13+
@currentTag="$currentTags.key"></note-abstract>
14+
15+
<!-- 分页 -->
16+
<pagation
17+
class="pagation"
18+
:total="posts.length"
19+
:currentPage="currentPage"
20+
@getCurrentPage="getCurrentPage"></pagation>
21+
</Common>
22+
</div>
23+
</template>
24+
25+
<script>
26+
import Common from '@theme/components/Common.vue'
27+
import NoteAbstract from '@theme/components/NoteAbstract.vue'
28+
import TagList from '@theme/components/TagList.vue'
29+
import mixin from '@theme/mixins/index.js'
30+
31+
export default {
32+
mixins: [mixin],
33+
components: { Common, NoteAbstract, TagList },
34+
35+
data () {
36+
return {
37+
// 当前页码
38+
currentPage: 1,
39+
recoShow: false,
40+
currentTag: '全部',
41+
}
42+
},
43+
44+
computed: {
45+
// 时间降序后的博客列表
46+
posts () {
47+
let posts = this.$currentTags.pages
48+
posts = this._filterPostData(posts)
49+
this._sortPostData(posts)
50+
this._setPage(1)
51+
return posts
52+
},
53+
},
54+
55+
mounted () {
56+
this.recoShow = true
57+
},
58+
59+
methods: {
60+
// 获取当前tag
61+
getCurrentTag (tag) {
62+
this.$emit('currentTag', tag)
63+
},
64+
tagClick (tagInfo) {
65+
this.$router.push({path: tagInfo.path})
66+
},
67+
// 获取当前页码
68+
getCurrentPage (page) {
69+
this._setPage(page)
70+
setTimeout(() => {
71+
window.scrollTo(0, 0)
72+
}, 100)
73+
},
74+
_setPage (page) {
75+
this.currentPage = page
76+
this.$page.currentPage = page
77+
},
78+
}
79+
}
80+
</script>
81+
82+
<style src="../styles/theme.styl" lang="stylus"></style>
83+
84+
<style lang="stylus" scoped>
85+
@require '../styles/recoConfig.styl'
86+
@require '../styles/loadMixin.styl'
87+
.tag-wrapper
88+
max-width: 740px;
89+
margin: 0 auto;
90+
padding: 4.6rem 2.5rem 0;
91+
&.reco-hide {
92+
.tags, .list, .pagation {
93+
load-start()
94+
}
95+
}
96+
&.reco-show {
97+
.tags {
98+
load-end(0.08s)
99+
}
100+
.list {
101+
load-end(0.16s)
102+
}
103+
.pagation {
104+
load-end(0.24s)
105+
}
106+
}
107+
108+
@media (max-width: $MQMobile)
109+
.tag-wrapper
110+
padding: 4.6rem 1rem 0;
111+
</style>

layouts/Tags.vue

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,10 @@ export default {
3939
computed: {
4040
// 时间降序后的博客列表
4141
posts () {
42-
const currentTag = this.currentTag
43-
let posts = []
44-
45-
if (currentTag !== '全部') {
46-
posts = this.$tags.map[currentTag].pages
47-
} else {
48-
posts = this.$themeConfig.posts
49-
}
50-
51-
posts = this._filterPostData(posts)
52-
this._sortPostData(posts)
53-
posts = posts.length == 0 ? [] : posts
54-
this._setPage(1)
55-
return posts
42+
return this.$themeConfig.posts || this.$site.pages
5643
}
5744
},
45+
5846
created () {
5947
if (this.$tags.list.length > 0) {
6048
this.currentTag = this.$route.query.tag ? this.$route.query.tag : this.currentTag
@@ -67,9 +55,8 @@ export default {
6755
6856
methods: {
6957
70-
tagClick (currentTag) {
71-
this.currentTag = currentTag
72-
window.scrollTo(0, 0)
58+
tagClick (tagInfo) {
59+
this.$router.push({ path: tagInfo.path })
7360
},
7461
7562
getCurrentTag (tag) {

mixins/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { promise } from "when"
2+
13
export default {
24
methods: {
35
_tagColor () {
@@ -23,6 +25,27 @@ export default {
2325
// 获取时间的数字类型
2426
_getTimeNum (date) {
2527
return parseInt(new Date(date.frontmatter.date).getTime())
28+
},
29+
// 获取博客数据
30+
_getPostData () {
31+
return new Promise(resolve => {
32+
if (!this.$themeConfig.posts) {
33+
const {
34+
$categories: { list: articles },
35+
_filterPostData,
36+
_sortPostData
37+
} = this
38+
39+
let posts = articles.reduce((allData, currnetData) => {
40+
return [...allData, ...currnetData.pages]
41+
}, [])
42+
posts = _filterPostData(posts)
43+
_sortPostData(posts)
44+
45+
this.$themeConfig.posts = posts
46+
resolve(posts)
47+
}
48+
})
2649
}
2750
}
2851
}

0 commit comments

Comments
 (0)