import dayjs from 'dayjs' ; export function jsonTimeFormat ( jsonTime , format ? ) { return dayjs ( jsonTime ) . format ( format || 'YYYY-MM-DD HH:mm:ss' ) ; } export interface ArrrToTreeOptions { root ? : string | number ; pidKey ? : string ; idKey ? : string ; childKey ? : string ; } param source param param export function arrToTree ( source , { root = 0 , pidKey = 'pid' , idKey = 'id' , childKey = 'children' } ) { function getNode ( id ) { const node = [ ] ; for ( let i = 0 , len = source . length ; i < len ; i ++ ) { if ( source [ i ] [ pidKey ] === id ) { const children = getNode ( source [ i ] [ idKey ] ) ; if ( children . length > 0 ) source [ i ] [ childKey ] = children ; node . push ( source [ i ] ) ; } } return node ; } return getNode ( root ) ; } param { content } 流 param { fileName } 文件名 export function downLoad ( content , fileName ) { const blob = new Blob ( [ content ] ) ; const url = window . URL . createObjectURL ( blob ) ; const dom = document . createElement ( 'a' ) ; dom . style . display = 'none' ; dom . href = url ; dom . setAttribute ( 'download' , fileName ) ; document . body . appendChild ( dom ) ; dom . click ( ) ; } param fileSize export function tranFileSize ( fileSize ) { let result = '' ; if ( fileSize >= 1073741824 ) { result = fileSize % 1073741824 === 0 ? fileSize / 1073741824 + 'G' : Math . trunc ( fileSize / 1073741824 ) + 'G' ; } else if ( fileSize >= 1048576 ) { result = fileSize % 1048576 === 0 ? fileSize / 1048576 + 'MB' : Math . trunc ( fileSize / 1048576 ) + 'MB' ; } else if ( fileSize >= 1024 ) { result = fileSize % 1024 === 0 ? fileSize / 1024 + 'KB' : Math . trunc ( fileSize / 1024 ) + 'KB' ; } else { result = fileSize + 'B' ; } return result ; } /**
 * 将 el-icond的组件名 AbbCdd 转化为 i-abb-cdd 形式
 */ export function tranElIconName ( iconName ) { return `i${ iconName . replace ( /[A-Z]/g , match => ( '-' + match . toLowerCase ) ) }` ; }