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 navContentHeight = function () {
|
//胶囊高度
|
const capsuleHeight = wx.getMenuButtonBoundingClientRect().bottom - wx.getMenuButtonBoundingClientRect().top
|
//胶囊上边框距顶部距离
|
const capsuleTop = wx.getMenuButtonBoundingClientRect().top
|
//状态栏高度
|
const statusBarHeight = wx.getSystemInfoSync().statusBarHeight
|
//药囊上边距状态栏下边的距离,即药囊在导航内容栏中的上下边距
|
const capsuleGap = capsuleTop - statusBarHeight
|
//导航内容栏的高度动态计算
|
const navContentHeight = capsuleGap * 2 + capsuleHeight
|
|
return navContentHeight + statusBarHeight
|
}
|
|
const deepCopy = function (obj) {
|
let b1 = typeof obj
|
if (b1 != 'object' || (obj instanceof Array) || obj == null) {
|
return obj;
|
}
|
var newobj = {};
|
for (var attr in obj) {
|
newobj[attr] = this.deepCopy(obj[attr]);
|
}
|
return newobj;
|
}
|
|
const lastMonth = function (year, month) {
|
var lM = month - 1
|
var lY = year
|
if (lM <= 0) {
|
lM += 12
|
lY -= 1
|
}
|
return [lY, lM]
|
}
|
|
module.exports = {
|
formatTime: formatTime,
|
navContentHeight: navContentHeight,
|
deepCopy: deepCopy,
|
lastMonth: lastMonth
|
}
|