export function findCodeLabel(codes,val) { if(!codes) return val; let item = codes.find(item=>item.value==val) if(!item) return val; return item.label } export function dateFormat (date, format) { if(!date) return date if(typeof date == 'string') date = new Date(date) let _format = format || 'yyyy-MM-dd'; const d = date; const o = { 'M+' : d.getMonth() + 1, // month 'd+' : d.getDate(), // day 'h+' : d.getHours(), // hour 'm+' : d.getMinutes(), // minute 's+' : d.getSeconds(), // second 'q+' : Math.floor((d.getMonth() + 3) / 3), // quarter 'S' : d.getMilliseconds() // millisecond }; if (/(y+)/.test(_format)) { _format = _format.replace(RegExp.$1, (d.getFullYear() + '').substr(4 - RegExp.$1.length)); } for (const k in o) { if (o.hasOwnProperty(k) && new RegExp('(' + k + ')').test(_format)) { _format = _format.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)); } } return _format; } // 数字展示成金额 export function moneyFormat(value, precision = 2) { //0 let num = value if (num == 0) { return num.toLocaleString(); } if (num) { num = typeof num == 'string' ? parseFloat(num) : num num = num.toFixed(precision); num = parseFloat(num); num = num.toLocaleString(); return num; } else { return num = null; } } export default { install(Vue){ Vue.prototype.findCodeLabel = findCodeLabel Vue.prototype.dateFormat = dateFormat Vue.prototype.moneyFormat = moneyFormat } }