gis-common 2.2.3 → 2.2.4
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/dist/resource.min.js +2687 -0
- package/package.json +3 -5
- package/src/assets/images/location.png +0 -0
- package/src/constant/ErrorTypeConstant.js +0 -20
- package/src/constant/EventTypeConstant.js +0 -23
- package/src/constant/GraphicConstant.js +0 -16
- package/src/constant/LayerType.js +0 -9
- package/src/constant/index.js +0 -4
- package/src/core/AudioPlayer.js +0 -30
- package/src/core/CanvasDrawer.js +0 -51
- package/src/core/DevicePixelRatio.js +0 -86
- package/src/core/ElQuery.js +0 -88
- package/src/core/EventDispatcher.js +0 -93
- package/src/core/HashMap.js +0 -36
- package/src/core/MqttClient.js +0 -108
- package/src/core/WebSocketClient.js +0 -104
- package/src/core/WebStorage.js +0 -73
- package/src/index.js +0 -10
- package/src/utils/AnimateUtils.js +0 -78
- package/src/utils/ArrayUtils.js +0 -82
- package/src/utils/BrowserUtils.js +0 -107
- package/src/utils/CommUtils.js +0 -230
- package/src/utils/Cookie.js +0 -23
- package/src/utils/CoordsUtils.js +0 -139
- package/src/utils/DateUtils.js +0 -130
- package/src/utils/DomUtils.js +0 -94
- package/src/utils/FileUtils.js +0 -105
- package/src/utils/GeoUtils.js +0 -242
- package/src/utils/MathUtils.js +0 -49
- package/src/utils/OptimizeUtils.js +0 -94
- package/src/utils/StringUtils.js +0 -135
- package/src/utils/index.js +0 -13
package/src/utils/Cookie.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
}
|
package/src/utils/CoordsUtils.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
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
|
-
}
|
package/src/utils/DateUtils.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
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
|
-
lastDayDate: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() - 1),
|
|
61
|
-
thisDayDate: new Date(new Date().setHours(0, 0, 0, 0)),
|
|
62
|
-
nextDayDate: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1),
|
|
63
|
-
parseDate(str) {
|
|
64
|
-
if (typeof str == 'string') {
|
|
65
|
-
var results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) *$/)
|
|
66
|
-
if (results && results.length > 3) return new Date(parseInt(results[1]), parseInt(results[2]) - 1, parseInt(results[3]))
|
|
67
|
-
results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2}) *$/)
|
|
68
|
-
if (results && results.length > 6)
|
|
69
|
-
return new Date(
|
|
70
|
-
parseInt(results[1]),
|
|
71
|
-
parseInt(results[2]) - 1,
|
|
72
|
-
parseInt(results[3]),
|
|
73
|
-
parseInt(results[4]),
|
|
74
|
-
parseInt(results[5]),
|
|
75
|
-
parseInt(results[6])
|
|
76
|
-
)
|
|
77
|
-
results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2})\.(\d{1,9}) *$/)
|
|
78
|
-
if (results && results.length > 7)
|
|
79
|
-
return new Date(
|
|
80
|
-
parseInt(results[1]),
|
|
81
|
-
parseInt(results[2]) - 1,
|
|
82
|
-
parseInt(results[3]),
|
|
83
|
-
parseInt(results[4]),
|
|
84
|
-
parseInt(results[5]),
|
|
85
|
-
parseInt(results[6]),
|
|
86
|
-
parseInt(results[7])
|
|
87
|
-
)
|
|
88
|
-
}
|
|
89
|
-
return null
|
|
90
|
-
},
|
|
91
|
-
/**
|
|
92
|
-
* 将时间间隔转换成中国话
|
|
93
|
-
*
|
|
94
|
-
* @param {*} startTime
|
|
95
|
-
* @param {*} endTime
|
|
96
|
-
* @returns {*}
|
|
97
|
-
*/
|
|
98
|
-
formatDateInterval(startTime, endTime) {
|
|
99
|
-
const dateCreateTime = new Date(startTime)
|
|
100
|
-
const dateFinishTime = new Date(endTime)
|
|
101
|
-
const dateInterval = dateFinishTime.getTime() - dateCreateTime.getTime()
|
|
102
|
-
const days = Math.floor(dateInterval / (24 * 3600 * 1000))
|
|
103
|
-
const leave1 = dateInterval % (24 * 3600 * 1000)
|
|
104
|
-
const hours = Math.floor(leave1 / (3600 * 1000))
|
|
105
|
-
const leave2 = leave1 % (3600 * 1000)
|
|
106
|
-
const minutes = Math.floor(leave2 / (60 * 1000))
|
|
107
|
-
const leave3 = leave2 % (60 * 1000)
|
|
108
|
-
const seconds = Math.round(leave3 / 1000)
|
|
109
|
-
let intervalDes = ''
|
|
110
|
-
if (days > 0) {
|
|
111
|
-
intervalDes += days + '天'
|
|
112
|
-
}
|
|
113
|
-
if (hours > 0) {
|
|
114
|
-
intervalDes += hours + '时'
|
|
115
|
-
}
|
|
116
|
-
if (minutes > 0) {
|
|
117
|
-
intervalDes += minutes + '分'
|
|
118
|
-
}
|
|
119
|
-
if (seconds > 0) {
|
|
120
|
-
intervalDes += seconds + '秒'
|
|
121
|
-
}
|
|
122
|
-
if (days === 0 && hours === 0 && minutes === 0 && seconds === 0) {
|
|
123
|
-
intervalDes = '少于1秒'
|
|
124
|
-
}
|
|
125
|
-
return intervalDes
|
|
126
|
-
},
|
|
127
|
-
sleep(d) {
|
|
128
|
-
for (let t = Date.now(); Date.now() - t <= d; );
|
|
129
|
-
},
|
|
130
|
-
}
|
package/src/utils/DomUtils.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
function trim(str) {
|
|
2
|
-
return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, '')
|
|
3
|
-
}
|
|
4
|
-
function splitWords(str) {
|
|
5
|
-
return trim(str).split(/\s+/)
|
|
6
|
-
}
|
|
7
|
-
export default {
|
|
8
|
-
getStyle(el, style) {
|
|
9
|
-
let value = el.style[style] || (el.currentStyle && el.currentStyle[style])
|
|
10
|
-
|
|
11
|
-
if ((!value || value === 'auto') && document.defaultView) {
|
|
12
|
-
const css = document.defaultView.getComputedStyle(el, null)
|
|
13
|
-
value = css ? css[style] : null
|
|
14
|
-
}
|
|
15
|
-
return value === 'auto' ? null : value
|
|
16
|
-
},
|
|
17
|
-
create(tagName, className, container) {
|
|
18
|
-
const el = document.createElement(tagName)
|
|
19
|
-
el.className = className || ''
|
|
20
|
-
|
|
21
|
-
if (container) {
|
|
22
|
-
container.appendChild(el)
|
|
23
|
-
}
|
|
24
|
-
return el
|
|
25
|
-
},
|
|
26
|
-
remove(el) {
|
|
27
|
-
const parent = el.parentNode
|
|
28
|
-
if (parent) {
|
|
29
|
-
parent.removeChild(el)
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
empty(el) {
|
|
33
|
-
while (el.firstChild) {
|
|
34
|
-
el.removeChild(el.firstChild)
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
toFront(el) {
|
|
38
|
-
const parent = el.parentNode
|
|
39
|
-
if (parent && parent.lastChild !== el) {
|
|
40
|
-
parent.appendChild(el)
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
toBack(el) {
|
|
44
|
-
const parent = el.parentNode
|
|
45
|
-
if (parent && parent.firstChild !== el) {
|
|
46
|
-
parent.insertBefore(el, parent.firstChild)
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
getClass(el) {
|
|
50
|
-
if (el.correspondingElement) {
|
|
51
|
-
el = el.correspondingElement
|
|
52
|
-
}
|
|
53
|
-
return el.className.baseVal === undefined ? el.className : el.className.baseVal
|
|
54
|
-
},
|
|
55
|
-
hasClass(el, name) {
|
|
56
|
-
if (el.classList !== undefined) {
|
|
57
|
-
return el.classList.contains(name)
|
|
58
|
-
}
|
|
59
|
-
const className = this.getClass(el)
|
|
60
|
-
return className.length > 0 && new RegExp('(^|\\s)' + name + '(\\s|$)').test(className)
|
|
61
|
-
},
|
|
62
|
-
addClass(el, name) {
|
|
63
|
-
if (el.classList !== undefined) {
|
|
64
|
-
const classes = splitWords(name)
|
|
65
|
-
for (let i = 0, len = classes.length; i < len; i++) {
|
|
66
|
-
el.classList.add(classes[i])
|
|
67
|
-
}
|
|
68
|
-
} else if (!this.hasClass(el, name)) {
|
|
69
|
-
const className = this.getClass(el)
|
|
70
|
-
this.setClass(el, (className ? className + ' ' : '') + name)
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
removeClass(el, name) {
|
|
74
|
-
if (el.classList !== undefined) {
|
|
75
|
-
const classes = splitWords(name)
|
|
76
|
-
classes.forEach((name) => el.classList.remove(name))
|
|
77
|
-
} else {
|
|
78
|
-
this.setClass(el, trim((' ' + this.getClass(el) + ' ').replace(' ' + name + ' ', ' ')))
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
setClass(el, name) {
|
|
82
|
-
if (el.className.baseVal === undefined) {
|
|
83
|
-
el.className = name
|
|
84
|
-
} else {
|
|
85
|
-
// in case of SVG element
|
|
86
|
-
el.className.baseVal = name
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
parseFromString(str) {
|
|
90
|
-
const parser = new DOMParser()
|
|
91
|
-
const doc = parser.parseFromString(str, 'text/xml')
|
|
92
|
-
return doc.children[0]
|
|
93
|
-
},
|
|
94
|
-
}
|
package/src/utils/FileUtils.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
/**
|
|
3
|
-
* 将base64类型编码的图片转换成blob类型
|
|
4
|
-
*
|
|
5
|
-
* @param {*} data
|
|
6
|
-
* @returns {*}
|
|
7
|
-
*/
|
|
8
|
-
convertBase64ToBlob(data) {
|
|
9
|
-
var mimeString = data.split(',')[0].split(':')[1].split(';')[0]
|
|
10
|
-
var byteString = window.atob(data.split(',')[1])
|
|
11
|
-
var ab = new ArrayBuffer(byteString.length)
|
|
12
|
-
var ia = new Uint8Array(ab)
|
|
13
|
-
|
|
14
|
-
for (var i = 0; i < byteString.length; i++) {
|
|
15
|
-
ia[i] = byteString.charCodeAt(i)
|
|
16
|
-
}
|
|
17
|
-
var bb = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder
|
|
18
|
-
|
|
19
|
-
if (bb) {
|
|
20
|
-
bb = new (window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder)()
|
|
21
|
-
bb.append(ab)
|
|
22
|
-
return bb.getBlob(mimeString)
|
|
23
|
-
} else {
|
|
24
|
-
bb = new Blob([ab], {
|
|
25
|
-
type: mimeString,
|
|
26
|
-
})
|
|
27
|
-
return bb
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
/**
|
|
31
|
-
* 将url图片转换成base64编码的图片,也可用于图片压缩
|
|
32
|
-
*
|
|
33
|
-
* @param {*} url 需要转换的图片url
|
|
34
|
-
* @param {*} width 指定宽高,如未指定则使用默认宽度
|
|
35
|
-
* @param {*} height
|
|
36
|
-
* @returns {*}
|
|
37
|
-
*/
|
|
38
|
-
convertUrlToBase64(url, width, height) {
|
|
39
|
-
return new Promise(function (resolve, reject) {
|
|
40
|
-
var img = new Image()
|
|
41
|
-
img.crossOrigin = 'Anonymous'
|
|
42
|
-
img.src = url
|
|
43
|
-
img.onload = function () {
|
|
44
|
-
var canvas = document.createElement('canvas')
|
|
45
|
-
canvas.width = width || img.width
|
|
46
|
-
canvas.height = height || img.height
|
|
47
|
-
var ctx = canvas.getContext('2d')
|
|
48
|
-
ctx.drawImage(img, 0, 0, img.width, img.height)
|
|
49
|
-
var ext = img.src.substring(img.src.lastIndexOf('.') + 1).toLowerCase()
|
|
50
|
-
var dataURL = canvas.toDataURL('image/' + ext)
|
|
51
|
-
var base64 = {
|
|
52
|
-
dataURL: dataURL,
|
|
53
|
-
type: 'image/' + ext,
|
|
54
|
-
ext: ext,
|
|
55
|
-
}
|
|
56
|
-
resolve(base64)
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
},
|
|
60
|
-
/**
|
|
61
|
-
* 将base64类型编码的图片转换成file类型
|
|
62
|
-
*
|
|
63
|
-
* @param {*} dataurl
|
|
64
|
-
* @param {*} filename
|
|
65
|
-
* @returns {*}
|
|
66
|
-
*/
|
|
67
|
-
convertBase64ToFile(dataurl, filename) {
|
|
68
|
-
var arr = dataurl.split(','),
|
|
69
|
-
mime = arr[0].match(/:(.*?);/)[1],
|
|
70
|
-
bstr = atob(arr[1]),
|
|
71
|
-
n = bstr.length,
|
|
72
|
-
u8arr = new Uint8Array(n)
|
|
73
|
-
while (n--) {
|
|
74
|
-
u8arr[n] = bstr.charCodeAt(n)
|
|
75
|
-
}
|
|
76
|
-
let file = new File([u8arr], filename, { type: mime })
|
|
77
|
-
return file
|
|
78
|
-
},
|
|
79
|
-
/**
|
|
80
|
-
* 直接下载文件,支持blob类型和url类型
|
|
81
|
-
*
|
|
82
|
-
* @param {*} data
|
|
83
|
-
* @param {*} saveName
|
|
84
|
-
*/
|
|
85
|
-
downloadFromFile(data, saveName) {
|
|
86
|
-
let url
|
|
87
|
-
if (typeof data == 'object') {
|
|
88
|
-
if (data instanceof Blob) {
|
|
89
|
-
url = URL.createObjectURL(data) // 创建blob地址
|
|
90
|
-
} else {
|
|
91
|
-
const str = JSON.stringify(data)
|
|
92
|
-
const blob = new Blob([str], { type: 'text/json' }) // json对象
|
|
93
|
-
url = window.URL.createObjectURL(blob)
|
|
94
|
-
}
|
|
95
|
-
} else if (typeof data == 'string') {
|
|
96
|
-
const blob = new Blob([data], { type: 'text/json' }) //json文本
|
|
97
|
-
url = window.URL.createObjectURL(blob)
|
|
98
|
-
}
|
|
99
|
-
var link = document.createElement('a')
|
|
100
|
-
link.href = url
|
|
101
|
-
link.download = saveName || '' // HTML5新增的属性,指定保存文件名,可以不要后缀,注意,file:///模式下不会生效
|
|
102
|
-
link.click()
|
|
103
|
-
window.URL.revokeObjectURL(link.href)
|
|
104
|
-
},
|
|
105
|
-
}
|