tree to array 【扁平化数据】
export const treeToArray = (data) => {
return data.reduce((res,{children = [], ...params}) => {
return res.concat([params],treeToArray(children))
},[])
}
防抖
export function simpleDebounce(fn, delay = 500) {
let timer = null
return function () {
let args = arguments
if (timer) {
clearTimeout(timer)
}
timer = setTimeout(() => {
fn.apply(this, args)
}, delay)
}
}
获取指定时间范围内指定间隔天数的所有日期
/**
*
* 获取指定时间范围内指定间隔天数的所有日期
* getDateStr('2023-02-01', '2023-03-10', 0)
* */
export function getDateStr(startDate, endDate, dayLength) {
let str = startDate
for (let i = 0
let getDate = getTargetDate(startDate, dayLength)
startDate = getDate
if (getDate <= endDate) {
str += ','+getDate
} else {
break
}
}
return str
}
export function getTargetDate(date,dayLength) {
dayLength = dayLength + 1
let tempDate = new Date(date)
tempDate.setDate(tempDate.getDate() + dayLength)
let year = tempDate.getFullYear()
let month = tempDate.getMonth() + 1 < 10 ? "0" + (tempDate.getMonth() + 1) : tempDate.getMonth() + 1
let day = tempDate.getDate() < 10 ? "0" + tempDate.getDate() : tempDate.getDate()
return year + "-" + month + "-" + day
}