const monent = require('../moment/moment') function percentage(value: any) { return (value * 100).toFixed(2) + '%' } function changeTime(time: any, type: any) { let format: any = "" if (type === 'hour' || type === 'day') { format = monent(time).format('HH:mm') } else if (type === 'week') { format = monent(time).format('MM-DD HH:mm') } else if (type === 'month') { format = monent(time).format('MM-DD') } else { format = monent(time).format('YYYY-MM-DD HH:mm:ss') } return format; } function changeSize(value: any, unit: any = '') { let val = value ? value : '无'; if (value >= 1024 && value / 1024 < 1024) { val = (value / 1024).toFixed(2) + 'K' + unit; } else if (value / 1024 >= 1024 && value / 1024 / 1024 < 1024) { val = (value / 1024 / 1024).toFixed(2) + 'M' + unit; } else if (value / 1024 / 1024 >= 1024) { val = (value / 1024 / 1024 / 1024).toFixed(2) + 'G' + unit; } else { val = value + unit } return val; } export default { percentage, changeTime, changeSize, }