mirror of https://github.com/halo-dev/halo-admin
Format file size.
parent
8e994922c7
commit
dd61e6cbe3
|
@ -1,7 +1,9 @@
|
|||
import Vue from 'vue'
|
||||
import moment from 'moment'
|
||||
import 'moment/locale/zh-cn'
|
||||
import { timeAgo } from '@/utils/util'
|
||||
import {
|
||||
timeAgo
|
||||
} from '@/utils/util'
|
||||
moment.locale('zh-cn')
|
||||
|
||||
Vue.filter('NumberFormat', function(value) {
|
||||
|
@ -21,3 +23,16 @@ Vue.filter('moment', function(dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
|
|||
})
|
||||
|
||||
Vue.filter('timeAgo', timeAgo)
|
||||
|
||||
Vue.filter('fileSizeFormat', function(value) {
|
||||
if (!value) {
|
||||
return '0 Bytes'
|
||||
}
|
||||
var unitArr = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
||||
var index = 0
|
||||
var srcsize = parseFloat(value)
|
||||
index = Math.floor(Math.log(srcsize) / Math.log(1024))
|
||||
var size = srcsize / Math.pow(1024, index)
|
||||
size = size.toFixed(2)
|
||||
return size + ' ' + unitArr[index]
|
||||
})
|
||||
|
|
|
@ -37,7 +37,10 @@
|
|||
</a-list-item-meta>
|
||||
</a-list-item>
|
||||
<a-list-item>
|
||||
<a-list-item-meta :description="attachment.size">
|
||||
<a-list-item-meta>
|
||||
<template slot="description">
|
||||
{{ attachment.size | fileSizeFormat }}
|
||||
</template>
|
||||
<span slot="title">附件大小:</span>
|
||||
</a-list-item-meta>
|
||||
</a-list-item>
|
||||
|
@ -47,7 +50,10 @@
|
|||
</a-list-item-meta>
|
||||
</a-list-item>
|
||||
<a-list-item>
|
||||
<a-list-item-meta :description="attachment.createTime">
|
||||
<a-list-item-meta>
|
||||
<template slot="description">
|
||||
{{ attachment.createTime | moment }}
|
||||
</template>
|
||||
<span slot="title">上传日期:</span>
|
||||
</a-list-item-meta>
|
||||
</a-list-item>
|
||||
|
|
Loading…
Reference in New Issue