listToTree(arr, parentId =null){const tree =[]
arr.forEach((element)=>{if(element.pid === parentId){const c =this.listToTree(arr, element.id)if(c.length){
element.children = c
}
tree.push(element)}})return tree
}
/**
* 格式化时间戳
* @param {*} time 时间戳:1653381151
* @returns 格式化日期时间:2022-05-24 16:31:12
*/formatTimestamp(time){let date =newDate(time);let year = date.getFullYear();let month = date.getMonth()+1;
month = month <10?('0'+ month): month;let day = date.getDate();
day = day <10?('0'+ day): day;let h = date.getHours();
h = h <10?('0'+ h): h;let m = date.getMinutes();
m = m <10?('0'+ m): m;let s = date.getSeconds();
s = s <10?('0'+ s): s;return year +"-"+ month +"-"+ day +" "+ h +":"+ m +":"+ s;}
/**
* 获取日期、星期、时间
* @param {*} value 时间戳
*/getDateTime(value =newDate()){const data ={date:newDate(value).getFullYear()+'/'+(newDate(value).getMonth()+1)+'/'+newDate(value).getDate(),timeStamp:dayjs(value).unix()*1000,}let date =newDate(data.timeStamp)const weekList =['星期日','星期一','星期二','星期三','星期四','星期五','星期六']let w = date.getDay()let h = date.getHours()let m = date.getMinutes()let s = date.getSeconds()this.date = data.date // 日期this.week = weekList[w]// 星期this.time =`${h}:${m <10?'0'+ m : m}:${s <10?'0'+ s : s}`// 时间// 实时更新setInterval(()=>{
data.timeStamp +=1000
date =newDate(data.timeStamp)
w = date.getDay()
h = date.getHours()
m = date.getMinutes()
s = date.getSeconds()this.date = data.date
this.week = weekList[w]this.time =`${h}:${m <10?'0'+ m : m}:${s <10?'0'+ s : s}`},1000)}
/**
* 秒 转化为 时分秒
* @param {*} time 秒
*/getTime(time){let h =parseInt(time /60/60%24)// h = h < 10 ? '0' + h : hlet m =parseInt(time /60%60)// m = m < 10 ? '0' + m : mlet s =parseInt(time %60)// s = s < 10 ? '0' + s : sreturn[h, m, s]}