gis-common 2.1.1 → 2.2.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.
- package/.babelrc +11 -0
- package/.editorconfig +9 -0
- package/.prettierrc +1 -0
- package/index.html +26 -0
- package/jsconfig.json +19 -0
- package/package.json +2 -3
- package/src/assets/images/location.png +0 -0
- package/src/constant/ErrorTypeConstant.js +20 -0
- package/src/constant/EventTypeConstant.js +23 -0
- package/src/constant/GraphicConstant.js +16 -0
- package/src/constant/LayerType.js +9 -0
- package/src/constant/index.js +4 -0
- package/src/core/AudioPlayer.js +30 -0
- package/src/core/CanvasDrawer.js +51 -0
- package/src/core/DevicePixelRatio.js +86 -0
- package/src/core/ElQuery.js +88 -0
- package/src/core/EventDispatcher.js +93 -0
- package/src/core/HashMap.js +36 -0
- package/src/core/MqttClient.js +108 -0
- package/src/core/WebSocketClient.js +104 -0
- package/src/core/WebStorage.js +73 -0
- package/src/index.js +10 -0
- package/src/utils/AnimateUtils.js +78 -0
- package/src/utils/ArrayUtils.js +82 -0
- package/src/utils/BrowserUtils.js +107 -0
- package/src/utils/CommUtils.js +230 -0
- package/src/utils/Cookie.js +23 -0
- package/src/utils/CoordsUtils.js +139 -0
- package/src/utils/DateUtils.js +130 -0
- package/src/utils/DomUtils.js +94 -0
- package/src/utils/FileUtils.js +105 -0
- package/src/utils/GeoUtils.js +242 -0
- package/src/utils/MathUtils.js +49 -0
- package/src/utils/OptimizeUtils.js +94 -0
- package/src/utils/StringUtils.js +135 -0
- package/src/utils/index.js +13 -0
- package/webpack.config.js +70 -0
- package/dist/resource.min.js +0 -2686
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import MathUtils from './MathUtils'
|
|
2
|
+
export default {
|
|
3
|
+
toRadian: Math.PI / 180,
|
|
4
|
+
R: 6371393,
|
|
5
|
+
/**
|
|
6
|
+
* 验证经纬度坐标
|
|
7
|
+
*
|
|
8
|
+
* @param {*} lng
|
|
9
|
+
* @param {*} lat
|
|
10
|
+
* @returns {*} {boolean}
|
|
11
|
+
*/
|
|
12
|
+
isLnglat(lng, lat) {
|
|
13
|
+
return !!(+lat > -90 && +lat < 90 && +lng > -180 && +lng < 180)
|
|
14
|
+
},
|
|
15
|
+
/**
|
|
16
|
+
* 格式化经纬度(转度分秒)
|
|
17
|
+
*
|
|
18
|
+
* @param {*} lng
|
|
19
|
+
* @param {*} lat
|
|
20
|
+
* @returns {*}
|
|
21
|
+
*/
|
|
22
|
+
formatLnglat(lng, lat) {
|
|
23
|
+
let res = ''
|
|
24
|
+
function format(value) {
|
|
25
|
+
const a = parseFloat(value)
|
|
26
|
+
const degree = parseInt(a)
|
|
27
|
+
let min = parseInt((a - degree) * 60)
|
|
28
|
+
let sec = (a - degree) * 3600 - min * 60
|
|
29
|
+
return degree + '°' + min + '′' + sec.toFixed(2) + '″'
|
|
30
|
+
}
|
|
31
|
+
if (lng && lat) {
|
|
32
|
+
res = format(lng) + ',' + format(lat)
|
|
33
|
+
}
|
|
34
|
+
return res
|
|
35
|
+
},
|
|
36
|
+
/**
|
|
37
|
+
* 度分秒转十进制
|
|
38
|
+
*
|
|
39
|
+
* @param {*} lng
|
|
40
|
+
* @param {*} lat
|
|
41
|
+
* @returns {*}
|
|
42
|
+
*/
|
|
43
|
+
transformLnglat(lng, lat) {
|
|
44
|
+
function dms2deg(s) {
|
|
45
|
+
var sw = /[sw]/i.test(s)
|
|
46
|
+
var f = sw ? -1 : 1
|
|
47
|
+
var bits = s.match(/[\d.]+/g)
|
|
48
|
+
var result = 0
|
|
49
|
+
for (var i = 0, iLen = bits.length; i < iLen; i++) {
|
|
50
|
+
result += bits[i] / f
|
|
51
|
+
f *= 60
|
|
52
|
+
}
|
|
53
|
+
return result
|
|
54
|
+
}
|
|
55
|
+
if (lng && lat) {
|
|
56
|
+
return {
|
|
57
|
+
lng: dms2deg(lng),
|
|
58
|
+
lat: dms2deg(lat),
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
/**
|
|
63
|
+
* 判断点是否在多边形内
|
|
64
|
+
*
|
|
65
|
+
* @param {*} p
|
|
66
|
+
* @param {*} poly
|
|
67
|
+
* @returns {*}
|
|
68
|
+
*/
|
|
69
|
+
rayCasting(p, poly) {
|
|
70
|
+
var px = p.x,
|
|
71
|
+
py = p.y,
|
|
72
|
+
flag = false
|
|
73
|
+
for (var i = 0, l = poly.length, j = l - 1; i < l; j = i, i++) {
|
|
74
|
+
var sx = poly[i].x,
|
|
75
|
+
sy = poly[i].y,
|
|
76
|
+
tx = poly[j].x,
|
|
77
|
+
ty = poly[j].y
|
|
78
|
+
// 点与多边形顶点重合
|
|
79
|
+
if ((sx === px && sy === py) || (tx === px && ty === py)) {
|
|
80
|
+
return 'on'
|
|
81
|
+
}
|
|
82
|
+
// 判断线段两端点是否在射线两侧
|
|
83
|
+
if ((sy < py && ty >= py) || (sy >= py && ty < py)) {
|
|
84
|
+
// 线段上与射线 Y 坐标相同的点的 X 坐标
|
|
85
|
+
var x = sx + ((py - sy) * (tx - sx)) / (ty - sy)
|
|
86
|
+
// 点在多边形的边上
|
|
87
|
+
if (x === px) {
|
|
88
|
+
return 'on'
|
|
89
|
+
}
|
|
90
|
+
// 射线穿过多边形的边界
|
|
91
|
+
if (x > px) {
|
|
92
|
+
flag = !flag
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// 射线穿过多边形边界的次数为奇数时点在多边形内
|
|
97
|
+
return flag ? 'in' : 'out'
|
|
98
|
+
},
|
|
99
|
+
/**
|
|
100
|
+
* 计算两点距离
|
|
101
|
+
*
|
|
102
|
+
* @param {*} fromPoint
|
|
103
|
+
* @param {*} toPoint
|
|
104
|
+
* @returns {*}
|
|
105
|
+
*/
|
|
106
|
+
wgs84PointsDistance(fromPoint, toPoint) {
|
|
107
|
+
var PI = Math.PI
|
|
108
|
+
function getRad(d) {
|
|
109
|
+
return (d * PI) / 180.0
|
|
110
|
+
}
|
|
111
|
+
if (arguments.length != 2) {
|
|
112
|
+
return 0
|
|
113
|
+
}
|
|
114
|
+
lon1 = fromPoint.x
|
|
115
|
+
lat1 = fromPoint.y
|
|
116
|
+
lon2 = toPoint.x
|
|
117
|
+
lat2 = toPoint.y
|
|
118
|
+
var a = 6378137,
|
|
119
|
+
b = 6356752.3142,
|
|
120
|
+
f = 1 / 298.257223563
|
|
121
|
+
var L = getRad(lon2 - lon1)
|
|
122
|
+
var U1 = Math.atan((1 - f) * Math.tan(getRad(lat1)))
|
|
123
|
+
var U2 = Math.atan((1 - f) * Math.tan(getRad(lat2)))
|
|
124
|
+
var sinU1 = Math.sin(U1),
|
|
125
|
+
cosU1 = Math.cos(U1)
|
|
126
|
+
var sinU2 = Math.sin(U2),
|
|
127
|
+
cosU2 = Math.cos(U2)
|
|
128
|
+
var lambda = L,
|
|
129
|
+
lambdaP,
|
|
130
|
+
iterLimit = 100
|
|
131
|
+
do {
|
|
132
|
+
var sinLambda = Math.sin(lambda),
|
|
133
|
+
cosLambda = Math.cos(lambda)
|
|
134
|
+
var sinSigma = Math.sqrt(
|
|
135
|
+
cosU2 * sinLambda * (cosU2 * sinLambda) + (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda) * (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda)
|
|
136
|
+
)
|
|
137
|
+
if (sinSigma == 0) return 0
|
|
138
|
+
var cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda
|
|
139
|
+
var sigma = Math.atan2(sinSigma, cosSigma)
|
|
140
|
+
var sinAlpha = (cosU1 * cosU2 * sinLambda) / sinSigma
|
|
141
|
+
var cosSqAlpha = 1 - sinAlpha * sinAlpha
|
|
142
|
+
var cos2SigmaM = cosSigma - (2 * sinU1 * sinU2) / cosSqAlpha
|
|
143
|
+
if (isNaN(cos2SigmaM)) cos2SigmaM = 0
|
|
144
|
+
var C = (f / 16) * cosSqAlpha * (4 + f * (4 - 3 * cosSqAlpha))
|
|
145
|
+
lambdaP = lambda
|
|
146
|
+
lambda = L + (1 - C) * f * sinAlpha * (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM)))
|
|
147
|
+
} while (Math.abs(lambda - lambdaP) > 1e-12 && --iterLimit > 0)
|
|
148
|
+
if (iterLimit == 0) {
|
|
149
|
+
return NaN
|
|
150
|
+
}
|
|
151
|
+
var uSq = (cosSqAlpha * (a * a - b * b)) / (b * b)
|
|
152
|
+
var A = 1 + (uSq / 16384) * (4096 + uSq * (-768 + uSq * (320 - 175 * uSq)))
|
|
153
|
+
var B = (uSq / 1024) * (256 + uSq * (-128 + uSq * (74 - 47 * uSq)))
|
|
154
|
+
var deltaSigma =
|
|
155
|
+
B *
|
|
156
|
+
sinSigma *
|
|
157
|
+
(cos2SigmaM +
|
|
158
|
+
(B / 4) *
|
|
159
|
+
(cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM) -
|
|
160
|
+
(B / 6) * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM)))
|
|
161
|
+
var s = b * A * (sigma - deltaSigma)
|
|
162
|
+
var fwdAz = Math.atan2(cosU2 * sinLambda, cosU1 * sinU2 - sinU1 * cosU2 * cosLambda)
|
|
163
|
+
var revAz = Math.atan2(cosU1 * sinLambda, -sinU1 * cosU2 + cosU1 * sinU2 * cosLambda)
|
|
164
|
+
return s
|
|
165
|
+
},
|
|
166
|
+
/**
|
|
167
|
+
* P1绕一个坐标点P2旋转θ角度后,新的坐标的计算公式
|
|
168
|
+
*
|
|
169
|
+
* @param {*} p1
|
|
170
|
+
* @param {*} p2
|
|
171
|
+
* @param {*} θ 旋转角度,正:表示顺时针,负:表示逆时针
|
|
172
|
+
*/
|
|
173
|
+
rotatePoint(p1, p2, θ) {
|
|
174
|
+
const x = (p1.x - p2.x) * Math.cos((Math.PI / 180) * -θ) - (p1.y - p2.y) * Math.sin((Math.PI / 180) * -θ) + p2.x
|
|
175
|
+
const y = (p1.x - p2.x) * Math.sin((Math.PI / 180) * -θ) + (p1.y - p2.y) * Math.cos((Math.PI / 180) * -θ) + p2.y
|
|
176
|
+
return { x, y }
|
|
177
|
+
},
|
|
178
|
+
/**
|
|
179
|
+
* 计算latlng2相对于latlng1的方位角和距离
|
|
180
|
+
*
|
|
181
|
+
* @param {*} latlng1
|
|
182
|
+
* @param {*} latlng2
|
|
183
|
+
* @returns {*} {boolean}
|
|
184
|
+
*/
|
|
185
|
+
calcBearAndDisByPoints(latlng1, latlng2) {
|
|
186
|
+
var f1 = parseFloat(latlng1.lat),
|
|
187
|
+
l1 = parseFloat(latlng1.lng),
|
|
188
|
+
f2 = parseFloat(latlng2.lat),
|
|
189
|
+
l2 = parseFloat(latlng2.lng)
|
|
190
|
+
var y = Math.sin((l2 - l1) * this.toRadian) * Math.cos(f2 * this.toRadian)
|
|
191
|
+
var x =
|
|
192
|
+
Math.cos(f1 * this.toRadian) * Math.sin(f2 * this.toRadian) -
|
|
193
|
+
Math.sin(f1 * this.toRadian) * Math.cos(f2 * this.toRadian) * Math.cos((l2 - l1) * this.toRadian)
|
|
194
|
+
var angle = Math.atan2(y, x) * (180 / Math.PI)
|
|
195
|
+
var deltaF = (f2 - f1) * this.toRadian
|
|
196
|
+
var deltaL = (l2 - l1) * this.toRadian
|
|
197
|
+
var a =
|
|
198
|
+
Math.sin(deltaF / 2) * Math.sin(deltaF / 2) +
|
|
199
|
+
Math.cos(f1 * this.toRadian) * Math.cos(f2 * this.toRadian) * Math.sin(deltaL / 2) * Math.sin(deltaL / 2)
|
|
200
|
+
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
|
|
201
|
+
var distance = this.R * c
|
|
202
|
+
return {
|
|
203
|
+
angle,
|
|
204
|
+
distance,
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
/**
|
|
208
|
+
* 根据方位角和距离生成新的坐标
|
|
209
|
+
*
|
|
210
|
+
* @param {*} latlng
|
|
211
|
+
* @param {*} angle
|
|
212
|
+
* @param {*} distance
|
|
213
|
+
* @returns {*}
|
|
214
|
+
*/
|
|
215
|
+
calcPointByBearAndDis(latlng, angle, distance) {
|
|
216
|
+
const sLat = MathUtils.toRadians(parseFloat(latlng.lat))
|
|
217
|
+
const sLng = MathUtils.toRadians(parseFloat(latlng.lng))
|
|
218
|
+
angle = parseFloat(angle)
|
|
219
|
+
distance = parseFloat(distance)
|
|
220
|
+
const d = distance / this.R
|
|
221
|
+
angle = MathUtils.toRadians(angle)
|
|
222
|
+
const lat = Math.asin(Math.sin(sLat) * Math.cos(d) + Math.cos(sLat) * Math.sin(d) * Math.cos(angle))
|
|
223
|
+
const lon = sLng + Math.atan2(Math.sin(angle) * Math.sin(d) * Math.cos(sLat), Math.cos(d) - Math.sin(sLat) * Math.sin(lat))
|
|
224
|
+
return {
|
|
225
|
+
lat: MathUtils.toDegrees(lat),
|
|
226
|
+
lng: MathUtils.toDegrees(lon),
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
mercatorTolonlat(x, y) {
|
|
230
|
+
const lng = (x / 20037508.34) * 180
|
|
231
|
+
var mmy = (y / 20037508.34) * 180
|
|
232
|
+
const lat = (180 / Math.PI) * (2 * Math.atan(Math.exp((mmy * Math.PI) / 180)) - Math.PI / 2)
|
|
233
|
+
return { lng, lat }
|
|
234
|
+
},
|
|
235
|
+
lonlatToMercator(lng, lat) {
|
|
236
|
+
var earthRad = 6378137.0
|
|
237
|
+
const x = ((lng * Math.PI) / 180) * earthRad
|
|
238
|
+
var a = (lat * Math.PI) / 180
|
|
239
|
+
const y = (earthRad / 2) * Math.log((1.0 + Math.sin(a)) / (1.0 - Math.sin(a)))
|
|
240
|
+
return { x, y }
|
|
241
|
+
},
|
|
242
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
DEG2RAD: Math.PI / 180,
|
|
3
|
+
RAD2DEG: 180 / Math.PI,
|
|
4
|
+
randInt(low, high) {
|
|
5
|
+
return low + Math.floor(Math.random() * (high - low + 1))
|
|
6
|
+
},
|
|
7
|
+
randFloat(low, high) {
|
|
8
|
+
return low + Math.random() * (high - low)
|
|
9
|
+
},
|
|
10
|
+
/**
|
|
11
|
+
* 角度转弧度
|
|
12
|
+
*
|
|
13
|
+
* @param {*} degrees
|
|
14
|
+
* @returns {*}
|
|
15
|
+
*/
|
|
16
|
+
degreesToRadians(degrees) {
|
|
17
|
+
return degrees * this.DEG2RAD
|
|
18
|
+
},
|
|
19
|
+
/**
|
|
20
|
+
* 角度转弧度
|
|
21
|
+
*
|
|
22
|
+
* @param {*} degrees
|
|
23
|
+
* @returns {*}
|
|
24
|
+
*/
|
|
25
|
+
toRadians(degrees) {
|
|
26
|
+
return degrees * this.DEG2RAD
|
|
27
|
+
},
|
|
28
|
+
/**
|
|
29
|
+
* 弧度转角度
|
|
30
|
+
*
|
|
31
|
+
* @param {*} radians
|
|
32
|
+
* @returns {*}
|
|
33
|
+
*/
|
|
34
|
+
radiansToDegrees(radians) {
|
|
35
|
+
return radians * this.RAD2DEG
|
|
36
|
+
},
|
|
37
|
+
/**
|
|
38
|
+
* 弧度转角度
|
|
39
|
+
*
|
|
40
|
+
* @param {*} radians
|
|
41
|
+
* @returns {*}
|
|
42
|
+
*/
|
|
43
|
+
toDegrees(radians) {
|
|
44
|
+
return radians * this.RAD2DEG
|
|
45
|
+
},
|
|
46
|
+
formatFloat(value, n = 2) {
|
|
47
|
+
return Math.round(value * Math.pow(10, n)) / Math.pow(10, n)
|
|
48
|
+
},
|
|
49
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
/**
|
|
3
|
+
* @desc 在事件被触发n秒后再执行回调函数,如果在这n秒内又被触发,则重新计时
|
|
4
|
+
* @desc 防止onresize,scroll,mousemove ,mousehover等,会被频繁触发影响性能
|
|
5
|
+
* @param func 需要执行的函数
|
|
6
|
+
* @param wait 延迟执行时间(毫秒)
|
|
7
|
+
* @param immediate---true 表立即执行,false 表非立即执行
|
|
8
|
+
* eg: window.addEventListener("resize",debounce(handle,1000));
|
|
9
|
+
* @returns {*}
|
|
10
|
+
*/
|
|
11
|
+
debounce(func, wait, immediate = true) {
|
|
12
|
+
let timeout, args, context, timestamp, result
|
|
13
|
+
|
|
14
|
+
const later = function () {
|
|
15
|
+
// 据上一次触发时间间隔
|
|
16
|
+
const last = +new Date() - timestamp
|
|
17
|
+
|
|
18
|
+
// 上次被包装函数被调用时间间隔last小于设定时间间隔wait
|
|
19
|
+
if (last < wait && last > 0) {
|
|
20
|
+
timeout = setTimeout(later, wait - last)
|
|
21
|
+
} else {
|
|
22
|
+
timeout = null
|
|
23
|
+
// 如果设定为immediate===true,因为开始边界已经调用过了此处无需调用
|
|
24
|
+
if (!immediate) {
|
|
25
|
+
result = func.apply(context, args)
|
|
26
|
+
if (!timeout) context = args = null
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return function (...args) {
|
|
32
|
+
context = this
|
|
33
|
+
timestamp = +new Date()
|
|
34
|
+
const callNow = immediate && !timeout
|
|
35
|
+
// 如果延时不存在,重新设定延时
|
|
36
|
+
if (!timeout) timeout = setTimeout(later, wait)
|
|
37
|
+
if (callNow) {
|
|
38
|
+
result = func.apply(context, args)
|
|
39
|
+
context = args = null
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return result
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
* 规定一个单位时间,在这个单位时间内,只能有一次触发事件的回调函数执行,如果在同一个单位时间内某事件被触发多次,只有一次能生效
|
|
47
|
+
*
|
|
48
|
+
* @param {*} func
|
|
49
|
+
* @param {*} wait
|
|
50
|
+
* @param {*} type 1 表时间戳版,2 表定时器版
|
|
51
|
+
* @returns {*}
|
|
52
|
+
*/
|
|
53
|
+
throttle(func, wait, type) {
|
|
54
|
+
if (type === 1) {
|
|
55
|
+
var previous = 0
|
|
56
|
+
} else if (type === 2) {
|
|
57
|
+
var timeout
|
|
58
|
+
}
|
|
59
|
+
return function () {
|
|
60
|
+
let context = this
|
|
61
|
+
let args = arguments
|
|
62
|
+
if (type === 1) {
|
|
63
|
+
let now = Date.now()
|
|
64
|
+
if (now - previous > wait) {
|
|
65
|
+
func.apply(context, args)
|
|
66
|
+
previous = now
|
|
67
|
+
}
|
|
68
|
+
} else if (type === 2) {
|
|
69
|
+
if (!timeout) {
|
|
70
|
+
timeout = setTimeout(() => {
|
|
71
|
+
timeout = null
|
|
72
|
+
func.apply(context, args)
|
|
73
|
+
}, wait)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
/**
|
|
79
|
+
* 延时递归
|
|
80
|
+
*
|
|
81
|
+
* @param {Number} frequency 间隔时间ms
|
|
82
|
+
* @param {Number} duration 持续时间ms
|
|
83
|
+
*/
|
|
84
|
+
recurve(fun, frequency = 500, duration = 5000) {
|
|
85
|
+
let timer = 0
|
|
86
|
+
setTimeout(function fn() {
|
|
87
|
+
timer++
|
|
88
|
+
if (timer < Math.floor(duration / frequency)) {
|
|
89
|
+
fun.call(this)
|
|
90
|
+
setTimeout(fn, frequency)
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
},
|
|
94
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import CommUtils from './CommUtils'
|
|
2
|
+
export default {
|
|
3
|
+
/**
|
|
4
|
+
* 常用正则验证
|
|
5
|
+
*
|
|
6
|
+
* @param {*} str
|
|
7
|
+
* @param {*} type
|
|
8
|
+
* @returns {*}
|
|
9
|
+
*/
|
|
10
|
+
checkStr(str, type) {
|
|
11
|
+
switch (type) {
|
|
12
|
+
case 'phone': // 手机号码
|
|
13
|
+
return /^1[3|4|5|6|7|8|9][0-9]{9}$/.test(str)
|
|
14
|
+
case 'tel': // 座机
|
|
15
|
+
return /^(0\d{2,3}-\d{7,8})(-\d{1,4})?$/.test(str)
|
|
16
|
+
case 'card': // 身份证
|
|
17
|
+
return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(str)
|
|
18
|
+
case 'pwd': // 密码以字母开头,长度在6~18之间,只能包含字母、数字和下划线
|
|
19
|
+
return /^[a-zA-Z]\w{5,17}$/.test(str)
|
|
20
|
+
case 'postal': // 邮政编码
|
|
21
|
+
return /[1-9]\d{5}(?!\d)/.test(str)
|
|
22
|
+
case 'QQ': // QQ号
|
|
23
|
+
return /^[1-9][0-9]{4,9}$/.test(str)
|
|
24
|
+
case 'email': // 邮箱
|
|
25
|
+
return /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(str)
|
|
26
|
+
case 'money': // 金额(小数点2位)
|
|
27
|
+
return /^\d*(?:\.\d{0,2})?$/.test(str)
|
|
28
|
+
case 'URL': // 网址
|
|
29
|
+
return /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/.test(str)
|
|
30
|
+
case 'IP': // IP
|
|
31
|
+
return /((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))/.test(str)
|
|
32
|
+
case 'date': // 日期时间
|
|
33
|
+
return /^(\d{4})\-(\d{2})\-(\d{2}) (\d{2})(?:\:\d{2}|:(\d{2}):(\d{2}))$/.test(str) || /^(\d{4})\-(\d{2})\-(\d{2})$/.test(str)
|
|
34
|
+
case 'number': // 数字
|
|
35
|
+
return /^[0-9]$/.test(str)
|
|
36
|
+
case 'english': // 英文
|
|
37
|
+
return /^[a-zA-Z]+$/.test(str)
|
|
38
|
+
case 'chinese': // 中文
|
|
39
|
+
return /^[\u4E00-\u9FA5]+$/.test(str)
|
|
40
|
+
case 'lower': // 小写
|
|
41
|
+
return /^[a-z]+$/.test(str)
|
|
42
|
+
case 'upper': // 大写
|
|
43
|
+
return /^[A-Z]+$/.test(str)
|
|
44
|
+
case 'HTML': // HTML标记
|
|
45
|
+
return /<("[^"]*"|'[^']*'|[^'">])*>/.test(str)
|
|
46
|
+
default:
|
|
47
|
+
return true
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
/**
|
|
51
|
+
* 字符串大小写转换 type: 1:首字母大写 2:首页母小写 3:大小写转换 4:全部大写 5:全部小写
|
|
52
|
+
*
|
|
53
|
+
* @param {*} str
|
|
54
|
+
* @param {*} type
|
|
55
|
+
* @returns {*}
|
|
56
|
+
*/
|
|
57
|
+
changeCase(str, type) {
|
|
58
|
+
type = type || 4
|
|
59
|
+
switch (type) {
|
|
60
|
+
case 1:
|
|
61
|
+
return str.replace(/\b\w+\b/g, function (word) {
|
|
62
|
+
return word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase()
|
|
63
|
+
})
|
|
64
|
+
case 2:
|
|
65
|
+
return str.replace(/\b\w+\b/g, function (word) {
|
|
66
|
+
return word.substring(0, 1).toLowerCase() + word.substring(1).toUpperCase()
|
|
67
|
+
})
|
|
68
|
+
case 3:
|
|
69
|
+
return str
|
|
70
|
+
.split('')
|
|
71
|
+
.map(function (word) {
|
|
72
|
+
if (/[a-z]/.test(word)) {
|
|
73
|
+
return word.toUpperCase()
|
|
74
|
+
} else {
|
|
75
|
+
return word.toLowerCase()
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
.join('')
|
|
79
|
+
case 4:
|
|
80
|
+
return str.toUpperCase()
|
|
81
|
+
case 5:
|
|
82
|
+
return str.toLowerCase()
|
|
83
|
+
default:
|
|
84
|
+
return str
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
/**
|
|
88
|
+
* 处理字符串模板
|
|
89
|
+
* eg: tag`${abc}`
|
|
90
|
+
* @param {*} strArray
|
|
91
|
+
* @param {*} args
|
|
92
|
+
* @returns {*}
|
|
93
|
+
*/
|
|
94
|
+
tag(strArray, ...args) {
|
|
95
|
+
args = args.map((val) => {
|
|
96
|
+
switch (CommUtils.getDataType(val)) {
|
|
97
|
+
case 'Object':
|
|
98
|
+
return val || '{}'
|
|
99
|
+
case 'Array':
|
|
100
|
+
return val || '[]'
|
|
101
|
+
default:
|
|
102
|
+
return val || ''
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
return strArray.reduce((prev, next, index) => `${prev}${args[index - 1]}${next}`)
|
|
106
|
+
},
|
|
107
|
+
/**
|
|
108
|
+
* 获取字符串字节长度
|
|
109
|
+
* @param {*} str
|
|
110
|
+
* @returns {*}
|
|
111
|
+
*/
|
|
112
|
+
getByteLength(str) {
|
|
113
|
+
return str.replace(/[\u0391-\uFFE5]/g, 'aa').length
|
|
114
|
+
},
|
|
115
|
+
/**
|
|
116
|
+
* 根据字节长度截取字符串
|
|
117
|
+
* @param {*} str
|
|
118
|
+
* @param {*} n
|
|
119
|
+
* @returns {*}
|
|
120
|
+
*/
|
|
121
|
+
subStringByte(str, start, n) {
|
|
122
|
+
var r = /[^\x00-\xff]/g
|
|
123
|
+
if (str.replace(r, 'mm').length <= n) {
|
|
124
|
+
return str
|
|
125
|
+
}
|
|
126
|
+
var m = Math.floor(n / 2)
|
|
127
|
+
for (var i = m; i < str.length; i++) {
|
|
128
|
+
let sub = str.substring(start, i)
|
|
129
|
+
if (sub.replace(r, 'mm').length >= n) {
|
|
130
|
+
return sub
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return str
|
|
134
|
+
},
|
|
135
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { default as AnimateUtils } from "./AnimateUtils";
|
|
2
|
+
export { default as ArrayUtils } from "./ArrayUtils";
|
|
3
|
+
export { default as BrowserUtils } from "./BrowserUtils";
|
|
4
|
+
export { default as Cookie } from "./Cookie";
|
|
5
|
+
export { default as CoordsUtils } from "./CoordsUtils";
|
|
6
|
+
export { default as DateUtils } from "./DateUtils";
|
|
7
|
+
export { default as DomUtils } from "./DomUtils";
|
|
8
|
+
export { default as GeoUtils } from "./GeoUtils";
|
|
9
|
+
export { default as FileUtils } from "./FileUtils";
|
|
10
|
+
export { default as MathUtils } from "./MathUtils";
|
|
11
|
+
export { default as OptimizeUtils } from "./OptimizeUtils";
|
|
12
|
+
export { default as StringUtils } from "./StringUtils";
|
|
13
|
+
export { default as Utils } from "./CommUtils";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
var path = require('path')
|
|
2
|
+
var webpack = require('webpack')
|
|
3
|
+
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
entry: './src/index.js',
|
|
7
|
+
output: {
|
|
8
|
+
path: path.resolve(__dirname, './dist'),
|
|
9
|
+
publicPath: '/dist/',
|
|
10
|
+
filename: 'resource.min.js',
|
|
11
|
+
library: 'Gis',
|
|
12
|
+
libraryTarget: 'umd',
|
|
13
|
+
umdNamedDefine: true,
|
|
14
|
+
},
|
|
15
|
+
module: {
|
|
16
|
+
rules: [
|
|
17
|
+
{
|
|
18
|
+
test: /\.css$/,
|
|
19
|
+
use: ['vue-style-loader', 'css-loader'],
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
test: /\.vue$/,
|
|
23
|
+
loader: 'vue-loader',
|
|
24
|
+
options: {
|
|
25
|
+
loaders: {},
|
|
26
|
+
// other vue-loader options go here
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
test: /\.js$/,
|
|
31
|
+
loader: 'babel-loader',
|
|
32
|
+
exclude: /node_modules/,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
test: /\.(png|jpg|gif|svg)$/,
|
|
36
|
+
loader: 'url-loader',
|
|
37
|
+
options: {
|
|
38
|
+
limit: 100000,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
externals: {
|
|
44
|
+
mqtt: 'mqtt',
|
|
45
|
+
},
|
|
46
|
+
plugins: [
|
|
47
|
+
new CleanWebpackPlugin(),
|
|
48
|
+
new webpack.LoaderOptionsPlugin({
|
|
49
|
+
minimize: true,
|
|
50
|
+
}),
|
|
51
|
+
],
|
|
52
|
+
resolve: {
|
|
53
|
+
alias: {
|
|
54
|
+
vue$: 'vue/dist/vue.esm.js',
|
|
55
|
+
},
|
|
56
|
+
extensions: ['*', '.js', '.vue', '.json'],
|
|
57
|
+
},
|
|
58
|
+
devServer: {
|
|
59
|
+
historyApiFallback: true,
|
|
60
|
+
noInfo: true,
|
|
61
|
+
overlay: true,
|
|
62
|
+
},
|
|
63
|
+
performance: {
|
|
64
|
+
hints: false,
|
|
65
|
+
},
|
|
66
|
+
devtool: 'none',
|
|
67
|
+
optimization: {
|
|
68
|
+
minimize: false,
|
|
69
|
+
},
|
|
70
|
+
}
|