export function parseTime(time) { if (!time) { return '--' } let date if (typeof time === 'object') { date = time } else { if (typeof time === 'string') { if (/^[0-9]+$/.test(time)) { time = parseInt(time) } else { time = time.replace(new RegExp(/-/gm), '/') } } date = new Date(time) } const formatRes = { y: date.getFullYear(), M: (date.getMonth() + 1 + '').padStart(2, 0), d: (date.getDate() + '').padStart(2, 0), h: (date.getHours() + '').padStart(2, 0), m: (date.getMinutes() + '').padStart(2, 0), s: (date.getSeconds() + '').padStart(2, 0), week: ['日', '一', '二', '三', '四', '五', '六'][date.getDay()] } // formatRes.M < 10 && (formatRes.M = '0' + formatRes.M) // formatRes.d < 10 && (formatRes.d = '0' + formatRes.d) // formatRes.h < 10 && (formatRes.h = '0' + formatRes.h) // formatRes.m < 10 && (formatRes.m = '0' + formatRes.m) // formatRes.s < 10 && (formatRes.s = '0' + formatRes.s) return formatRes } // 防抖 export function debounce(fn, delay) { let timer = null function _implementer(...args) { if (timer) clearTimeout(timer) let _this = this timer = setTimeout(function () { fn.call(_this, ...args) }, delay) } _implementer.cancel = () => { clearTimeout(timer) } return _implementer } // 车牌校验 export function isLicensePlate(number) { let instance = new RegExp( '^([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[a-zA-Z](([DF]((?![IO])[a-zA-Z0-9](?![IO]))[0-9]{4})|([0-9]{5}[DF]))|[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1})$' ) return instance.test(number) } // 类型判断 export function typeJudgment(object) { let res = {}.__proto__.toString.call(object) let type = /(?<= ).+(?=\])/.exec(res) return type.length ? type[0] : '' } // 油批项目专用 保留两位小数,第三位小数四舍五入 export function fixedHandle(val) { val = parseFloat(val) if (!isNaN(val)) { let fixedLength4 = val.toFixed(4) let length = fixedLength4.length let fixedLength3 = fixedLength4.slice(0, length - 1) fixedLength3 *= 100 fixedLength3 = Math.round(fixedLength3) fixedLength3 /= 100 let fixedLength2 = fixedLength3.toFixed(2) return fixedLength2 } return 0 }