gis-common 2.2.19 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,107 @@
1
+ export default {
2
+ getUrlParams(href = window.location.href, needDecode = true) {
3
+ const reg = /([^&=]+)=([\w\W]*?)(&|$|#)/g
4
+ const { search, hash } = new URL(href)
5
+ const args = [search, hash]
6
+ let obj = {}
7
+ for (let i = 0; i < args.length; i++) {
8
+ const str = args[i]
9
+ if (str) {
10
+ const s = str.replace(/#|\//g, '')
11
+ const arr = s.split('?')
12
+ if (arr.length > 1) {
13
+ for (let i = 1; i < arr.length; i++) {
14
+ let res
15
+ while ((res = reg.exec(arr[i]))) {
16
+ obj[res[1]] = needDecode ? decodeURIComponent(res[2]) : res[2]
17
+ }
18
+ }
19
+ }
20
+ }
21
+ }
22
+ return obj
23
+ },
24
+ getExplorer() {
25
+ var explorer = window.navigator.userAgent
26
+ if (explorer.indexOf('MSIE') >= 0) {
27
+ return 'IE'
28
+ }
29
+ if (!!window.ActiveXObject || 'ActiveXObject' in window) {
30
+ // IE
31
+ return 'IE'
32
+ } else if (explorer.indexOf('Firefox') >= 0) {
33
+ // Firefox
34
+ return 'Firefox'
35
+ } else if (explorer.indexOf('Chrome') >= 0) {
36
+ // Chrome
37
+ return 'Chrome'
38
+ } else if (explorer.indexOf('Opera') >= 0) {
39
+ // Opera
40
+ return 'Opera'
41
+ } else if (explorer.indexOf('Safari') >= 0) {
42
+ // Safari
43
+ return 'Safari'
44
+ }
45
+ },
46
+ detectOS() {
47
+ let os_type = ''
48
+ const windows = navigator.userAgent.indexOf('Windows', 0) != -1 ? 1 : 0
49
+ const mac = navigator.userAgent.indexOf('mac', 0) != -1 ? 1 : 0
50
+ const linux = navigator.userAgent.indexOf('Linux', 0) != -1 ? 1 : 0
51
+ const unix = navigator.userAgent.indexOf('X11', 0) != -1 ? 1 : 0
52
+ if (windows) os_type = 'MS Windows'
53
+ else if (mac) os_type = 'Apple mac'
54
+ else if (linux) os_type = 'Linux'
55
+ else if (unix) os_type = 'Unix'
56
+ return os_type
57
+ },
58
+ switchFullScreen(status) {
59
+ if (status) {
60
+ const element = document.documentElement
61
+ if (element.requestFullscreen) {
62
+ element.requestFullscreen()
63
+ } else if (element.msRequestFullscreen) {
64
+ element.msRequestFullscreen()
65
+ } else if (element.mozRequestFullScreen) {
66
+ element.mozRequestFullScreen()
67
+ } else if (element.webkitRequestFullscreen) {
68
+ element.webkitRequestFullscreen()
69
+ }
70
+ } else {
71
+ if (document.exitFullscreen) {
72
+ document.exitFullscreen()
73
+ } else if (document.msExitFullscreen) {
74
+ document.msExitFullscreen()
75
+ } else if (document.mozCancelFullScreen) {
76
+ document.mozCancelFullScreen()
77
+ } else if (document.webkitExitFullscreen) {
78
+ document.webkitExitFullscreen()
79
+ }
80
+ }
81
+ },
82
+ /**
83
+ * scale屏幕适配方案
84
+ */
85
+ refreshScale() {
86
+ const baseWidth = document.documentElement.clientWidth
87
+ const baseHeight = document.documentElement.clientHeight
88
+ const appStyle = document.getElementById('app').style
89
+ const realRatio = baseWidth / baseHeight
90
+ const designRatio = 16 / 9
91
+ let scaleRate = baseWidth / 1920
92
+ if (realRatio > designRatio) {
93
+ scaleRate = baseHeight / 1080
94
+ }
95
+ appStyle.transformOrigin = 'left top'
96
+ appStyle.transform = `scale(${scaleRate}) translateX(-49.99%)`
97
+ appStyle.width = `${baseWidth / scaleRate}px`
98
+ },
99
+ /**
100
+ * rem屏幕适配方案
101
+ */
102
+ getHtmlFontSize() {
103
+ const htmlwidth = document.documentElement.clientWidth || document.body.clientWidth
104
+ const htmlDom = document.querySelector('html')
105
+ htmlDom.style.fontSize = htmlwidth / 192 + 'px'
106
+ },
107
+ }
@@ -0,0 +1,236 @@
1
+ import { ErrorType } from '../constant'
2
+
3
+ /* eslint-disable no-extend-native, space-in-parens */
4
+ export default {
5
+ /**
6
+ * 判断数据类型
7
+ *
8
+ * @param {*} data
9
+ * @returns {*}
10
+ */
11
+ getDataType(data) {
12
+ return Object.prototype.toString.call(data).slice(8, -1)
13
+ },
14
+ isEmpty(value) {
15
+ if (value == null) {
16
+ // 等同于 value === undefined || value === null
17
+ return true
18
+ }
19
+ const type = this.getDataType(value)
20
+ switch (type) {
21
+ case 'String':
22
+ return value.trim() === ''
23
+ case 'Array':
24
+ return !value.length
25
+ case 'Object':
26
+ return !Object.keys(value).length
27
+ case 'Boolean':
28
+ return !value
29
+ default:
30
+ return false // 其他对象均视作非空
31
+ }
32
+ },
33
+ isNotEmpty(val) {
34
+ return !this.isEmpty(val)
35
+ },
36
+ json2form(json) {
37
+ const formData = new FormData()
38
+ Object.keys(json).forEach((key) => {
39
+ formData.append(key, json[key] instanceof Object ? JSON.stringify(json[key]) : json[key])
40
+ })
41
+ return formData
42
+ },
43
+ /**
44
+ * json转换成get参数形式
45
+ *
46
+ * @param {*} json
47
+ * @returns {*}
48
+ */
49
+ json2Query(json) {
50
+ var tempArr = []
51
+ for (var i in json) {
52
+ var key = i
53
+ var value = json[i]
54
+ tempArr.push(key + '=' + value)
55
+ }
56
+ var urlParamsStr = tempArr.join('&')
57
+ return urlParamsStr
58
+ },
59
+ generateGuid() {
60
+ const S4 = function () {
61
+ return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)
62
+ }
63
+ return S4() + S4() + S4() + S4() + S4() + S4() + S4() + S4()
64
+ },
65
+ decodeDict(...args) {
66
+ let res = ''
67
+ if (args.length > 1) {
68
+ const items = args.slice(1, args.length % 2 === 0 ? args.length - 1 : args.length)
69
+ for (let i = 0; i < items.length; i = i + 2) {
70
+ const item = items[i]
71
+ if (args[0] === item) {
72
+ res = items[i + 1]
73
+ }
74
+ }
75
+ if (!res && args.length % 2 === 0) {
76
+ res = args[args.length - 1]
77
+ }
78
+ } else {
79
+ res = args[0]
80
+ }
81
+ return res
82
+ },
83
+ /**
84
+ *
85
+ * @param {*} dest
86
+ * @param {...any} args
87
+ * @returns 等同于L.extend
88
+ */
89
+ extend(dest, ...args) {
90
+ let i, j, len, src
91
+ for (j = 0, len = args.length; j < len; j++) {
92
+ src = args[j]
93
+ for (i in src) {
94
+ dest[i] = src[i]
95
+ }
96
+ }
97
+ return dest
98
+ },
99
+ rgb2hex(rgb) {
100
+ var hex = '#' + ((1 << 24) + (rgb[0] << 16) + (rgb[1] << 8) + rgb[2]).toString(16).slice(1)
101
+ return hex
102
+ },
103
+ /**
104
+ * 将平级对象列表转换为树形结构对象列表
105
+ *
106
+ * @param {Array} data
107
+ * @param {string} [idPropertyName="id"]
108
+ * @param {string} [parentIdPropertyName="parentId"]
109
+ * @param {string} [childrenPropertyName="children"]
110
+ * @returns {*}
111
+ */
112
+ convertToTree2(data, idPropertyName = 'id', parentIdPropertyName = 'parentId', childrenPropertyName = 'children') {
113
+ const result = []
114
+ function buildChildren(item) {
115
+ const id = item[idPropertyName]
116
+ const children = data.filter((item2) => item2.hasOwnProperty(parentIdPropertyName) && item2[parentIdPropertyName] === id)
117
+ if (children.length > 0) {
118
+ children.forEach(buildChildren)
119
+ item[childrenPropertyName] = children
120
+ }
121
+ }
122
+ for (const item of data) {
123
+ if (data.findIndex((t) => t[idPropertyName] === item[parentIdPropertyName]) === -1) {
124
+ buildChildren(item)
125
+ result.push(item)
126
+ }
127
+ }
128
+ return result
129
+ },
130
+ /**
131
+ * 异步加载script
132
+ *
133
+ * @param {*} url
134
+ */
135
+ asyncLoadScript(url) {
136
+ return new Promise((resolve, reject) => {
137
+ try {
138
+ var oscript = document.createElement('script')
139
+ if (oscript.readyState) {
140
+ // ie8及以下版本
141
+ oscript.onreadystatechange = function () {
142
+ if (oscript.readyState === 'complete' || oscript.readyState === 'loaded') {
143
+ resolve(oscript)
144
+ }
145
+ }
146
+ } else {
147
+ oscript.onload = function () {
148
+ resolve(oscript)
149
+ }
150
+ }
151
+ oscript.type = 'text/javascript'
152
+ oscript.src = url
153
+ document.body.appendChild(oscript)
154
+ } catch (error) {
155
+ reject(error)
156
+ }
157
+ })
158
+ },
159
+ loadStyle(urls) {
160
+ urls.forEach((url) => {
161
+ const css = document.createElement('link')
162
+ css.href = url
163
+ css.rel = 'stylesheet'
164
+ css.type = 'text/css'
165
+ document.head.appendChild(css)
166
+ })
167
+ },
168
+ /**
169
+ * 提取json中的value组成一个新的字符串
170
+ * eg: template('aaa{key}', json)
171
+ *
172
+ * @param {*} str
173
+ * @param {*} data
174
+ * @returns {*}
175
+ */
176
+ template(str, data) {
177
+ const templateRe = /\{ *([\w_-]+) *\}/g
178
+ return str.replace(templateRe, function (str, key) {
179
+ var value = data[key]
180
+ if (value === undefined) {
181
+ throw new Error(ErrorType.JSON_VALUE_ERROR + str)
182
+ } else if (typeof value === 'function') {
183
+ value = value(data)
184
+ }
185
+ return value
186
+ })
187
+ },
188
+ deleteEmptyProperty(data) {
189
+ return Object.fromEntries(
190
+ Object.keys(data)
191
+ .filter((d) => !this.isEmpty(data[d]))
192
+ .map((i) => [i, data[i]])
193
+ )
194
+ },
195
+ deepAssign() {
196
+ let len = arguments.length,
197
+ target = arguments[0]
198
+ if (this.getDataType(target) !== 'Object') {
199
+ target = {}
200
+ }
201
+ for (let i = 1; i < len; i++) {
202
+ let source = arguments[i]
203
+ if (this.getDataType(source) === 'Object') {
204
+ for (let s in source) {
205
+ if (s === '__proto__' || target === source[s]) {
206
+ continue
207
+ }
208
+ if (this.getDataType(source[s]) === 'Object') {
209
+ target[s] = this.deepAssign(target[s], source[s])
210
+ } else {
211
+ target[s] = source[s]
212
+ }
213
+ }
214
+ }
215
+ }
216
+ return target
217
+ },
218
+ handleCopyValue(text) {
219
+ if (!navigator.clipboard && window.isSecureContext) {
220
+ return navigator.clipboard.writeText(text)
221
+ } else {
222
+ const textArea = document.createElement('textarea')
223
+ textArea.style.position = 'fixed'
224
+ textArea.style.top = textArea.style.left = '-100vh'
225
+ textArea.style.opacity = '0'
226
+ textArea.value = text
227
+ document.body.appendChild(textArea)
228
+ textArea.focus()
229
+ textArea.select()
230
+ return new Promise((resolve, reject) => {
231
+ document.execCommand('copy') ? resolve() : reject(new Error('copy failed'))
232
+ textArea.remove()
233
+ })
234
+ }
235
+ },
236
+ }
@@ -0,0 +1,23 @@
1
+ export default {
2
+ set: function (name, value, Days = 30) {
3
+ var exp = new Date()
4
+ exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000)
5
+ document.cookie = name + '=' + escape(value) + ';expires=' + exp.toGMTString()
6
+ },
7
+ remove: function (name) {
8
+ var exp = new Date()
9
+ exp.setTime(exp.getTime() - 1)
10
+ var cval = this.get(name)
11
+ if (cval != null) {
12
+ document.cookie = name + '=' + cval + ';expires=' + exp.toGMTString()
13
+ }
14
+ },
15
+ get: function (name) {
16
+ var arr = document.cookie.match(new RegExp('(^| )' + name + '=([^;]*)(;|$)'))
17
+ if (arr != null) {
18
+ return arr[2]
19
+ } else {
20
+ return ''
21
+ }
22
+ },
23
+ }
@@ -0,0 +1,145 @@
1
+ export default {
2
+ PI: 3.14159265358979324,
3
+ XPI: (3.14159265358979324 * 3000.0) / 180.0,
4
+ delta(lat, lng) {
5
+ const a = 6378245.0 // a: 卫星椭球坐标投影到平面地图坐标系的投影因子。
6
+ const ee = 0.00669342162296594323 // ee: 椭球的偏心率。
7
+ let dLat = this.transformLat(lng - 105.0, lat - 35.0)
8
+ let dLon = this.transformLon(lng - 105.0, lat - 35.0)
9
+ const radLat = (lat / 180.0) * this.PI
10
+ let magic = Math.sin(radLat)
11
+ magic = 1 - ee * magic * magic
12
+ const sqrtMagic = Math.sqrt(magic)
13
+ dLat = (dLat * 180.0) / (((a * (1 - ee)) / (magic * sqrtMagic)) * this.PI)
14
+ dLon = (dLon * 180.0) / ((a / sqrtMagic) * Math.cos(radLat) * this.PI)
15
+ return { lat: dLat, lng: dLon }
16
+ },
17
+ // WGS-84 to GCJ-02
18
+ gcjEncrypt(wgsLat, wgsLon) {
19
+ if (this.outOfChina(wgsLat, wgsLon)) {
20
+ return { lat: wgsLat, lng: wgsLon }
21
+ }
22
+
23
+ const d = this.delta(wgsLat, wgsLon)
24
+ return { lat: wgsLat + d.lat, lng: wgsLon + d.lng }
25
+ },
26
+ // GCJ-02 to WGS-84
27
+ gcjDecrypt(gcjLat, gcjLon) {
28
+ if (this.outOfChina(gcjLat, gcjLon)) {
29
+ return { lat: gcjLat, lng: gcjLon }
30
+ }
31
+
32
+ const d = this.delta(gcjLat, gcjLon)
33
+ return { lat: gcjLat - d.lat, lng: gcjLon - d.lng }
34
+ },
35
+ // GCJ-02 to WGS-84 exactly
36
+ gcjDecryptExact(gcjLat, gcjLon) {
37
+ const initDelta = 0.01
38
+ const threshold = 0.000000001
39
+ let dLat = initDelta
40
+ let dLon = initDelta
41
+ let mLat = gcjLat - dLat
42
+ let mLon = gcjLon - dLon
43
+ let pLat = gcjLat + dLat
44
+ let pLon = gcjLon + dLon
45
+ let wgsLat
46
+ let wgsLon
47
+ let i = 0
48
+ while (1) {
49
+ wgsLat = (mLat + pLat) / 2
50
+ wgsLon = (mLon + pLon) / 2
51
+ const tmp = this.gcj_encrypt(wgsLat, wgsLon)
52
+ dLat = tmp.lat - gcjLat
53
+ dLon = tmp.lng - gcjLon
54
+ if (Math.abs(dLat) < threshold && Math.abs(dLon) < threshold) {
55
+ break
56
+ }
57
+
58
+ if (dLat > 0) pLat = wgsLat
59
+ else mLat = wgsLat
60
+ if (dLon > 0) pLon = wgsLon
61
+ else mLon = wgsLon
62
+
63
+ if (++i > 10000) break
64
+ }
65
+ // console.log(i);
66
+ return { lat: wgsLat, lng: wgsLon }
67
+ },
68
+ // GCJ-02 to BD-09
69
+ bdEncrypt(gcjLat, gcjLon) {
70
+ const x = gcjLon
71
+ const y = gcjLat
72
+ const z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * this.XPI)
73
+ const theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * this.XPI)
74
+ const bdLon = z * Math.cos(theta) + 0.0065
75
+ const bdLat = z * Math.sin(theta) + 0.006
76
+ return { lat: bdLat, lng: bdLon }
77
+ },
78
+ // BD-09 to GCJ-02
79
+ bdDecrypt(bdLat, bdLon) {
80
+ const x = bdLon - 0.0065
81
+ const y = bdLat - 0.006
82
+ const z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * this.XPI)
83
+ const theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * this.XPI)
84
+ const gcjLon = z * Math.cos(theta)
85
+ const gcjLat = z * Math.sin(theta)
86
+ return { lat: gcjLat, lng: gcjLon }
87
+ },
88
+ // WGS-84 to Web mercator
89
+ // mercatorLat -> y mercatorLon -> x
90
+ mercatorEncrypt(wgsLat, wgsLon) {
91
+ const x = (wgsLon * 20037508.34) / 180.0
92
+ let y = Math.log(Math.tan(((90.0 + wgsLat) * this.PI) / 360.0)) / (this.PI / 180.0)
93
+ y = (y * 20037508.34) / 180.0
94
+ return { lat: y, lng: x }
95
+ },
96
+ // Web mercator to WGS-84
97
+ // mercatorLat -> y mercatorLon -> x
98
+ mercatorDecrypt(mercatorLat, mercatorLon) {
99
+ const x = (mercatorLon / 20037508.34) * 180.0
100
+ let y = (mercatorLat / 20037508.34) * 180.0
101
+ y = (180 / this.PI) * (2 * Math.atan(Math.exp((y * this.PI) / 180.0)) - this.PI / 2)
102
+ return { lat: y, lng: x }
103
+ },
104
+ // two point's distance
105
+ distance(latA, lngA, latB, lngB) {
106
+ const earthR = 6371000.0
107
+ const x = Math.cos((latA * this.PI) / 180.0) * Math.cos((latB * this.PI) / 180.0) * Math.cos(((lngA - lngB) * this.PI) / 180)
108
+ const y = Math.sin((latA * this.PI) / 180.0) * Math.sin((latB * this.PI) / 180.0)
109
+ let s = x + y
110
+ if (s > 1) s = 1
111
+ if (s < -1) s = -1
112
+ const alpha = Math.acos(s)
113
+ const distance = alpha * earthR
114
+ return distance
115
+ },
116
+ outOfChina(lat, lng) {
117
+ if (lng < 72.004 || lng > 137.8347) {
118
+ return true
119
+ }
120
+ if (lat < 0.8293 || lat > 55.8271) {
121
+ return true
122
+ }
123
+ return false
124
+ },
125
+ transformLat(x, y) {
126
+ let ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x))
127
+ ret += ((20.0 * Math.sin(6.0 * x * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0) / 3.0
128
+ ret += ((20.0 * Math.sin(y * this.PI) + 40.0 * Math.sin((y / 3.0) * this.PI)) * 2.0) / 3.0
129
+ ret += ((160.0 * Math.sin((y / 12.0) * this.PI) + 320 * Math.sin((y * this.PI) / 30.0)) * 2.0) / 3.0
130
+ return ret
131
+ },
132
+ transformLon(x, y) {
133
+ let ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x))
134
+ ret += ((20.0 * Math.sin(6.0 * x * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0) / 3.0
135
+ ret += ((20.0 * Math.sin(x * this.PI) + 40.0 * Math.sin((x / 3.0) * this.PI)) * 2.0) / 3.0
136
+ ret += ((150.0 * Math.sin((x / 12.0) * this.PI) + 300.0 * Math.sin((x / 30.0) * this.PI)) * 2.0) / 3.0
137
+ return ret
138
+ },
139
+ randomCoordinate(minX, minY, maxX, maxY) {
140
+ return {
141
+ lat: Math.random() * (maxY - minY) + minY,
142
+ lng: Math.random() * (maxX - minX) + minX,
143
+ }
144
+ },
145
+ }
@@ -0,0 +1,144 @@
1
+ Date.prototype.format = function (fmt) {
2
+ const o = {
3
+ 'M+': this.getMonth() + 1, // 月份
4
+ 'd+': this.getDate(), // 日
5
+ 'h+': this.getHours(), // 小时
6
+ 'm+': this.getMinutes(), // 分
7
+ 's+': this.getSeconds(), // 秒
8
+ 'q+': Math.floor((this.getMonth() + 3) / 3), // 季度
9
+ S: this.getMilliseconds(), // 毫秒
10
+ }
11
+ if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length))
12
+ for (const k in o) {
13
+ if (new RegExp('(' + k + ')').test(fmt)) fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length))
14
+ }
15
+ return fmt
16
+ }
17
+ /**
18
+ * 实现的时间增减功能
19
+ *
20
+ * @param {*} interval 字符串表达式,表示要添加的时间间隔类型
21
+ * @param {*} number 数值表达式,表示要添加的时间间隔的个数
22
+ */
23
+ Date.prototype.addDate = function (interval, number) {
24
+ const date = new Date(this)
25
+ switch (interval) {
26
+ case 'y':
27
+ date.setFullYear(this.getFullYear() + number)
28
+ break
29
+ case 'q':
30
+ date.setMonth(this.getMonth() + number * 3)
31
+ break
32
+ case 'M':
33
+ date.setMonth(this.getMonth() + number)
34
+ break
35
+ case 'w':
36
+ date.setDate(this.getDate() + number * 7)
37
+ break
38
+ case 'd':
39
+ date.setDate(this.getDate() + number)
40
+ break
41
+ case 'h':
42
+ date.setHours(this.getHours() + number)
43
+ break
44
+ case 'm':
45
+ date.setMinutes(this.getMinutes() + number)
46
+ break
47
+ case 's':
48
+ date.setSeconds(this.getSeconds() + number)
49
+ break
50
+ default:
51
+ date.setDate(this.getDate() + number)
52
+ break
53
+ }
54
+ return date
55
+ }
56
+ export default {
57
+ lastMonthDate: new Date(new Date().getFullYear(), new Date().getMonth() - 1, 1),
58
+ thisMonthDate: new Date(new Date().getFullYear(), new Date().getMonth(), 1),
59
+ nextMonthDate: new Date(new Date().getFullYear(), new Date().getMonth() + 1, 1),
60
+ lastWeekDate: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1 - 7 - new Date().getDay()),
61
+ thisWeekDate: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1 - new Date().getDay()),
62
+ nextWeekDate: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1 + 7 - new Date().getDay()),
63
+ lastDayDate: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() - 1),
64
+ thisDayDate: new Date(new Date().setHours(0, 0, 0, 0)),
65
+ nextDayDate: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1),
66
+ parseDate(str) {
67
+ if (typeof str == 'string') {
68
+ var results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) *$/)
69
+ if (results && results.length > 3) return new Date(parseInt(results[1]), parseInt(results[2]) - 1, parseInt(results[3]))
70
+ results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2}) *$/)
71
+ if (results && results.length > 6)
72
+ return new Date(
73
+ parseInt(results[1]),
74
+ parseInt(results[2]) - 1,
75
+ parseInt(results[3]),
76
+ parseInt(results[4]),
77
+ parseInt(results[5]),
78
+ parseInt(results[6])
79
+ )
80
+ results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2})\.(\d{1,9}) *$/)
81
+ if (results && results.length > 7)
82
+ return new Date(
83
+ parseInt(results[1]),
84
+ parseInt(results[2]) - 1,
85
+ parseInt(results[3]),
86
+ parseInt(results[4]),
87
+ parseInt(results[5]),
88
+ parseInt(results[6]),
89
+ parseInt(results[7])
90
+ )
91
+ }
92
+ return null
93
+ },
94
+ /**
95
+ * 将时间间隔转换成中国话
96
+ *
97
+ * @param {*} startTime
98
+ * @param {*} endTime
99
+ * @returns {*}
100
+ */
101
+ formatDateInterval(startTime, endTime) {
102
+ const dateCreateTime = new Date(startTime)
103
+ const dateFinishTime = new Date(endTime)
104
+ const dateInterval = dateFinishTime.getTime() - dateCreateTime.getTime()
105
+ const days = Math.floor(dateInterval / (24 * 3600 * 1000))
106
+ const leave1 = dateInterval % (24 * 3600 * 1000)
107
+ const hours = Math.floor(leave1 / (3600 * 1000))
108
+ const leave2 = leave1 % (3600 * 1000)
109
+ const minutes = Math.floor(leave2 / (60 * 1000))
110
+ const leave3 = leave2 % (60 * 1000)
111
+ const seconds = Math.round(leave3 / 1000)
112
+ let intervalDes = ''
113
+ if (days > 0) {
114
+ intervalDes += days + '天'
115
+ }
116
+ if (hours > 0) {
117
+ intervalDes += hours + '时'
118
+ }
119
+ if (minutes > 0) {
120
+ intervalDes += minutes + '分'
121
+ }
122
+ if (seconds > 0) {
123
+ intervalDes += seconds + '秒'
124
+ }
125
+ if (days === 0 && hours === 0 && minutes === 0 && seconds === 0) {
126
+ intervalDes = '少于1秒'
127
+ }
128
+ return intervalDes
129
+ },
130
+ formatterCounter(times) {
131
+ const checked = function (j) {
132
+ return (j > 10 ? '' : '0') + (j || 0)
133
+ }
134
+ const houres = checked(Math.floor(times / 3600))
135
+ const level1 = times % 3600
136
+ const minutes = checked(Math.floor(level1 / 60))
137
+ const leave2 = level1 % 60
138
+ const seconds = checked(Math.round(leave2))
139
+ return `${houres}:${minutes}:${seconds}`
140
+ },
141
+ sleep(d) {
142
+ for (let t = Date.now(); Date.now() - t <= d; );
143
+ },
144
+ }