export function dateFormat(date, format = 'YYYY-MM-DD HH:mm:ss'){ const config = { YYYY: date.getFullYear(), MM: date.getMonth()<9?'0'+Number(date.getMonth()+1):Number(date.getMonth()+1), DD: date.getDate()<10?'0'+date.getDate():date.getDate(), HH: date.getHours()<10?'0'+date.getHours():date.getHours(), mm: date.getMinutes()<10?'0'+date.getMinutes():date.getMinutes(), ss: date.getSeconds()<10?'0'+date.getSeconds():date.getSeconds(), } for (const key in config) { format = format.replace(key, config[key]) } return format } export function unitConvert(num) { var moneyUnits = ["元", "万元", "亿元", "万亿"] var dividend = 10000; var curentNum = Number(num); //转换数字 var curentUnit = moneyUnits[0]; //转换单位 for (var i = 0; i <4; i++) { curentUnit = moneyUnits[i] if(strNumSize(curentNum)<5){ break; } curentNum = curentNum / dividend } var m = {num: 0, unit: ""} m.num = curentNum.toFixed(2) m.unit = curentUnit; return m; } export function strNumSize(tempNum){ var stringNum = tempNum.toString() var index = stringNum.indexOf(".") var newNum = stringNum; if(index!=-1){ newNum = stringNum.substring(0,index) } return newNum.length }