export function arrToIds(arr){ var new_ids = ''; for(var i = 0; i < arr.length; i++){ new_ids += ','+arr[i].id; } if(new_ids!=''){ new_ids = new_ids.substr(1); } return new_ids; } // 时间格式化 export function timeDate(timestamp) { var date = new Date(timestamp) var Y = date.getFullYear() + '-' var M = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) + '-' : (date.getMonth() + 1) + '-' var D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() return Y + M + D } /** * 函数防抖 (只执行最后一次点击) */ export const Debounce = (fn, t) => { let delay = t || 500; let timer; console.log(fn) console.log(typeof fn) return function () { let args = arguments; if(timer){ clearTimeout(timer); } timer = setTimeout(() => { timer = null; fn.apply(this, args); }, delay); } }; /* * 函数节流 */ export const Throttle = (fn, t) => { let last; let timer; let interval = t || 500; return function () { let args = arguments; let now = + new Date(); if (last && now - last < interval) { clearTimeout(timer); timer = setTimeout(() => { last = now; fn.apply(this, args); }, interval); } else { last = now; fn.apply(this, args); } } };