const formatTime = date => { const year = date.getFullYear() const month = date.getMonth() + 1 const day = date.getDate() const hour = date.getHours() const minute = date.getMinutes() const second = date.getSeconds() return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}` } const formatNumber = n => { n = n.toString() return n[1] ? n : `0${n}` } // 处理省市县数据结构 const createMenu = node => { var that = this let obj = Object.keys(node).map((key,index,item)=>{ var elNode = { label: key, value: key, item:node[key], } return elNode; }) obj.forEach(e=>{ if ((e.item) instanceof Array) { e.children = [] e.item.forEach(c=>{ e.children.push({ label:c, value:c }) }) } else { if (Object.keys(e.item).length !== 0) { e.children = createMenu(e.item) } } }) return obj } module.exports = { formatTime, createMenu }