vuepress-theme-reco/components/PageInfo.vue

115 lines
2.8 KiB
Vue
Raw Normal View History

2019-04-15 10:35:40 +08:00
<template>
<div>
<i
class="iconfont reco-account"
2019-05-08 15:13:18 +08:00
v-if="pageInfo.frontmatter.author || $themeConfig.author || $site.title">
<span>{{ pageInfo.frontmatter.author || $themeConfig.author || $site.title }}</span>
2019-04-15 10:35:40 +08:00
</i>
<i
v-if="pageInfo.frontmatter.date"
class="iconfont reco-date">
<span>{{ pageInfo.frontmatter.date | formatDateValue }}</span>
</i>
2019-10-16 15:06:20 +08:00
<i
v-if="showAccessNumber === true"
2019-10-16 15:06:20 +08:00
class="iconfont reco-eye">
<AccessNumber
:idVal="pageInfo.path"
:numStyle="numStyle" />
</i>
<i
v-if="pageInfo.frontmatter.tags"
class="iconfont reco-tag tags">
2019-04-15 10:35:40 +08:00
<span
v-for="(subItem, subIndex) in pageInfo.frontmatter.tags"
:key="subIndex"
class="tag-item"
:class="{ 'active': currentTag == subItem }"
@click="goTags(subItem)">
{{subItem}}
</span>
</i>
</div>
</template>
<script>
2019-10-10 21:35:49 +08:00
// 引入时间格式化js文件
import { formatDate } from '@theme/helpers/utils'
2019-04-15 10:35:40 +08:00
export default {
2019-07-20 19:38:25 +08:00
props: {
pageInfo: {
type: Object,
2019-09-20 13:54:13 +08:00
default () {
return {}
}
2019-07-20 19:38:25 +08:00
},
currentTag: {
type: String,
default: ''
},
showAccessNumber: {
2019-07-20 19:38:25 +08:00
type: Boolean,
default: false
}
},
2019-04-15 10:35:40 +08:00
data () {
return {
numStyle: {
fontSize: '.9rem',
fontWeight: 'normal',
color: '#999'
}
}
},
filters: {
formatDateValue (value) {
if (!value) return ''
// 返回的value的值都是这个样子2019-09-20T18:22:30.000Z
// 对value进行处理
2019-10-10 21:18:58 +08:00
value = value.replace('T', ' ').slice(0, value.lastIndexOf('.'))
// 转化后的value 2019-09-20 18:22:30
2019-10-10 21:18:58 +08:00
// 获取到时分秒
const h = Number(value.substr(11, 2))
const m = Number(value.substr(14, 2))
const s = Number(value.substr(17, 2))
2019-10-10 21:18:58 +08:00
// 判断时分秒是不是 00:00:00 (如果是用户手动输入的00:00:00也会不显示)
if (h > 0 || m > 0 || s > 0) {
2019-10-10 21:35:49 +08:00
// 时分秒有一个> 0 就说明用户输入一个非 00:00:00 的时分秒
return formatDate(value)
2019-10-10 21:18:58 +08:00
} else {
// 用户没有输入或者输入了 00:00:00
return formatDate(value, 'yyyy-MM-dd')
}
}
},
2019-04-15 10:35:40 +08:00
methods: {
goTags (tag) {
this.$router.push({ path: `/tags/${tag}/` })
2019-04-15 10:35:40 +08:00
}
}
}
</script>
<style lang="stylus" scoped>
.iconfont
display inline-block
line-height 1.5rem
&:not(:last-child)
margin-right 1rem
2019-09-20 13:54:13 +08:00
span
2019-10-10 21:18:58 +08:00
margin-left 0.5rem
2019-04-15 10:35:40 +08:00
.tags
.tag-item
2019-10-10 21:18:58 +08:00
cursor pointer
font-family Ubuntu, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif
2019-04-15 10:35:40 +08:00
&.active
color $accentColor
2019-09-20 13:54:13 +08:00
&:hover
2019-04-15 10:35:40 +08:00
color $accentColor
@media (max-width: $MQMobile)
.tags
display block
2019-10-10 21:18:58 +08:00
margin-left 0 !important
2019-04-15 10:35:40 +08:00
</style>