import { hash } from "immutable"; // 深拷贝 function deepClone(obj) { let objClone = Array.isArray(obj) ? [] : {}; if (obj && typeof obj === 'object' && obj != null) { for (let key in obj) { if (obj.hasOwnProperty(key)) { if (obj[key] && typeof obj[key] === 'object') { objClone[key] = deepClone(obj[key]); } else { objClone[key] = obj[key]; } } } } return objClone; } // 计算时间 function computeTime(time2) { const t1 = new Date(); const t2 = new Date(time2); return filterTime(t2.getTime() - t1.getTime()); } function filterTime(time) { if (time < 0) { return '已逾期'; } let dd = Math.floor(time/24/60/60/1000), hh = Math.floor(time/60/60/1000-dd*24), mi = Math.floor(time/60/1000-dd*24*60-hh*60); console.log(dd, hh, mi) return addDay(fillTime(dd)) + addHour(fillTime(hh)) + addMin(fillTime(mi)); } function fillTime(num) { if (num < 10) { return '0' + num; } return num; } function addDay(str) { str = parseFloat(str); if (str <= 0) { return; } return str + '天' } function addHour(str) { str = parseFloat(str); if (str <= 0) { return; } return str + '小时' } function addMin(str) { str = parseFloat(str); if (str <= 0) { return; } return str + '分钟' } export { deepClone, computeTime };