riku
2022-09-15 bd3a9d7086f5a428b385599ba2cb08299b22c0df
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const moment = require('./moment.min')
 
 
 
const formatTime = date => {
  const time = moment(date)
  const now = moment()
 
  const timeYear = time.year()
  const timeMonth = time.month() + 1
  const timeDay = time.date()
 
  const thisYear = now.year()
  const thisMonth = now.month() + 1
  const thisDay = now.date()
 
  if (timeYear < thisYear) {
    return time.format('YYYY-MM-DD')
  } else if (timeMonth < thisMonth) {
    return time.format('MM-DD')
  } else if (timeDay < thisDay) {
    if (timeDay + 1 == thisDay) {
      return '昨天'
    } else {
      return time.format('MM-DD')
    }
  } else {
    return time.fromNow()
  }
}
 
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
}