2025-08-13 00:05:08 +08:00
|
|
|
|
|
2025-09-12 17:56:35 +08:00
|
|
|
|
let timeout = null;
|
|
|
|
|
|
let timer;
|
|
|
|
|
|
let flag;
|
2025-08-13 00:05:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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}`;
|
|
|
|
|
|
}
|
|
|
|
|
|
return tmpTime;
|
|
|
|
|
|
},
|
2025-09-12 17:56:35 +08:00
|
|
|
|
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)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-08-13 00:05:08 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|