Merge pull request #53 from vuepress-reco/feature/lxb

Feature/lxb
This commit is contained in:
reco_luan 2019-10-09 10:42:06 +08:00 committed by GitHub
commit 18d46f1cdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 18 deletions

View File

@ -5,7 +5,7 @@
v-if="pageInfo.frontmatter.author || $themeConfig.author || $site.title">
<span>{{ pageInfo.frontmatter.author || $themeConfig.author || $site.title }}</span>
</i>
<i class="iconfont reco-date" v-if="pageInfo.frontmatter.date"><span>{{ new Date(pageInfo.frontmatter.date).toLocaleDateString() }}</span></i>
<i class="iconfont reco-date" v-if="pageInfo.frontmatter.date"><span>{{ pageInfo.frontmatter.date | formatDate }}</span></i>
<AccessNumber v-if="isHome !== true" :idVal="pageInfo.path" :numStyle="numStyle"></AccessNumber>
<i class="iconfont reco-tag tags" v-if="pageInfo.frontmatter.tags">
<span
@ -22,6 +22,8 @@
<script>
import AccessNumber from './Valine/AccessNumber'
//js
import { fromatDateTime } from '@theme/util/formatDate.js'
export default {
components: { AccessNumber },
@ -51,7 +53,27 @@ export default {
}
}
},
filters: {
formatDate: function (value) {
if (!value) return ''
// value2019-09-20T18:22:30.000Z
// value
value = value.replace('T', ' ').slice(0,value.lastIndexOf('.'))
// value 2019-09-20 18:22:30
// 00:00:00 (00:00:00)
const h = Number(value.substr(11, 2))
const m = Number(value.substr(14, 2))
const s = Number(value.substr(17, 2))
// > 0 00:00:00
if (h > 0 || m > 0 || s > 0) {
return fromatDateTime(value)
}else {
// 00:00:00
return new Date(value).toLocaleDateString()
}
}
},
methods: {
goTags (tag) {
const base = this.$site.base

21
util/formatDate.js Normal file
View File

@ -0,0 +1,21 @@
/**
* 时间格式化的方法
* 创建时间2019-10-08
* 作者刘晓北
* 邮箱 15732451723@163.com
*/
// 将时间格式化成 YYYY/MM/DD HH:mm:SS
export const fromatDateTime = (time) => {
const date = new Date(time)
const Y = date.getFullYear()
const M = date.getMonth() + 1
const D = date.getDate()
let H = date.getHours()
H = H > 9 ? H : '0' + H
let m = date.getMinutes()
m = m > 9 ? m : '0' + m
let S = date.getSeconds()
S = S > 9 ? S : '0' + S
return Y + '/' + M + '/' + D + ' ' + H + ':' + m + ':' + S
}