派生自 wuyushui/SewerAndRainNetwork

chenyabin
2021-05-18 8dc33d1e8da59e87a2be6b921ac96600d7786685
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// 参数名称:authCode    值: 所有:0 化工销售:HXXT; 炼油销售:LXXT;  江苏石油:CPYXT;  销售华东:XSHD
const SysAuthCode = '0'
/**
 * Created by liangruizhe on 2019/01/14
 */
// ==============时间===============
// 获取当前时间
function GetCurrentTime () {
  var today = new Date()
  var year = today.getFullYear()
  var month = today.getMonth() + 1
  var day = today.getDate() > 9 ? today.getDate() : '0' + today.getDate()
  var hours = today.getHours() > 9 ? today.getHours() : '0' + today.getHours()
  var minutes = today.getMinutes() > 9 ? today.getMinutes() : '0' + today.getMinutes()
  var seconds = today.getSeconds() > 9 ? today.getSeconds() : '0' + today.getSeconds()
  return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
}
// 获取当天零点时间
function GetCurrentDayTime () {
  var today = new Date()
  var year = today.getFullYear()
  var month = today.getMonth() + 1
  var day = today.getDate() > 9 ? today.getDate() : '0' + today.getDate()
  return year + '-' + month + '-' + day + ' 00:01:01'
}
// UtcToDateTime
function UtcToDateTime (time) {
  var date = new Date(time)
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()
  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()
  return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second
}
// UtcToMonDate
function UtcToMonDate (time) {
  var date = new Date(time)
  var month = date.getMonth() + 1
  var day = date.getDate()
  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()
  return month + '/' + day + ' ' + hour + ':' + minute + ':' + second
}
// yyyy-MM-dd
function convertDateFromString (dateString) {
  if (dateString) {
    var date = new Date(dateString.replace(/-/, '/'))
    return date
  }
}
// yyyy-MM-dd hh:mm:ss
function convertDateTimeFromString (dateString) {
  if (dateString) {
    var arr1 = dateString.split(' ')
    var sdate = arr1[0].split('-')
    var stime = arr1[1].split(':')
    var date = new Date(sdate[0], sdate[1] - 1, sdate[2], stime[0], stime[1], stime[2])
    return date
  }
}
// ==============空间计算===============
// 计算点串距离
function getLength (arrPnts, isJwd) {
  var dist = 0
  var length = 0
  var offset = 103133.845
  var fntPnt = null
  var lastPnt = null
  if (isJwd === undefined) isJwd = true
  if (arrPnts.length < 2) {
    return 0
  }
  for (var i = 0; i < arrPnts.length - 1; i++) {
    fntPnt = arrPnts[i]
    lastPnt = arrPnts[i + 1]
    if (lastPnt) {
      var xD = Math.abs(fntPnt.x - lastPnt.x)
      var yD = Math.abs(fntPnt.y - lastPnt.y)
 
      if (isJwd) {
        if (Math.abs(fntPnt.x) > 180) {
          xD = xD / 3600
          yD = yD / 3600
        }
        dist = (Math.sqrt(Math.pow(xD, 2) + Math.pow(yD, 2))) * offset
      } else {
        dist = (Math.sqrt(Math.pow(xD, 2) + Math.pow(yD, 2)))
      }
 
      length += dist
    }
  }
  return length
}
 
// 计算点到线段的距离
function getDistance (point, lineP1, lineP2) {
  var a = Number((lineP1.y - lineP2.y) / (lineP1.x - lineP2.x))
  var b = -1
  var c = Number(lineP2.y - a * lineP2.x)
  var td = Math.abs(a * point.x + b * point.y + c) / Math.sqrt(a * a + b * b)
  return td
}
 
export default {
  SysAuthCode,
  getDistance,
  getLength,
  GetCurrentTime,
  GetCurrentDayTime,
  UtcToDateTime,
  UtcToMonDate,
  convertDateFromString,
  convertDateTimeFromString
}