let timeout = null; let timer; let flag; export default { formatDate (date,val) { let y = date.getFullYear(); let m = date.getMonth()+1; let d = date.getDate(); let h = date.getHours(); let mm = date.getMinutes(); let s = date.getSeconds(); if(m <= 9){ m = '0' + m; } if(d <= 9){ d = '0' + d; } if(h <= 9){ h = '0' + h; } if(mm <= 9){ mm = '0' + mm; } if(s <= 9){ s = '0' + s; } let tmpTime = ''; if(val == 0){ tmpTime = `${h}:${mm}`; }else if(val == 1){ tmpTime = `${m}-${d}`; }else if(val == 2){ tmpTime = `${y}-${m}-${d} ${h}:${mm}:${s}`; }else if(val == 3){ tmpTime = `${y}-${m}-${d}`; }else if(val == 4){ tmpTime = `${y}-${m}-${d} ${h}:${mm}`; } return tmpTime; },  myToast(str = '',time = 1000){ if(str){ uni.hideToast(); setTimeout(()=>{ uni.showToast({ icon:'none', title:str, mask:true, duration:time }) },100) }else{ uni.showToast({ icon:'loading', title:'请求中...', mask:true, duration:1000 }) } }, debounce(func,wait = 1000,immediate = true){ // 清除定时器 if (timeout !== null) clearTimeout(timeout) // 立即执行,此类情况一般用不到 if (immediate) { const callNow = !timeout timeout = setTimeout(() => { timeout = null }, wait) if (callNow) typeof func === 'function' && func() } else { // 设置定时器,当最后一次操作后,timeout不会再被清除,所以在延时wait毫秒后执行func回调方法 timeout = setTimeout(() => { typeof func === 'function' && func() }, wait) } }, checkInputNum(value,max = null,num = null){ if(max === 0){ return ''; } // value = value.replace(/^0*/g, ''); // 第一个数不能为0 ,若为0替换为空 value = value.replace(/[^\d]/g,''); // 是否是数字,若是除数字之外的则替换为空 if(num && value.length > num){ value = value.substr(0, num); } if(max && (Number(value) >= Number(max))){ value = max; } return value; }, checkInputPrice(value,max = null) { if(max === 0){ return ''; } // value = value.replace(/^0*/g, ''); // 第一个数不能为0 ,若为0替换为空 value = value.replace(/[^\d.]/g, ""); // 是否是数字 和小数点,若是除数字 和小数点之外的则替换为空 value = value.replace(/^\./g, ""); // 确证第一个为数字而不是“.” value = value.replace(/\.{2,}/g, "."); // 只能输入一个“.” value = value.replace(".", "$#$").replace(/\./g, "").replace("$#$", "."); // 保证”.“只出现一次,而不能出现两次以上 value = value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); // 只能输入两个小数 if(max && value >= max){ value = max; } return value; }, addressTurn(val,num = 9) { if (val.length < 10) { return val } else { let str = val.slice(num, val.length - num) val = val.replace(str, '...') return val } }, }