import productDits from "./productDicts"; export const home = 'main'; export function resetProperties(srcObj: any, destObj?: Object){ // 先设置为undefined for (const key in srcObj) { // console.log('key', key) if (srcObj.hasOwnProperty(key)) { srcObj[key] = undefined; } } // 再更新为目标对象 if(destObj){ Object.assign(srcObj, destObj); } }; export {productDits}; /** * * @param timestamp 时间戳转时间格式 * @param type * @returns */ export function timestampToTime(timestamp: number, type?: string) { if(type == 's'){ timestamp = timestamp * 1000; } let date = new Date(timestamp);//时间戳为10位需*1000,时间戳为13位的话不需乘1000 let Y = date.getFullYear() + '-'; let M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-'; let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '; let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours())+ ':'; let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':'; let s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()); return Y+M+D+h+m+s; } // 树 function addNode(dest: any, node: any){ // 添加路径 node.key = node.id if(node.path instanceof Array){ node.path.push(dest.id) }else{ node.path = [dest.id] } if(dest.id != undefined && node.pid != undefined && dest.id == node.pid){ if (dest.children) dest.children.push(node) else dest.children = [node] return dest; }else if(dest.children instanceof Array){ for(let i = 0; i < dest.children.length; i++){ if(addNode(dest.children[i], node)){ return dest } } } delete node.path; return undefined; } function addNodeMutual(node1: any, node2: any){ const item = addNode(node1, node2); if(item){ return item; }else{ return addNode(node2, node1); } } function addListNode(list: any[], node: any){ for(let i = 0; i < list.length; i++){ const item = addNodeMutual(list[i], node) if(item){ list[i] = item; return list } } return undefined; } export function tree(list: any[]){ const data: any[] = []; for(let i = 0; i < list.length; i++){ if(addListNode(data, list[i]) == undefined){ data.push(list[i]) } } return data } // modal可拖拽 export function draggable(aClass: string){ let modal:any = document.getElementsByClassName(aClass)[0]; console.log(modal) let header:any = modal.querySelector('.ant-modal-header'); let mask:any = modal.parentNode header.addEventListener('mouseover', () => { header.style.cursor = 'move'; }) header.addEventListener('mousedown', function(e:any){ let x = e.pageX - modal.offsetLeft; let y = e.pageY - modal.offsetTop; document.addEventListener('mousemove', move); function move(e:any){ modal.style.position = 'absolute' modal.style.top = (e.pageY - y) + 'px' modal.style.left = (e.pageX - x) + 'px' // 左侧 if(modal.offsetLeft < 0){ modal.style.left = '0px' }else if(modal.offsetLeft > (mask.clientWidth - modal.clientWidth - 10)){ modal.style.left = (mask.clientWidth - modal.clientWidth ) + 'px' } // 上 if(modal.offsetTop < 0){ modal.style.top = '0px' }else if(modal.offsetTop > (mask.clientHeight - modal.clientHeight)){ modal.style.top = (mask.clientHeight - modal.clientHeight) + 'px' } // console.log(e) // console.log('%O', mask) // console.log('%O', modal) // console.log(modal.offsetTop) // console.log(modal.offsetLeft) } header.addEventListener('mouseup', function(){ document.removeEventListener('mousemove', move) }) }) }